10 defined(
'JPATH_PLATFORM') or die;
28 public $name =
'sqlite';
39 protected $nameQuote =
'`';
46 public function __destruct()
49 unset($this->connection);
59 public function disconnect()
62 unset($this->connection);
75 public function dropTable($tableName, $ifExists =
true)
79 $query = $this->getQuery(
true);
81 $this->setQuery(
'DROP TABLE ' . ($ifExists ?
'IF EXISTS ' :
'') . $query->quoteName($tableName));
101 public function escape($text, $extra =
false)
103 if (is_int($text) || is_float($text))
108 return SQLite3::escapeString($text);
118 public function getCollation()
120 return $this->charset;
135 public function getTableCreate($tables)
140 settype($tables,
'array');
156 public function getTableColumns($table, $typeOnly =
true)
161 $query = $this->getQuery(
true);
163 $fieldCasing = $this->getOption(PDO::ATTR_CASE);
165 $this->setOption(PDO::ATTR_CASE, PDO::CASE_UPPER);
167 $table = strtoupper($table);
169 $query->setQuery(
'pragma table_info(' . $table .
')');
171 $this->setQuery($query);
172 $fields = $this->loadObjectList();
176 foreach ($fields as $field)
178 $columns[$field->NAME] = $field->TYPE;
183 foreach ($fields as $field)
187 $columns[$field->NAME] = (object) array(
188 'Field' => $field->NAME,
189 'Type' => $field->TYPE,
190 'Null' => ($field->NOTNULL ==
'1' ?
'NO' :
'YES'),
191 'Default' => $field->DFLT_VALUE,
192 'Key' => ($field->PK ==
'1' ?
'PRI' :
'')
197 $this->setOption(PDO::ATTR_CASE, $fieldCasing);
212 public function getTableKeys($table)
217 $query = $this->getQuery(
true);
219 $fieldCasing = $this->getOption(PDO::ATTR_CASE);
221 $this->setOption(PDO::ATTR_CASE, PDO::CASE_UPPER);
223 $table = strtoupper($table);
224 $query->setQuery(
'pragma table_info( ' . $table .
')');
228 $this->setQuery($query);
229 $rows = $this->loadObjectList();
231 foreach ($rows as $column)
233 if ($column->PK == 1)
235 $keys[$column->NAME] = $column;
239 $this->setOption(PDO::ATTR_CASE, $fieldCasing);
252 public function getTableList()
258 $query = $this->getQuery(
true)
260 ->from(
'sqlite_master')
261 ->where(
'type = :type')
262 ->bind(
':type', $type)
265 $this->setQuery($query);
267 $tables = $this->loadColumn();
279 public function getVersion()
283 $this->setQuery(
"SELECT sqlite_version()");
285 return $this->loadResult();
298 public function select($database)
316 public function setUTF()
333 public function lockTable($table)
351 public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
353 $this->setQuery(
'ALTER TABLE ' . $oldTable .
' RENAME TO ' . $newTable)->execute();
366 public function unlockTables()
378 public static function isSupported()
380 return class_exists(
'PDO') && in_array(
'sqlite', PDO::getAvailableDrivers());
393 public function transactionCommit($toSavepoint =
false)
397 if (!$toSavepoint || $this->transactionDepth <= 1)
399 parent::transactionCommit($toSavepoint);
403 $this->transactionDepth--;
417 public function transactionRollback($toSavepoint =
false)
421 if (!$toSavepoint || $this->transactionDepth <= 1)
423 parent::transactionRollback($toSavepoint);
427 $savepoint =
'SP_' . ($this->transactionDepth - 1);
428 $this->setQuery(
'ROLLBACK TO ' . $this->quoteName($savepoint));
430 if ($this->execute())
432 $this->transactionDepth--;
447 public function transactionStart($asSavepoint =
false)
451 if (!$asSavepoint || !$this->transactionDepth)
453 parent::transactionStart($asSavepoint);
456 $savepoint =
'SP_' . $this->transactionDepth;
457 $this->setQuery(
'SAVEPOINT ' . $this->quoteName($savepoint));
459 if ($this->execute())
461 $this->transactionDepth++;