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.

sqlite_utils.h 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SRC_LIBUTIL_SQLITE_UTILS_H_
  17. #define SRC_LIBUTIL_SQLITE_UTILS_H_
  18. #include "config.h"
  19. #include "mem_pool.h"
  20. #include "sqlite3.h"
  21. #define RSPAMD_SQLITE3_STMT_MULTIPLE (1 << 0)
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. struct rspamd_sqlite3_prstmt {
  26. gint idx;
  27. const gchar *sql;
  28. const gchar *args;
  29. sqlite3_stmt *stmt;
  30. gint result;
  31. const gchar *ret;
  32. gint flags;
  33. };
  34. /**
  35. * Create prepared statements for specified database from init statements
  36. * @param db
  37. * @param max_idx
  38. * @param err
  39. * @return new prepared statements array or NULL
  40. */
  41. GArray *rspamd_sqlite3_init_prstmt(sqlite3 *db,
  42. struct rspamd_sqlite3_prstmt *init_stmt,
  43. gint max_idx,
  44. GError **err);
  45. /**
  46. * Run prepared statements by its index getting parameters and setting results from
  47. * varargs structure
  48. * @param db
  49. * @param stmts
  50. * @param idx
  51. * @return
  52. */
  53. gint rspamd_sqlite3_run_prstmt(rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
  54. gint idx, ...);
  55. /**
  56. * Close and free prepared statements
  57. * @param db
  58. * @param stmts
  59. */
  60. void rspamd_sqlite3_close_prstmt(sqlite3 *db, GArray *stmts);
  61. /**
  62. * Creates or opens sqlite database trying to share it between processes
  63. * @param path
  64. * @param create_sql
  65. * @return
  66. */
  67. sqlite3 *rspamd_sqlite3_open_or_create(rspamd_mempool_t *pool,
  68. const gchar *path, const gchar *create_sql,
  69. uint32_t version, GError **err);
  70. /**
  71. * Sync sqlite3 db ensuring that all wal things are done
  72. * @param db
  73. */
  74. gboolean rspamd_sqlite3_sync(sqlite3 *db, gint *wal_frames, gint *wal_checkpoints);
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif /* SRC_LIBUTIL_SQLITE_UTILS_H_ */