Skip to content

Commit

Permalink
Sqlite::truncate(): Verify sqlite_sequence exists before _execute()
Browse files Browse the repository at this point in the history
`sqlite_sequence` is a dynamic table that's only available when a table in
the database use an auto increment field.  For some cases, eg: databases that
exclusively use uuid for primary keys, this table won't exist and
truncate() call will fail with:

  Error: SQLSTATE[HY000]: General error: 1 no such table: sqlite_sequence
  • Loading branch information
rchavik committed Aug 21, 2013
1 parent 8428928 commit 9d8bb8c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -230,7 +230,9 @@ public function update(Model $model, $fields = array(), $values = null, $conditi
* @return boolean SQL TRUNCATE TABLE statement, false if not applicable.
*/
public function truncate($table) {
$this->_execute('DELETE FROM sqlite_sequence where name=' . $this->startQuote . $this->fullTableName($table, false, false) . $this->endQuote);
if (in_array('sqlite_sequence', $this->listSources())) {
$this->_execute('DELETE FROM sqlite_sequence where name=' . $this->startQuote . $this->fullTableName($table, false, false) . $this->endQuote);
}
return $this->execute('DELETE FROM ' . $this->fullTableName($table));
}

Expand Down

0 comments on commit 9d8bb8c

Please sign in to comment.