本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.7KB

  1. // Copyright (C) 2018 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
  2. //
  3. // Use of this source code is governed by an MIT-style
  4. // license that can be found in the LICENSE file.
  5. #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
  6. #include <stdio.h>
  7. #include <sqlite3-binding.h>
  8. extern int unlock_notify_wait(sqlite3 *db);
  9. int
  10. _sqlite3_step_blocking(sqlite3_stmt *stmt)
  11. {
  12. int rv;
  13. sqlite3* db;
  14. db = sqlite3_db_handle(stmt);
  15. for (;;) {
  16. rv = sqlite3_step(stmt);
  17. if (rv != SQLITE_LOCKED) {
  18. break;
  19. }
  20. if (sqlite3_extended_errcode(db) != SQLITE_LOCKED_SHAREDCACHE) {
  21. break;
  22. }
  23. rv = unlock_notify_wait(db);
  24. if (rv != SQLITE_OK) {
  25. break;
  26. }
  27. sqlite3_reset(stmt);
  28. }
  29. return rv;
  30. }
  31. int
  32. _sqlite3_step_row_blocking(sqlite3_stmt* stmt, long long* rowid, long long* changes)
  33. {
  34. int rv;
  35. sqlite3* db;
  36. db = sqlite3_db_handle(stmt);
  37. for (;;) {
  38. rv = sqlite3_step(stmt);
  39. if (rv!=SQLITE_LOCKED) {
  40. break;
  41. }
  42. if (sqlite3_extended_errcode(db) != SQLITE_LOCKED_SHAREDCACHE) {
  43. break;
  44. }
  45. rv = unlock_notify_wait(db);
  46. if (rv != SQLITE_OK) {
  47. break;
  48. }
  49. sqlite3_reset(stmt);
  50. }
  51. *rowid = (long long) sqlite3_last_insert_rowid(db);
  52. *changes = (long long) sqlite3_changes(db);
  53. return rv;
  54. }
  55. int
  56. _sqlite3_prepare_v2_blocking(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail)
  57. {
  58. int rv;
  59. for (;;) {
  60. rv = sqlite3_prepare_v2(db, zSql, nBytes, ppStmt, pzTail);
  61. if (rv!=SQLITE_LOCKED) {
  62. break;
  63. }
  64. if (sqlite3_extended_errcode(db) != SQLITE_LOCKED_SHAREDCACHE) {
  65. break;
  66. }
  67. rv = unlock_notify_wait(db);
  68. if (rv != SQLITE_OK) {
  69. break;
  70. }
  71. }
  72. return rv;
  73. }
  74. #endif
上海开阖软件有限公司 沪ICP备12045867号-1