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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. struct rspamd_sqlite3_prstmt {
  23. gint idx;
  24. const gchar *sql;
  25. const gchar *args;
  26. sqlite3_stmt *stmt;
  27. gint result;
  28. const gchar *ret;
  29. gint flags;
  30. };
  31. /**
  32. * Create prepared statements for specified database from init statements
  33. * @param db
  34. * @param max_idx
  35. * @param err
  36. * @return new prepared statements array or NULL
  37. */
  38. GArray* rspamd_sqlite3_init_prstmt (sqlite3 *db,
  39. struct rspamd_sqlite3_prstmt *init_stmt,
  40. gint max_idx,
  41. GError **err);
  42. /**
  43. * Run prepared statements by its index getting parameters and setting results from
  44. * varargs structure
  45. * @param db
  46. * @param stmts
  47. * @param idx
  48. * @return
  49. */
  50. gint rspamd_sqlite3_run_prstmt (rspamd_mempool_t *pool, sqlite3 *db, GArray *stmts,
  51. gint idx, ...);
  52. /**
  53. * Close and free prepared statements
  54. * @param db
  55. * @param stmts
  56. */
  57. void rspamd_sqlite3_close_prstmt (sqlite3 *db, GArray *stmts);
  58. /**
  59. * Creates or opens sqlite database trying to share it between processes
  60. * @param path
  61. * @param create_sql
  62. * @return
  63. */
  64. sqlite3 * rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
  65. gchar *create_sql, guint32 version, GError **err);
  66. /**
  67. * Sync sqlite3 db ensuring that all wal things are done
  68. * @param db
  69. */
  70. gboolean rspamd_sqlite3_sync (sqlite3 *db, gint *wal_frames, gint *wal_checkpoints);
  71. #endif /* SRC_LIBUTIL_SQLITE_UTILS_H_ */