SQLite Prepared Statements not Inserting if bind text contains dash -
i run problem text field of table cannot bind string containing dash. if remove or replace dash/dashes against character prepared , bind statement works fine.
here 2 code fragments. demo table "create table mytable (sometime text)"
//do not work... runs commit!! add nothing mytable int result = sqlite3_exec(validsqlite3, "begin;", nullptr, nullptr, nullptr); if (result != sqlite_ok) return; sqlite3_stmt* stmt = nullptr; bool ok = true; if (sqlite3_prepare_v2(validsqlite3, "insert mytable (sometime) values (?);", -1, &stmt, nullptr) != sqlite_ok) ok = false; if (ok && sqlite3_bind_text(stmt, 1, "2016-11-01 12:00:00", -1, sqlite_transient) != sqlite_ok) ok = false; if (ok && sqlite3_step(stmt) != sqlite_done) ok = false; if (ok && sqlite3_finalize(stmt) != sqlite_ok) ok = false; if (ok) sqlite3_exec(validsqlite3, "commit;", nullptr, nullptr, nullptr); else sqlite3_exec(validsqlite3, "rollback;", nullptr, nullptr, nullptr); //same code above... but: no dashes in text field //works fine... runs commit , inserts new row in mytable column sometime content: "2016/11/01 12:00:00" int result = sqlite3_exec(validsqlite3, "begin;", nullptr, nullptr, nullptr); if (result != sqlite_ok) return; sqlite3_stmt* stmt = nullptr; bool ok = true; if (sqlite3_prepare_v2(validsqlite3, "insert mytable (sometime) values (?);", -1, &stmt, nullptr) != sqlite_ok) ok = false; if (ok && sqlite3_bind_text(stmt, 1, "2016/11/01 12:00:00", -1, sqlite_transient) != sqlite_ok) ok = false; if (ok && sqlite3_step(stmt) != sqlite_done) ok = false; if (ok && sqlite3_finalize(stmt) != sqlite_ok) ok = false; if (ok) sqlite3_exec(validsqlite3, "commit;", nullptr, nullptr, nullptr); else sqlite3_exec(validsqlite3, "rollback;", nullptr, nullptr, nullptr);
Comments
Post a Comment