Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. //do not work... runs into commit!! but add nothing to MyTable
  2. int result = sqlite3_exec(validSqlite3, "begin;", nullptr, nullptr, nullptr);
  3. if (result != SQLITE_OK)
  4. return;
  5. sqlite3_stmt* stmt = nullptr;
  6. bool ok = true;
  7. if (sqlite3_prepare_v2(validSqlite3, "insert into MyTable (SomeTime) values (?);", -1, &stmt, nullptr) != SQLITE_OK)
  8. ok = false;
  9. if (ok && sqlite3_bind_text(stmt, 1, "2016-11-01 12:00:00", -1, SQLITE_TRANSIENT) != SQLITE_OK)
  10. ok = false;
  11. if (ok && sqlite3_step(stmt) != SQLITE_DONE)
  12. ok = false;
  13. if (ok && sqlite3_finalize(stmt) != SQLITE_OK)
  14. ok = false;
  15. if (ok)
  16. sqlite3_exec(validSqlite3, "commit;", nullptr, nullptr, nullptr);
  17. else
  18. sqlite3_exec(validSqlite3, "rollback;", nullptr, nullptr, nullptr);
  19.  
  20. //same code as above... BUT: no dashes in the text field
  21. //works fine... runs into commit and inserts a new row in MyTable with column SomeTime content: "2016/11/01 12:00:00"
  22. int result = sqlite3_exec(validSqlite3, "begin;", nullptr, nullptr, nullptr);
  23. if (result != SQLITE_OK)
  24. return;
  25. sqlite3_stmt* stmt = nullptr;
  26. bool ok = true;
  27. if (sqlite3_prepare_v2(validSqlite3, "insert into MyTable (SomeTime) values (?);", -1, &stmt, nullptr) != SQLITE_OK)
  28. ok = false;
  29. if (ok && sqlite3_bind_text(stmt, 1, "2016/11/01 12:00:00", -1, SQLITE_TRANSIENT) != SQLITE_OK)
  30. ok = false;
  31. if (ok && sqlite3_step(stmt) != SQLITE_DONE)
  32. ok = false;
  33. if (ok && sqlite3_finalize(stmt) != SQLITE_OK)
  34. ok = false;
  35. if (ok)
  36. sqlite3_exec(validSqlite3, "commit;", nullptr, nullptr, nullptr);
  37. else
  38. sqlite3_exec(validSqlite3, "rollback;", nullptr, nullptr, nullptr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement