php_pgsql.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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: Zeev Suraski <zeev@php.net> |
  14. | Jouni Ahto <jouni.ahto@exdec.fi> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifndef PHP_PGSQL_H
  18. #define PHP_PGSQL_H
  19. #ifdef HAVE_PGSQL
  20. #define PHP_PGSQL_API_VERSION 20140217
  21. extern zend_module_entry pgsql_module_entry;
  22. #define pgsql_module_ptr &pgsql_module_entry
  23. #include "php_version.h"
  24. #define PHP_PGSQL_VERSION PHP_VERSION
  25. #ifdef PHP_PGSQL_PRIVATE
  26. #undef SOCKET_SIZE_TYPE
  27. #include <libpq-fe.h>
  28. #include <libpq/libpq-fs.h>
  29. #ifdef PHP_WIN32
  30. #undef PHP_PGSQL_API
  31. #ifdef PGSQL_EXPORTS
  32. #define PHP_PGSQL_API __declspec(dllexport)
  33. #else
  34. #define PHP_PGSQL_API __declspec(dllimport)
  35. #endif
  36. #else
  37. # if defined(__GNUC__) && __GNUC__ >= 4
  38. # define PHP_PGSQL_API __attribute__ ((visibility("default")))
  39. # else
  40. # define PHP_PGSQL_API
  41. # endif
  42. #endif
  43. #ifdef HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT
  44. const char * pg_encoding_to_char(int encoding);
  45. #endif
  46. PHP_MINIT_FUNCTION(pgsql);
  47. PHP_MSHUTDOWN_FUNCTION(pgsql);
  48. PHP_RINIT_FUNCTION(pgsql);
  49. PHP_RSHUTDOWN_FUNCTION(pgsql);
  50. PHP_MINFO_FUNCTION(pgsql);
  51. /* connection options - ToDo: Add async connection option */
  52. #define PGSQL_CONNECT_FORCE_NEW (1<<1)
  53. #define PGSQL_CONNECT_ASYNC (1<<2)
  54. /* php_pgsql_convert options */
  55. #define PGSQL_CONV_IGNORE_DEFAULT (1<<1) /* Do not use DEFAULT value by removing field from returned array */
  56. #define PGSQL_CONV_FORCE_NULL (1<<2) /* Convert to NULL if string is null string */
  57. #define PGSQL_CONV_IGNORE_NOT_NULL (1<<3) /* Ignore NOT NULL constraints */
  58. #define PGSQL_CONV_OPTS (PGSQL_CONV_IGNORE_DEFAULT|PGSQL_CONV_FORCE_NULL|PGSQL_CONV_IGNORE_NOT_NULL)
  59. /* php_pgsql_insert/update/select/delete options */
  60. #define PGSQL_DML_NO_CONV (1<<8) /* Do not call php_pgsql_convert() */
  61. #define PGSQL_DML_EXEC (1<<9) /* Execute query */
  62. #define PGSQL_DML_ASYNC (1<<10) /* Do async query */
  63. #define PGSQL_DML_STRING (1<<11) /* Return query string */
  64. #define PGSQL_DML_ESCAPE (1<<12) /* No convert, but escape only */
  65. /* exported functions */
  66. PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const zend_string *table_name, zval *meta, bool extended);
  67. PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *table_name, const zval *values, zval *result, zend_ulong opt);
  68. PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *table, zval *values, zend_ulong opt, zend_string **sql);
  69. PHP_PGSQL_API zend_result php_pgsql_update(PGconn *pg_link, const zend_string *table, zval *values, zval *ids, zend_ulong opt , zend_string **sql);
  70. PHP_PGSQL_API zend_result php_pgsql_delete(PGconn *pg_link, const zend_string *table, zval *ids, zend_ulong opt, zend_string **sql);
  71. PHP_PGSQL_API zend_result php_pgsql_select(PGconn *pg_link, const zend_string *table, zval *ids, zval *ret_array, zend_ulong opt, long fetch_option, zend_string **sql );
  72. PHP_PGSQL_API void php_pgsql_result2array(PGresult *pg_result, zval *ret_array, long fetch_option);
  73. /* internal functions */
  74. static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
  75. static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  76. static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  77. static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  78. static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  79. static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
  80. static ssize_t php_pgsql_fd_write(php_stream *stream, const char *buf, size_t count);
  81. static ssize_t php_pgsql_fd_read(php_stream *stream, char *buf, size_t count);
  82. static int php_pgsql_fd_close(php_stream *stream, int close_handle);
  83. static int php_pgsql_fd_flush(php_stream *stream);
  84. static int php_pgsql_fd_set_option(php_stream *stream, int option, int value, void *ptrparam);
  85. static int php_pgsql_fd_cast(php_stream *stream, int cast_as, void **ret);
  86. typedef enum _php_pgsql_data_type {
  87. /* boolean */
  88. PG_BOOL,
  89. /* number */
  90. PG_OID,
  91. PG_INT2,
  92. PG_INT4,
  93. PG_INT8,
  94. PG_FLOAT4,
  95. PG_FLOAT8,
  96. PG_NUMERIC,
  97. PG_MONEY,
  98. /* character */
  99. PG_TEXT,
  100. PG_CHAR,
  101. PG_VARCHAR,
  102. /* time and interval */
  103. PG_UNIX_TIME,
  104. PG_UNIX_TIME_INTERVAL,
  105. PG_DATE,
  106. PG_TIME,
  107. PG_TIME_WITH_TIMEZONE,
  108. PG_TIMESTAMP,
  109. PG_TIMESTAMP_WITH_TIMEZONE,
  110. PG_INTERVAL,
  111. /* binary */
  112. PG_BYTEA,
  113. /* network */
  114. PG_CIDR,
  115. PG_INET,
  116. PG_MACADDR,
  117. /* bit */
  118. PG_BIT,
  119. PG_VARBIT,
  120. /* geometoric */
  121. PG_LINE,
  122. PG_LSEG,
  123. PG_POINT,
  124. PG_BOX,
  125. PG_PATH,
  126. PG_POLYGON,
  127. PG_CIRCLE,
  128. /* unknown and system */
  129. PG_UNKNOWN
  130. } php_pgsql_data_type;
  131. typedef struct pgsql_link_handle {
  132. PGconn *conn;
  133. zend_string *hash;
  134. HashTable *notices;
  135. bool persistent;
  136. zend_object std;
  137. } pgsql_link_handle;
  138. typedef struct pgLofp {
  139. PGconn *conn;
  140. int lofd;
  141. zend_object std;
  142. } pgLofp;
  143. typedef struct _php_pgsql_result_handle {
  144. PGconn *conn;
  145. PGresult *result;
  146. int row;
  147. zend_object std;
  148. } pgsql_result_handle;
  149. typedef struct _php_pgsql_notice {
  150. char *message;
  151. size_t len;
  152. } php_pgsql_notice;
  153. static const php_stream_ops php_stream_pgsql_fd_ops = {
  154. php_pgsql_fd_write,
  155. php_pgsql_fd_read,
  156. php_pgsql_fd_close,
  157. php_pgsql_fd_flush,
  158. "PostgreSQL link",
  159. NULL, /* seek */
  160. php_pgsql_fd_cast, /* cast */
  161. NULL, /* stat */
  162. php_pgsql_fd_set_option
  163. };
  164. ZEND_BEGIN_MODULE_GLOBALS(pgsql)
  165. zend_long num_links,num_persistent;
  166. zend_long max_links,max_persistent;
  167. zend_long allow_persistent;
  168. zend_long auto_reset_persistent;
  169. int ignore_notices,log_notices;
  170. zend_object *default_link; /* default link when connection is omitted */
  171. HashTable field_oids;
  172. HashTable table_oids;
  173. HashTable connections;
  174. ZEND_END_MODULE_GLOBALS(pgsql)
  175. ZEND_EXTERN_MODULE_GLOBALS(pgsql)
  176. # define PGG(v) ZEND_MODULE_GLOBALS_ACCESSOR(pgsql, v)
  177. #if defined(ZTS) && defined(COMPILE_DL_PGSQL)
  178. ZEND_TSRMLS_CACHE_EXTERN()
  179. #endif
  180. #endif
  181. #else
  182. #define pgsql_module_ptr NULL
  183. #endif
  184. #define phpext_pgsql_ptr pgsql_module_ptr
  185. #endif /* PHP_PGSQL_H */