From 53b3612fadd76b50971c3a767f04baa02d82496c Mon Sep 17 00:00:00 2001 From: Mike Zenith Date: Thu, 8 May 2014 22:38:34 +0200 Subject: [PATCH 1/2] [Driver:sqlite].clear should reset autoincrement Sqlite stores sequences differently, you have to reset them manually after clearing the table --- lib/Drivers/DML/sqlite.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/Drivers/DML/sqlite.js b/lib/Drivers/DML/sqlite.js index 63b6a043..2c15b9de 100644 --- a/lib/Drivers/DML/sqlite.js +++ b/lib/Drivers/DML/sqlite.js @@ -215,12 +215,25 @@ Driver.prototype.remove = function (table, conditions, cb) { }; Driver.prototype.clear = function (table, cb) { - var query = "DELETE FROM " + this.query.escapeId(table); + var query = "DELETE FROM " + this.query.escapeId(table), + debug = this.opts.debug; - if (this.opts.debug) { + if (debug) { require("../../Debug").sql('sqlite', query); } - this.db.all(query, cb); + this.db.all(query, function (err) { + if (err) { + return cb(err); + } + var query = "DELETE FROM " + + this.query.escapeId("sqlite_sequence") + + " WHERE name=" + this.query.escapeVal(table); + + if (debug) { + require("../../Debug").sql('sqlite', query); + } + this.db.all(query, cb); + }.bind(this)); }; Driver.prototype.valueToProperty = function (value, property) { From 051089e776e010aec9b16d8307182bede7f21687 Mon Sep 17 00:00:00 2001 From: Mike Zenith Date: Fri, 9 May 2014 00:31:16 +0200 Subject: [PATCH 2/2] bad line breaks before + sorry, wasnt paying attention --- lib/Drivers/DML/sqlite.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Drivers/DML/sqlite.js b/lib/Drivers/DML/sqlite.js index 2c15b9de..624e331a 100644 --- a/lib/Drivers/DML/sqlite.js +++ b/lib/Drivers/DML/sqlite.js @@ -225,9 +225,10 @@ Driver.prototype.clear = function (table, cb) { if (err) { return cb(err); } - var query = "DELETE FROM " - + this.query.escapeId("sqlite_sequence") - + " WHERE name=" + this.query.escapeVal(table); + var query = "DELETE FROM " + + this.query.escapeId("sqlite_sequence") + + " WHERE name=" + + this.query.escapeVal(table); if (debug) { require("../../Debug").sql('sqlite', query);