It will be always get 'database table is locked' message when trying to delete a record after select.
I'v tested on WinXP and Ubuntu 5.10, but got the same error. SQLite version v3.2.8 please see the following code #include <cstdio> #include <cstdlib> #include <sqlite3.h> #define DATFILE "test.dat" int main(int argc, char *argv[]) { // sqlite sqlite3 *db = 0; sqlite3_stmt *stmt = 0; char *sql; int rc; int id = 0; // Open the database if (SQLITE_OK != sqlite3_open(DATFILE, &db)) { printf("!!! Couldn't open the database - %s\n", DATFILE); exit(1); } sqlite3_busy_timeout(db, 3000); if (SQLITE_OK != sqlite3_prepare(db, "SELECT ProxyId, Host, Port FROM ss_proxy", -1, &stmt, 0)) { printf("!!! sqlite3_prepare::%s", sqlite3_errmsg(db)); sqlite3_close(db); exit(1); } //sqlite3_exec(db, "BEGIN;", 0, 0, 0); while (SQLITE_ROW == sqlite3_step(stmt)) { id = sqlite3_column_int(stmt, 0); printf("*** %d. %s:%d\n", sqlite3_column_int(stmt, 0), sqlite3_column_text(stmt, 1), sqlite3_column_int(stmt, 2)); // i will do something with every record, currently simple use '(id == 1742 || id == 1743)' instead of if (id == 1742 || id == 1743) { //sqlite3_reset(stmt); // database table is locked - [rc=6] sql = sqlite3_mprintf("DELETE FROM ss_proxy WHERE ProxyId=%d;", id); rc = sqlite3_exec(db, sql, 0, 0, 0); if (SQLITE_OK != rc) { printf("*** delete failed - %s - [rc=%d]\n", sqlite3_errmsg (db), rc); } else { printf("*** %d record deleted!\n", sqlite3_changes(db)); } sqlite3_free(sql); } }; //sqlite3_exec(db, "COMMIT;", 0, 0, 0); sqlite3_finalize(stmt); // Close the database sqlite3_close(db); return 0; }