php_sqlite3_structs.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Scott MacVicar <scottmac@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifndef PHP_SQLITE_STRUCTS_H
  19. #define PHP_SQLITE_STRUCTS_H
  20. #include <sqlite3.h>
  21. /* for backwards compatibility reasons */
  22. #ifndef SQLITE_OPEN_READONLY
  23. #define SQLITE_OPEN_READONLY 0x00000001
  24. #endif
  25. #ifndef SQLITE_OPEN_READWRITE
  26. #define SQLITE_OPEN_READWRITE 0x00000002
  27. #endif
  28. #ifndef SQLITE_OPEN_CREATE
  29. #define SQLITE_OPEN_CREATE 0x00000004
  30. #endif
  31. /* Structure for SQLite Statement Parameter. */
  32. struct php_sqlite3_bound_param {
  33. zend_long param_number;
  34. zend_string *name;
  35. zend_long type;
  36. zval parameter;
  37. };
  38. struct php_sqlite3_fci {
  39. zend_fcall_info fci;
  40. zend_fcall_info_cache fcc;
  41. };
  42. /* Structure for SQLite function. */
  43. typedef struct _php_sqlite3_func {
  44. struct _php_sqlite3_func *next;
  45. const char *func_name;
  46. int argc;
  47. zval func, step, fini;
  48. struct php_sqlite3_fci afunc, astep, afini;
  49. } php_sqlite3_func;
  50. /* Structure for SQLite collation function */
  51. typedef struct _php_sqlite3_collation {
  52. struct _php_sqlite3_collation *next;
  53. const char *collation_name;
  54. zval cmp_func;
  55. struct php_sqlite3_fci fci;
  56. } php_sqlite3_collation;
  57. /* Structure for SQLite Database object. */
  58. typedef struct _php_sqlite3_db_object {
  59. int initialised;
  60. sqlite3 *db;
  61. php_sqlite3_func *funcs;
  62. php_sqlite3_collation *collations;
  63. zend_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. int complete; // unused
  90. zend_object zo;
  91. };
  92. static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj) {
  93. return (php_sqlite3_result*)((char*)(obj) - XtOffsetOf(php_sqlite3_result, zo));
  94. }
  95. #define Z_SQLITE3_RESULT_P(zv) php_sqlite3_result_from_obj(Z_OBJ_P((zv)))
  96. /* Structure for SQLite Statement object. */
  97. struct _php_sqlite3_stmt_object {
  98. sqlite3_stmt *stmt;
  99. php_sqlite3_db_object *db_obj;
  100. zval db_obj_zval;
  101. int initialised;
  102. /* Keep track of the zvals for bound parameters */
  103. HashTable *bound_params;
  104. zend_object zo;
  105. };
  106. static inline php_sqlite3_stmt *php_sqlite3_stmt_from_obj(zend_object *obj) {
  107. return (php_sqlite3_stmt*)((char*)(obj) - XtOffsetOf(php_sqlite3_stmt, zo));
  108. }
  109. #define Z_SQLITE3_STMT_P(zv) php_sqlite3_stmt_from_obj(Z_OBJ_P((zv)))
  110. #endif
  111. /*
  112. * Local variables:
  113. * tab-width: 4
  114. * c-basic-offset: 4
  115. * indent-tabs-mode: t
  116. * End:
  117. */