MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
SqliteSchemaManager.php
Ir para a documentação deste ficheiro.
1
<?php
2
/*
3
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
*
15
* This software consists of voluntary contributions made by many individuals
16
* and is licensed under the LGPL. For more information, see
17
* <http://www.doctrine-project.org>.
18
*/
19
20
namespace
Doctrine\DBAL\Schema
;
21
32
class
SqliteSchemaManager
extends
AbstractSchemaManager
33
{
39
public
function
dropDatabase
($database)
40
{
41
if
(file_exists($database)) {
42
unlink($database);
43
}
44
}
45
51
public
function
createDatabase
($database)
52
{
53
$params = $this->_conn->getParams();
54
$driver = $params[
'driver'
];
55
$options = array(
56
'driver'
=> $driver,
57
'path'
=> $database
58
);
59
$conn = \Doctrine\DBAL\DriverManager::getConnection($options);
60
$conn->connect();
61
$conn->close();
62
}
63
64
protected
function
_getPortableTableDefinition
($table)
65
{
66
return
$table[
'name'
];
67
}
68
76
protected
function
_getPortableTableIndexesList
($tableIndexes, $tableName=
null
)
77
{
78
$indexBuffer = array();
79
80
// fetch primary
81
$stmt = $this->_conn->executeQuery(
"PRAGMA TABLE_INFO ('$tableName')"
);
82
$indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
83
foreach
($indexArray AS $indexColumnRow) {
84
if
($indexColumnRow[
'pk'
] ==
"1"
) {
85
$indexBuffer[] = array(
86
'key_name'
=>
'primary'
,
87
'primary'
=>
true
,
88
'non_unique'
=>
false
,
89
'column_name'
=> $indexColumnRow[
'name'
]
90
);
91
}
92
}
93
94
// fetch regular indexes
95
foreach
($tableIndexes AS $tableIndex) {
96
$keyName = $tableIndex[
'name'
];
97
$idx = array();
98
$idx[
'key_name'
] = $keyName;
99
$idx[
'primary'
] =
false
;
100
$idx[
'non_unique'
] = $tableIndex[
'unique'
]?
false
:
true
;
101
102
$stmt = $this->_conn->executeQuery(
"PRAGMA INDEX_INFO ( '{$keyName}' )"
);
103
$indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
104
105
foreach
( $indexArray as $indexColumnRow ) {
106
$idx[
'column_name'
] = $indexColumnRow[
'name'
];
107
$indexBuffer[] = $idx;
108
}
109
}
110
111
return
parent::_getPortableTableIndexesList($indexBuffer, $tableName);
112
}
113
114
protected
function
_getPortableTableIndexDefinition
($tableIndex)
115
{
116
return
array(
117
'name'
=> $tableIndex[
'name'
],
118
'unique'
=> (
bool
) $tableIndex[
'unique'
]
119
);
120
}
121
122
protected
function
_getPortableTableColumnDefinition
($tableColumn)
123
{
124
$e = explode(
'('
, $tableColumn[
'type'
]);
125
$tableColumn[
'type'
] = $e[0];
126
if
(isset($e[1])) {
127
$length = trim($e[1],
')'
);
128
$tableColumn[
'length'
] = $length;
129
}
130
131
$dbType = strtolower($tableColumn[
'type'
]);
132
$length = isset($tableColumn[
'length'
]) ? $tableColumn[
'length'
] :
null
;
133
$unsigned = (boolean) isset($tableColumn[
'unsigned'
]) ? $tableColumn[
'unsigned'
] :
false
;
134
$fixed =
false
;
135
$type = $this->_platform->getDoctrineTypeMapping($dbType);
136
$default = $tableColumn[
'dflt_value'
];
137
if
($default ==
'NULL'
) {
138
$default =
null
;
139
}
140
$notnull = (bool) $tableColumn[
'notnull'
];
141
142
if
( ! isset($tableColumn[
'name'
])) {
143
$tableColumn[
'name'
] =
''
;
144
}
145
146
$precision =
null
;
147
$scale =
null
;
148
149
switch
($dbType) {
150
case
'char'
:
151
$fixed =
true
;
152
break
;
153
case
'float'
:
154
case
'double'
:
155
case
'real'
:
156
case
'decimal'
:
157
case
'numeric'
:
158
list($precision, $scale) = array_map(
'trim'
, explode(
', '
, $tableColumn[
'length'
]));
159
$length =
null
;
160
break
;
161
}
162
163
$options = array(
164
'length'
=> $length,
165
'unsigned'
=> (
bool
) $unsigned,
166
'fixed'
=> $fixed,
167
'notnull'
=> $notnull,
168
'default'
=> $default,
169
'precision'
=> $precision,
170
'scale'
=> $scale,
171
'autoincrement'
=> (
bool
) $tableColumn[
'pk'
],
172
);
173
174
return
new
Column
($tableColumn[
'name'
], \Doctrine\DBAL\Types\Type::getType($type), $options);
175
}
176
177
protected
function
_getPortableViewDefinition
($view)
178
{
179
return
new
View
($view[
'name'
], $view[
'sql'
]);
180
}
181
}
Doctrine\DBAL\Schema\AbstractSchemaManager
Definição
AbstractSchemaManager.php:40
Doctrine\DBAL\Schema\Column
Definição
Column.php:35
Doctrine\DBAL\Schema\SqliteSchemaManager
Definição
SqliteSchemaManager.php:33
Doctrine\DBAL\Schema\SqliteSchemaManager\_getPortableTableDefinition
_getPortableTableDefinition($table)
Definição
SqliteSchemaManager.php:64
Doctrine\DBAL\Schema\SqliteSchemaManager\dropDatabase
dropDatabase($database)
Definição
SqliteSchemaManager.php:39
Doctrine\DBAL\Schema\SqliteSchemaManager\_getPortableViewDefinition
_getPortableViewDefinition($view)
Definição
SqliteSchemaManager.php:177
Doctrine\DBAL\Schema\SqliteSchemaManager\createDatabase
createDatabase($database)
Definição
SqliteSchemaManager.php:51
Doctrine\DBAL\Schema\SqliteSchemaManager\_getPortableTableIndexDefinition
_getPortableTableIndexDefinition($tableIndex)
Definição
SqliteSchemaManager.php:114
Doctrine\DBAL\Schema\SqliteSchemaManager\_getPortableTableIndexesList
_getPortableTableIndexesList($tableIndexes, $tableName=null)
Definição
SqliteSchemaManager.php:76
Doctrine\DBAL\Schema\SqliteSchemaManager\_getPortableTableColumnDefinition
_getPortableTableColumnDefinition($tableColumn)
Definição
SqliteSchemaManager.php:122
Doctrine\DBAL\Schema\View
Definição
View.php:34
Doctrine\DBAL\Schema
Definição
AbstractAsset.php:22
classes
extensions
doctrine-dbal
Doctrine
DBAL
Schema
SqliteSchemaManager.php
Gerado por
1.10.0