php_ibase_includes.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 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: Jouni Ahto <jouni.ahto@exdec.fi> |
  16. | Andrew Avdeev <andy@simgts.mv.ru> |
  17. | Ard Biesheuvel <a.k.biesheuvel@ewi.tudelft.nl> |
  18. +----------------------------------------------------------------------+
  19. */
  20. #ifndef PHP_IBASE_INCLUDES_H
  21. #define PHP_IBASE_INCLUDES_H
  22. #include <ibase.h>
  23. #ifndef SQLDA_CURRENT_VERSION
  24. #define SQLDA_CURRENT_VERSION SQLDA_VERSION1
  25. #endif
  26. #ifndef METADATALENGTH
  27. #define METADATALENGTH 68
  28. #endif
  29. #define RESET_ERRMSG do { IBG(errmsg)[0] = '\0'; IBG(sql_code) = 0; } while (0)
  30. #define IB_STATUS (IBG(status))
  31. /* XXX ZEND_DEBUG_ is misleading, it should be something like IBASE_DEBUG. */
  32. #ifdef ZEND_DEBUG_
  33. #define IBDEBUG(a) php_printf("::: %s (%d)\n", a, __LINE__);
  34. #endif
  35. #ifndef IBDEBUG
  36. #define IBDEBUG(a)
  37. #endif
  38. extern int le_link, le_plink, le_trans;
  39. #define LE_LINK "Firebird/InterBase link"
  40. #define LE_PLINK "Firebird/InterBase persistent link"
  41. #define LE_TRANS "Firebird/InterBase transaction"
  42. #define IBASE_MSGSIZE 512
  43. #define MAX_ERRMSG (IBASE_MSGSIZE*2)
  44. #define IB_DEF_DATE_FMT "%Y-%m-%d"
  45. #define IB_DEF_TIME_FMT "%H:%M:%S"
  46. /* this value should never be > USHRT_MAX */
  47. #define IBASE_BLOB_SEG 4096
  48. ZEND_BEGIN_MODULE_GLOBALS(ibase)
  49. ISC_STATUS status[20];
  50. long default_link;
  51. long num_links, num_persistent;
  52. char errmsg[MAX_ERRMSG];
  53. long sql_code;
  54. ZEND_END_MODULE_GLOBALS(ibase)
  55. ZEND_EXTERN_MODULE_GLOBALS(ibase)
  56. typedef struct {
  57. isc_db_handle handle;
  58. struct tr_list *tr_list;
  59. unsigned short dialect;
  60. struct event *event_head;
  61. } ibase_db_link;
  62. typedef struct {
  63. isc_tr_handle handle;
  64. unsigned short link_cnt;
  65. unsigned long affected_rows;
  66. ibase_db_link *db_link[1]; /* last member */
  67. } ibase_trans;
  68. typedef struct tr_list {
  69. ibase_trans *trans;
  70. struct tr_list *next;
  71. } ibase_tr_list;
  72. typedef struct {
  73. isc_blob_handle bl_handle;
  74. unsigned short type;
  75. ISC_QUAD bl_qd;
  76. } ibase_blob;
  77. typedef struct event {
  78. ibase_db_link *link;
  79. long link_res_id;
  80. ISC_LONG event_id;
  81. unsigned short event_count;
  82. char **events;
  83. char *event_buffer, *result_buffer;
  84. zval *callback;
  85. void **thread_ctx;
  86. struct event *event_next;
  87. enum event_state { NEW, ACTIVE, DEAD } state;
  88. } ibase_event;
  89. enum php_interbase_option {
  90. PHP_IBASE_DEFAULT = 0,
  91. PHP_IBASE_CREATE = 0,
  92. /* fetch flags */
  93. PHP_IBASE_FETCH_BLOBS = 1,
  94. PHP_IBASE_FETCH_ARRAYS = 2,
  95. PHP_IBASE_UNIXTIME = 4,
  96. /* transaction access mode */
  97. PHP_IBASE_WRITE = 1,
  98. PHP_IBASE_READ = 2,
  99. /* transaction isolation level */
  100. PHP_IBASE_CONCURRENCY = 4,
  101. PHP_IBASE_COMMITTED = 8,
  102. PHP_IBASE_REC_NO_VERSION = 32,
  103. PHP_IBASE_REC_VERSION = 64,
  104. PHP_IBASE_CONSISTENCY = 16,
  105. /* transaction lock resolution */
  106. PHP_IBASE_WAIT = 128,
  107. PHP_IBASE_NOWAIT = 256
  108. };
  109. #ifdef ZTS
  110. #define IBG(v) TSRMG(ibase_globals_id, zend_ibase_globals *, v)
  111. #else
  112. #define IBG(v) (ibase_globals.v)
  113. #endif
  114. #define BLOB_ID_LEN 18
  115. #define BLOB_ID_MASK "0x%" LL_MASK "x"
  116. #define BLOB_INPUT 1
  117. #define BLOB_OUTPUT 2
  118. #ifdef PHP_WIN32
  119. #define LL_MASK "I64"
  120. #define LL_LIT(lit) lit ## I64
  121. typedef void (__stdcall *info_func_t)(char*);
  122. #else
  123. #define LL_MASK "ll"
  124. #define LL_LIT(lit) lit ## ll
  125. typedef void (*info_func_t)(char*);
  126. #endif
  127. void _php_ibase_error(TSRMLS_D);
  128. void _php_ibase_module_error(char * TSRMLS_DC, ...)
  129. PHP_ATTRIBUTE_FORMAT(printf,1,PHP_ATTR_FMT_OFFSET +2);
  130. /* determine if a resource is a link or transaction handle */
  131. #define PHP_IBASE_LINK_TRANS(pzval, lh, th) \
  132. do { if (!pzval) { \
  133. ZEND_FETCH_RESOURCE2(lh, ibase_db_link *, NULL, IBG(default_link), \
  134. "InterBase link", le_link, le_plink) } \
  135. else \
  136. _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAM_PASSTHRU, &pzval, &lh, &th); \
  137. if (SUCCESS != _php_ibase_def_trans(lh, &th TSRMLS_CC)) { RETURN_FALSE; } \
  138. } while (0)
  139. int _php_ibase_def_trans(ibase_db_link *ib_link, ibase_trans **trans TSRMLS_DC);
  140. void _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAMETERS, zval **link_id,
  141. ibase_db_link **ib_link, ibase_trans **trans);
  142. /* provided by ibase_query.c */
  143. void php_ibase_query_minit(INIT_FUNC_ARGS);
  144. /* provided by ibase_blobs.c */
  145. void php_ibase_blobs_minit(INIT_FUNC_ARGS);
  146. int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd);
  147. char *_php_ibase_quad_to_string(ISC_QUAD const qd);
  148. int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, unsigned long max_len TSRMLS_DC);
  149. int _php_ibase_blob_add(zval **string_arg, ibase_blob *ib_blob TSRMLS_DC);
  150. /* provided by ibase_events.c */
  151. void php_ibase_events_minit(INIT_FUNC_ARGS);
  152. void _php_ibase_free_event(ibase_event *event TSRMLS_DC);
  153. /* provided by ibase_service.c */
  154. void php_ibase_service_minit(INIT_FUNC_ARGS);
  155. #ifndef max
  156. #define max(a,b) ((a)>(b)?(a):(b))
  157. #endif
  158. #endif /* PHP_IBASE_INCLUDES_H */
  159. /*
  160. * Local variables:
  161. * tab-width: 4
  162. * c-basic-offset: 4
  163. * End:
  164. */