Permalink
Browse files

Sqlite::truncate(): Verify `sqlite_sequence` exists before _execute()

`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...
1 parent 8428928 commit 9d8bb8c04764ac12f8e3b70d4d0b9c1accbe6187 @rchavik rchavik committed Aug 21, 2013
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/Cake/Model/Datasource/Database/Sqlite.php
@@ -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));
}

0 comments on commit 9d8bb8c

Please sign in to comment.