php_sqlite3_structs.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Scott MacVicar <scottmac@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef PHP_SQLITE_STRUCTS_H
  17. #define PHP_SQLITE_STRUCTS_H
  18. #include <sqlite3.h>
  19. /* for backwards compatibility reasons */
  20. #ifndef SQLITE_OPEN_READONLY
  21. #define SQLITE_OPEN_READONLY 0x00000001
  22. #endif
  23. #ifndef SQLITE_OPEN_READWRITE
  24. #define SQLITE_OPEN_READWRITE 0x00000002
  25. #endif
  26. #ifndef SQLITE_OPEN_CREATE
  27. #define SQLITE_OPEN_CREATE 0x00000004
  28. #endif
  29. /* Structure for SQLite Statement Parameter. */
  30. struct php_sqlite3_bound_param {
  31. zend_long param_number;
  32. zend_string *name;
  33. zend_long type;
  34. zval parameter;
  35. };
  36. struct php_sqlite3_fci {
  37. zend_fcall_info fci;
  38. zend_fcall_info_cache fcc;
  39. };
  40. /* Structure for SQLite function. */
  41. typedef struct _php_sqlite3_func {
  42. struct _php_sqlite3_func *next;
  43. const char *func_name;
  44. int argc;
  45. zval func, step, fini;
  46. struct php_sqlite3_fci afunc, astep, afini;
  47. } php_sqlite3_func;
  48. /* Structure for SQLite collation function */
  49. typedef struct _php_sqlite3_collation {
  50. struct _php_sqlite3_collation *next;
  51. const char *collation_name;
  52. zval cmp_func;
  53. struct php_sqlite3_fci fci;
  54. } php_sqlite3_collation;
  55. /* Structure for SQLite Database object. */
  56. typedef struct _php_sqlite3_db_object {
  57. int initialised;
  58. sqlite3 *db;
  59. php_sqlite3_func *funcs;
  60. php_sqlite3_collation *collations;
  61. zend_fcall_info authorizer_fci;
  62. zend_fcall_info_cache authorizer_fcc;
  63. bool exception;
  64. zend_llist free_list;
  65. zend_object zo;
  66. } php_sqlite3_db_object;
  67. static inline php_sqlite3_db_object *php_sqlite3_db_from_obj(zend_object *obj) {
  68. return (php_sqlite3_db_object*)((char*)(obj) - XtOffsetOf(php_sqlite3_db_object, zo));
  69. }
  70. #define Z_SQLITE3_DB_P(zv) php_sqlite3_db_from_obj(Z_OBJ_P((zv)))
  71. /* Structure for SQLite Database object. */
  72. typedef struct _php_sqlite3_agg_context {
  73. zval zval_context;
  74. zend_long row_count;
  75. } php_sqlite3_agg_context;
  76. typedef struct _php_sqlite3_stmt_object php_sqlite3_stmt;
  77. typedef struct _php_sqlite3_result_object php_sqlite3_result;
  78. /* sqlite3 objects to be destroyed */
  79. typedef struct _php_sqlite3_free_list {
  80. zval stmt_obj_zval;
  81. php_sqlite3_stmt *stmt_obj;
  82. } php_sqlite3_free_list;
  83. /* Structure for SQLite Result object. */
  84. struct _php_sqlite3_result_object {
  85. php_sqlite3_db_object *db_obj;
  86. php_sqlite3_stmt *stmt_obj;
  87. zval stmt_obj_zval;
  88. int is_prepared_statement;
  89. zend_object zo;
  90. };
  91. static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj) {
  92. return (php_sqlite3_result*)((char*)(obj) - XtOffsetOf(php_sqlite3_result, zo));
  93. }
  94. #define Z_SQLITE3_RESULT_P(zv) php_sqlite3_result_from_obj(Z_OBJ_P((zv)))
  95. /* Structure for SQLite Statement object. */
  96. struct _php_sqlite3_stmt_object {
  97. sqlite3_stmt *stmt;
  98. php_sqlite3_db_object *db_obj;
  99. zval db_obj_zval;
  100. int initialised;
  101. /* Keep track of the zvals for bound parameters */
  102. HashTable *bound_params;
  103. zend_object zo;
  104. };
  105. static inline php_sqlite3_stmt *php_sqlite3_stmt_from_obj(zend_object *obj) {
  106. return (php_sqlite3_stmt*)((char*)(obj) - XtOffsetOf(php_sqlite3_stmt, zo));
  107. }
  108. #define Z_SQLITE3_STMT_P(zv) php_sqlite3_stmt_from_obj(Z_OBJ_P((zv)))
  109. #endif