Passed
Push — master ( 9155e7...72c61b )
by 世昌
02:37
created

SQLiteTableCreator::seekField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
namespace suda\application\database\creator;
3
4
use suda\orm\exception\SQLException;
5
use suda\orm\struct\Field;
6
use suda\orm\struct\Fields;
7
use suda\orm\connection\Connection;
8
use suda\orm\statement\QueryStatement;
9
10
/**
11
 * 数据表链接对象
12
 *
13
 */
14
class SQLiteTableCreator
15
{
16
    /**
17
     * 连接
18
     *
19
     * @var Connection
20
     */
21
    protected $connection;
22
23
    /**
24
     * 字段
25
     *
26
     * @var Fields
27
     */
28
    protected $fields;
29
30
    const ENGINE_MyISAM = 'MyISAM';
31
    const ENGINE_InnoDB = 'InnoDB';
32
33
    protected $name;
34
    protected $engine = self::ENGINE_InnoDB;
35
    protected $comment;
36
37
    protected $collate;
38
    protected $charset = 'utf8mb4';
39
    
40
    protected $auto;
41
    protected $foreignKeys;
42
43
    public function __construct(Connection $connection, Fields $fields)
44
    {
45
        $this->name = $fields->getName();
46
        $this->fields = $fields;
47
        $this->connection = $connection;
48
    }
49
50
    /**
51
     * @return bool
52
     * @throws SQLException
53
     */
54
    public function create()
55
    {
56
        $statement = new QueryStatement($this->toSQL());
57
        $statement->isWrite(true);
58
        return $this->connection->query($statement) > 0;
59
    }
60
61
    protected function seekField(Field $field)
62
    {
63
        $name = $field->getName();
64
        $this->fields[$name] = $field;
65
        if ($foreign = $field->getForeignKey()) {
66
            $this->foreignKeys[$name] = $foreign;
67
        }
68
        return $this;
69
    }
70
71
72
    protected function toSQL()
73
    {
74
        // TODO
75
        return '';
76
    }
77
}
78