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.

271 lines
8.1 KiB

24 years ago
24 years ago
24 years ago
24 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2004 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.0 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_0.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: Zeev Suraski <zeev@zend.com> |
  16. | Jouni Ahto <jouni.ahto@exdec.fi> |
  17. +----------------------------------------------------------------------+
  18. */
  19. /* $Id$ */
  20. #ifndef PHP_PGSQL_H
  21. #define PHP_PGSQL_H
  22. #if HAVE_PGSQL
  23. extern zend_module_entry pgsql_module_entry;
  24. #define pgsql_module_ptr &pgsql_module_entry
  25. #ifdef PHP_PGSQL_PRIVATE
  26. #undef SOCKET_SIZE_TYPE
  27. #include <libpq-fe.h>
  28. #ifdef PHP_WIN32
  29. #define INV_WRITE 0x00020000
  30. #define INV_READ 0x00040000
  31. #undef PHP_PGSQL_API
  32. #ifdef PGSQL_EXPORTS
  33. #define PHP_PGSQL_API __declspec(dllexport)
  34. #else
  35. #define PHP_PGSQL_API __declspec(dllimport)
  36. #endif
  37. #else
  38. #include <libpq/libpq-fs.h>
  39. #define PHP_PGSQL_API /* nothing special */
  40. #endif
  41. #ifdef HAVE_PG_CONFIG_H
  42. #include <pg_config.h>
  43. #endif
  44. #ifdef HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT
  45. const char * pg_encoding_to_char(int encoding);
  46. #endif
  47. PHP_MINIT_FUNCTION(pgsql);
  48. PHP_MSHUTDOWN_FUNCTION(pgsql);
  49. PHP_RINIT_FUNCTION(pgsql);
  50. PHP_RSHUTDOWN_FUNCTION(pgsql);
  51. PHP_MINFO_FUNCTION(pgsql);
  52. /* connection functions */
  53. PHP_FUNCTION(pg_connect);
  54. PHP_FUNCTION(pg_pconnect);
  55. PHP_FUNCTION(pg_close);
  56. PHP_FUNCTION(pg_connection_reset);
  57. PHP_FUNCTION(pg_connection_status);
  58. PHP_FUNCTION(pg_connection_busy);
  59. PHP_FUNCTION(pg_host);
  60. PHP_FUNCTION(pg_dbname);
  61. PHP_FUNCTION(pg_port);
  62. PHP_FUNCTION(pg_tty);
  63. PHP_FUNCTION(pg_options);
  64. PHP_FUNCTION(pg_version);
  65. PHP_FUNCTION(pg_ping);
  66. #if HAVE_PQPARAMETERSTATUS
  67. PHP_FUNCTION(pg_parameter_status);
  68. #endif
  69. /* query functions */
  70. PHP_FUNCTION(pg_query);
  71. PHP_FUNCTION(pg_send_query);
  72. PHP_FUNCTION(pg_cancel_query);
  73. /* result functions */
  74. PHP_FUNCTION(pg_fetch_assoc);
  75. PHP_FUNCTION(pg_fetch_array);
  76. PHP_FUNCTION(pg_fetch_object);
  77. PHP_FUNCTION(pg_fetch_result);
  78. PHP_FUNCTION(pg_fetch_row);
  79. PHP_FUNCTION(pg_fetch_all);
  80. PHP_FUNCTION(pg_affected_rows);
  81. PHP_FUNCTION(pg_get_result);
  82. PHP_FUNCTION(pg_result_seek);
  83. PHP_FUNCTION(pg_result_status);
  84. PHP_FUNCTION(pg_free_result);
  85. PHP_FUNCTION(pg_last_oid);
  86. PHP_FUNCTION(pg_num_rows);
  87. PHP_FUNCTION(pg_num_fields);
  88. PHP_FUNCTION(pg_field_name);
  89. PHP_FUNCTION(pg_field_num);
  90. PHP_FUNCTION(pg_field_size);
  91. PHP_FUNCTION(pg_field_type);
  92. PHP_FUNCTION(pg_field_prtlen);
  93. PHP_FUNCTION(pg_field_is_null);
  94. /* async message functions */
  95. PHP_FUNCTION(pg_get_notify);
  96. PHP_FUNCTION(pg_get_pid);
  97. /* error message functions */
  98. PHP_FUNCTION(pg_result_error);
  99. PHP_FUNCTION(pg_last_error);
  100. PHP_FUNCTION(pg_last_notice);
  101. /* copy functions */
  102. PHP_FUNCTION(pg_put_line);
  103. PHP_FUNCTION(pg_end_copy);
  104. PHP_FUNCTION(pg_copy_to);
  105. PHP_FUNCTION(pg_copy_from);
  106. /* large object functions */
  107. PHP_FUNCTION(pg_lo_create);
  108. PHP_FUNCTION(pg_lo_unlink);
  109. PHP_FUNCTION(pg_lo_open);
  110. PHP_FUNCTION(pg_lo_close);
  111. PHP_FUNCTION(pg_lo_read);
  112. PHP_FUNCTION(pg_lo_write);
  113. PHP_FUNCTION(pg_lo_read_all);
  114. PHP_FUNCTION(pg_lo_import);
  115. PHP_FUNCTION(pg_lo_export);
  116. PHP_FUNCTION(pg_lo_seek);
  117. PHP_FUNCTION(pg_lo_tell);
  118. /* debugging functions */
  119. PHP_FUNCTION(pg_trace);
  120. PHP_FUNCTION(pg_untrace);
  121. /* utility functions */
  122. PHP_FUNCTION(pg_client_encoding);
  123. PHP_FUNCTION(pg_set_client_encoding);
  124. #if HAVE_PQESCAPE
  125. PHP_FUNCTION(pg_escape_string);
  126. PHP_FUNCTION(pg_escape_bytea);
  127. PHP_FUNCTION(pg_unescape_bytea);
  128. #endif
  129. /* misc functions */
  130. PHP_FUNCTION(pg_meta_data);
  131. PHP_FUNCTION(pg_convert);
  132. PHP_FUNCTION(pg_insert);
  133. PHP_FUNCTION(pg_update);
  134. PHP_FUNCTION(pg_delete);
  135. PHP_FUNCTION(pg_select);
  136. /* connection options - ToDo: Add async connection option */
  137. #define PGSQL_CONNECT_FORCE_NEW (1<<1)
  138. /* php_pgsql_convert options */
  139. #define PGSQL_CONV_IGNORE_DEFAULT (1<<1) /* Do not use DEAFULT value by removing field from returned array */
  140. #define PGSQL_CONV_FORCE_NULL (1<<2) /* Convert to NULL if string is null string */
  141. #define PGSQL_CONV_IGNORE_NOT_NULL (1<<3) /* Ignore NOT NULL constraints */
  142. #define PGSQL_CONV_OPTS (PGSQL_CONV_IGNORE_DEFAULT|PGSQL_CONV_FORCE_NULL|PGSQL_CONV_IGNORE_NOT_NULL)
  143. /* php_pgsql_insert/update/select/delete options */
  144. #define PGSQL_DML_NO_CONV (1<<8) /* Do not call php_pgsql_convert() */
  145. #define PGSQL_DML_EXEC (1<<9) /* Execute query */
  146. #define PGSQL_DML_ASYNC (1<<10) /* Do async query */
  147. #define PGSQL_DML_STRING (1<<11) /* Return query string */
  148. /* exported functions */
  149. PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC);
  150. PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC);
  151. PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *values, ulong opt, char **sql TSRMLS_DC);
  152. PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *values, zval *ids, ulong opt , char **sql TSRMLS_DC);
  153. PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids, ulong opt, char **sql TSRMLS_DC);
  154. PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids, zval *ret_array, ulong opt, char **sql TSRMLS_DC);
  155. PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC);
  156. /* internal functions */
  157. static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
  158. static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  159. static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  160. static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC);
  161. static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  162. static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  163. static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
  164. typedef enum _php_pgsql_data_type {
  165. /* boolean */
  166. PG_BOOL,
  167. /* number */
  168. PG_OID,
  169. PG_INT2,
  170. PG_INT4,
  171. PG_INT8,
  172. PG_FLOAT4,
  173. PG_FLOAT8,
  174. PG_NUMERIC,
  175. PG_MONEY,
  176. /* character */
  177. PG_TEXT,
  178. PG_CHAR,
  179. PG_VARCHAR,
  180. /* time and interval */
  181. PG_UNIX_TIME,
  182. PG_UNIX_TIME_INTERVAL,
  183. PG_DATE,
  184. PG_TIME,
  185. PG_TIME_WITH_TIMEZONE,
  186. PG_TIMESTAMP,
  187. PG_TIMESTAMP_WITH_TIMEZONE,
  188. PG_INTERVAL,
  189. /* binary */
  190. PG_BYTEA,
  191. /* network */
  192. PG_CIDR,
  193. PG_INET,
  194. PG_MACADDR,
  195. /* bit */
  196. PG_BIT,
  197. PG_VARBIT,
  198. /* geometoric */
  199. PG_LINE,
  200. PG_LSEG,
  201. PG_POINT,
  202. PG_BOX,
  203. PG_PATH,
  204. PG_POLYGON,
  205. PG_CIRCLE,
  206. /* unkown and system */
  207. PG_UNKNOWN
  208. } php_pgsql_data_type;
  209. typedef struct pgLofp {
  210. PGconn *conn;
  211. int lofd;
  212. } pgLofp;
  213. typedef struct _php_pgsql_result_handle {
  214. PGconn *conn;
  215. PGresult *result;
  216. int row;
  217. } pgsql_result_handle;
  218. typedef struct _php_pgsql_notice {
  219. char *message;
  220. size_t len;
  221. } php_pgsql_notice;
  222. ZEND_BEGIN_MODULE_GLOBALS(pgsql)
  223. long default_link; /* default link when connection is omitted */
  224. long num_links,num_persistent;
  225. long max_links,max_persistent;
  226. long allow_persistent;
  227. long auto_reset_persistent;
  228. int le_lofp,le_string;
  229. int ignore_notices,log_notices;
  230. HashTable notices; /* notice message for each connection */
  231. ZEND_END_MODULE_GLOBALS(pgsql)
  232. ZEND_EXTERN_MODULE_GLOBALS(pgsql)
  233. #ifdef ZTS
  234. # define PGG(v) TSRMG(pgsql_globals_id, zend_pgsql_globals *, v)
  235. #else
  236. # define PGG(v) (pgsql_globals.v)
  237. #endif
  238. #endif
  239. #else
  240. #define pgsql_module_ptr NULL
  241. #endif
  242. #define phpext_pgsql_ptr pgsql_module_ptr
  243. #endif /* PHP_PGSQL_H */