MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
SqlitePlatform.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
21
23
34{
41 public function getRegexpExpression()
42 {
43 return 'RLIKE';
44 }
45
53 public function getNowExpression($type = 'timestamp')
54 {
55 switch ($type) {
56 case 'time':
57 return 'time(\'now\')';
58 case 'date':
59 return 'date(\'now\')';
60 case 'timestamp':
61 default:
62 return 'datetime(\'now\')';
63 }
64 }
65
74 public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false)
75 {
76 $trimFn = '';
77 $trimChar = ($char != false) ? (', ' . $char) : '';
78
79 if ($pos == self::TRIM_LEADING) {
80 $trimFn = 'LTRIM';
81 } else if($pos == self::TRIM_TRAILING) {
82 $trimFn = 'RTRIM';
83 } else {
84 $trimFn = 'TRIM';
85 }
86
87 return $trimFn . '(' . $str . $trimChar . ')';
88 }
89
103 public function getSubstringExpression($value, $position, $length = null)
104 {
105 if ($length !== null) {
106 return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')';
107 }
108 return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))';
109 }
110
119 public function getLocateExpression($str, $substr, $startPos = false)
120 {
121 if ($startPos == false) {
122 return 'LOCATE('.$str.', '.$substr.')';
123 } else {
124 return 'LOCATE('.$str.', '.$substr.', '.$startPos.')';
125 }
126 }
127
128 protected function _getTransactionIsolationLevelSQL($level)
129 {
130 switch ($level) {
131 case \Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED:
132 return 0;
133 case \Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED:
134 case \Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ:
135 case \Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE:
136 return 1;
137 default:
138 return parent::_getTransactionIsolationLevelSQL($level);
139 }
140 }
141
142 public function getSetTransactionIsolationSQL($level)
143 {
144 return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSQL($level);
145 }
146
150 public function prefersIdentityColumns()
151 {
152 return true;
153 }
154
158 public function getBooleanTypeDeclarationSQL(array $field)
159 {
160 return 'BOOLEAN';
161 }
162
166 public function getIntegerTypeDeclarationSQL(array $field)
167 {
168 return $this->_getCommonIntegerTypeDeclarationSQL($field);
169 }
170
174 public function getBigIntTypeDeclarationSQL(array $field)
175 {
176 return $this->_getCommonIntegerTypeDeclarationSQL($field);
177 }
178
182 public function getTinyIntTypeDeclarationSql(array $field)
183 {
184 return $this->_getCommonIntegerTypeDeclarationSQL($field);
185 }
186
190 public function getSmallIntTypeDeclarationSQL(array $field)
191 {
192 return $this->_getCommonIntegerTypeDeclarationSQL($field);
193 }
194
198 public function getMediumIntTypeDeclarationSql(array $field)
199 {
200 return $this->_getCommonIntegerTypeDeclarationSQL($field);
201 }
202
206 public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
207 {
208 return 'DATETIME';
209 }
210
214 public function getDateTypeDeclarationSQL(array $fieldDeclaration)
215 {
216 return 'DATE';
217 }
218
222 public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
223 {
224 return 'TIME';
225 }
226
230 protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
231 {
232 $autoinc = ! empty($columnDef['autoincrement']) ? ' AUTOINCREMENT' : '';
233 $pk = ! empty($columnDef['primary']) && ! empty($autoinc) ? ' PRIMARY KEY' : '';
234
235 return 'INTEGER' . $pk . $autoinc;
236 }
237
267 protected function _getCreateTableSQL($name, array $columns, array $options = array())
268 {
269 $queryFields = $this->getColumnDeclarationListSQL($columns);
270
271 $autoinc = false;
272 foreach($columns as $field) {
273 if (isset($field['autoincrement']) && $field['autoincrement']) {
274 $autoinc = true;
275 break;
276 }
277 }
278
279 if ( ! $autoinc && isset($options['primary']) && ! empty($options['primary'])) {
280 $keyColumns = array_unique(array_values($options['primary']));
281 $keyColumns = array_map(array($this, 'quoteIdentifier'), $keyColumns);
282 $queryFields.= ', PRIMARY KEY('.implode(', ', $keyColumns).')';
283 }
284
285 $query[] = 'CREATE TABLE ' . $name . ' (' . $queryFields . ')';
286
287 if (isset($options['indexes']) && ! empty($options['indexes'])) {
288 foreach ($options['indexes'] as $index => $indexDef) {
289 $query[] = $this->getCreateIndexSQL($indexDef, $name);
290 }
291 }
292 if (isset($options['unique']) && ! empty($options['unique'])) {
293 foreach ($options['unique'] as $index => $indexDef) {
294 $query[] = $this->getCreateIndexSQL($indexDef, $name);
295 }
296 }
297 return $query;
298 }
299
303 public function getVarcharTypeDeclarationSQL(array $field)
304 {
305 if ( ! isset($field['length'])) {
306 if (array_key_exists('default', $field)) {
307 $field['length'] = $this->getVarcharDefaultLength();
308 } else {
309 $field['length'] = false;
310 }
311 }
312 $length = ($field['length'] <= $this->getVarcharMaxLength()) ? $field['length'] : false;
313 $fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
314
315 return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
316 : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
317 }
318
319 public function getClobTypeDeclarationSQL(array $field)
320 {
321 return 'CLOB';
322 }
323
324 public function getListTableConstraintsSQL($table)
325 {
326 return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = '$table' AND sql NOT NULL ORDER BY name";
327 }
328
329 public function getListTableColumnsSQL($table)
330 {
331 return "PRAGMA table_info($table)";
332 }
333
334 public function getListTableIndexesSQL($table)
335 {
336 return "PRAGMA index_list($table)";
337 }
338
339 public function getListTablesSQL()
340 {
341 return "SELECT name FROM sqlite_master WHERE type = 'table' AND name != 'sqlite_sequence' "
342 . "UNION ALL SELECT name FROM sqlite_temp_master "
343 . "WHERE type = 'table' ORDER BY name";
344 }
345
346 public function getListViewsSQL($database)
347 {
348 return "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL";
349 }
350
351 public function getCreateViewSQL($name, $sql)
352 {
353 return 'CREATE VIEW ' . $name . ' AS ' . $sql;
354 }
355
356 public function getDropViewSQL($name)
357 {
358 return 'DROP VIEW '. $name;
359 }
360
370 {
371 return false;
372 }
373
374 public function supportsAlterTable()
375 {
376 return false;
377 }
378
379 public function supportsIdentityColumns()
380 {
381 return true;
382 }
383
389 public function getName()
390 {
391 return 'sqlite';
392 }
393
397 public function getTruncateTableSQL($tableName, $cascade = false)
398 {
399 return 'DELETE FROM '.$tableName;
400 }
401
408 static public function udfSqrt($value)
409 {
410 return sqrt($value);
411 }
412
416 static public function udfMod($a, $b)
417 {
418 return ($a % $b);
419 }
420
426 static public function udfLocate($str, $substr, $offset = 0)
427 {
428 $pos = strpos($str, $substr, $offset);
429 if ($pos !== false) {
430 return $pos+1;
431 }
432 return 0;
433 }
434
435 public function getForUpdateSql()
436 {
437 return '';
438 }
439
441 {
442 $this->doctrineTypeMapping = array(
443 'boolean' => 'boolean',
444 'tinyint' => 'boolean',
445 'smallint' => 'smallint',
446 'mediumint' => 'integer',
447 'int' => 'integer',
448 'integer' => 'integer',
449 'serial' => 'integer',
450 'bigint' => 'bigint',
451 'bigserial' => 'bigint',
452 'clob' => 'text',
453 'tinytext' => 'text',
454 'mediumtext' => 'text',
455 'longtext' => 'text',
456 'text' => 'text',
457 'varchar' => 'string',
458 'varchar2' => 'string',
459 'nvarchar' => 'string',
460 'image' => 'string',
461 'ntext' => 'string',
462 'char' => 'string',
463 'date' => 'date',
464 'datetime' => 'datetime',
465 'timestamp' => 'datetime',
466 'time' => 'time',
467 'float' => 'float',
468 'double' => 'float',
469 'real' => 'float',
470 'decimal' => 'decimal',
471 'numeric' => 'decimal',
472 );
473 }
474}
getTimeTypeDeclarationSQL(array $fieldDeclaration)
getLocateExpression($str, $substr, $startPos=false)
getSubstringExpression($value, $position, $length=null)
_getCommonIntegerTypeDeclarationSQL(array $columnDef)
getTrimExpression($str, $pos=self::TRIM_UNSPECIFIED, $char=false)
getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
_getCreateTableSQL($name, array $columns, array $options=array())
getDateTypeDeclarationSQL(array $fieldDeclaration)
getTruncateTableSQL($tableName, $cascade=false)
static udfLocate($str, $substr, $offset=0)