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.

302 lines
8.7 KiB

21 years ago
24 years ago
24 years ago
24 years ago
24 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2005 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. #if HAVE_PGTRANSACTIONSTATUS
  70. PHP_FUNCTION(pg_transaction_status);
  71. #endif
  72. /* query functions */
  73. PHP_FUNCTION(pg_query);
  74. #if HAVE_PQEXECPARAMS
  75. PHP_FUNCTION(pg_query_params);
  76. #endif
  77. #if HAVE_PQPREPARE
  78. PHP_FUNCTION(pg_prepare);
  79. #endif
  80. #if HAVE_PQEXECPREPARED
  81. PHP_FUNCTION(pg_execute);
  82. #endif
  83. PHP_FUNCTION(pg_send_query);
  84. #if HAVE_PQSENDQUERYPARAMS
  85. PHP_FUNCTION(pg_send_query_params);
  86. #endif
  87. #if HAVE_PQSENDPREPARE
  88. PHP_FUNCTION(pg_send_prepare);
  89. #endif
  90. #if HAVE_PQSENDQUERYPREPARED
  91. PHP_FUNCTION(pg_send_execute);
  92. #endif
  93. PHP_FUNCTION(pg_cancel_query);
  94. /* result functions */
  95. PHP_FUNCTION(pg_fetch_assoc);
  96. PHP_FUNCTION(pg_fetch_array);
  97. PHP_FUNCTION(pg_fetch_object);
  98. PHP_FUNCTION(pg_fetch_result);
  99. PHP_FUNCTION(pg_fetch_row);
  100. PHP_FUNCTION(pg_fetch_all);
  101. PHP_FUNCTION(pg_fetch_all_columns);
  102. #if HAVE_PQCMDTUPLES
  103. PHP_FUNCTION(pg_affected_rows);
  104. #endif
  105. PHP_FUNCTION(pg_get_result);
  106. PHP_FUNCTION(pg_result_seek);
  107. PHP_FUNCTION(pg_result_status);
  108. PHP_FUNCTION(pg_free_result);
  109. PHP_FUNCTION(pg_last_oid);
  110. PHP_FUNCTION(pg_num_rows);
  111. PHP_FUNCTION(pg_num_fields);
  112. PHP_FUNCTION(pg_field_name);
  113. PHP_FUNCTION(pg_field_num);
  114. PHP_FUNCTION(pg_field_size);
  115. PHP_FUNCTION(pg_field_type);
  116. PHP_FUNCTION(pg_field_type_oid);
  117. PHP_FUNCTION(pg_field_prtlen);
  118. PHP_FUNCTION(pg_field_is_null);
  119. /* async message functions */
  120. PHP_FUNCTION(pg_get_notify);
  121. PHP_FUNCTION(pg_get_pid);
  122. /* error message functions */
  123. PHP_FUNCTION(pg_result_error);
  124. #if HAVE_PQRESULTERRORFIELD
  125. PHP_FUNCTION(pg_result_error_field);
  126. #endif
  127. PHP_FUNCTION(pg_last_error);
  128. PHP_FUNCTION(pg_last_notice);
  129. /* copy functions */
  130. PHP_FUNCTION(pg_put_line);
  131. PHP_FUNCTION(pg_end_copy);
  132. PHP_FUNCTION(pg_copy_to);
  133. PHP_FUNCTION(pg_copy_from);
  134. /* large object functions */
  135. PHP_FUNCTION(pg_lo_create);
  136. PHP_FUNCTION(pg_lo_unlink);
  137. PHP_FUNCTION(pg_lo_open);
  138. PHP_FUNCTION(pg_lo_close);
  139. PHP_FUNCTION(pg_lo_read);
  140. PHP_FUNCTION(pg_lo_write);
  141. PHP_FUNCTION(pg_lo_read_all);
  142. PHP_FUNCTION(pg_lo_import);
  143. PHP_FUNCTION(pg_lo_export);
  144. PHP_FUNCTION(pg_lo_seek);
  145. PHP_FUNCTION(pg_lo_tell);
  146. /* debugging functions */
  147. PHP_FUNCTION(pg_trace);
  148. PHP_FUNCTION(pg_untrace);
  149. /* utility functions */
  150. PHP_FUNCTION(pg_client_encoding);
  151. PHP_FUNCTION(pg_set_client_encoding);
  152. #if HAVE_PQSETERRORVERBOSITY
  153. PHP_FUNCTION(pg_set_error_verbosity);
  154. #endif
  155. #if HAVE_PQESCAPE
  156. PHP_FUNCTION(pg_escape_string);
  157. PHP_FUNCTION(pg_escape_bytea);
  158. PHP_FUNCTION(pg_unescape_bytea);
  159. #endif
  160. /* misc functions */
  161. PHP_FUNCTION(pg_meta_data);
  162. PHP_FUNCTION(pg_convert);
  163. PHP_FUNCTION(pg_insert);
  164. PHP_FUNCTION(pg_update);
  165. PHP_FUNCTION(pg_delete);
  166. PHP_FUNCTION(pg_select);
  167. /* connection options - ToDo: Add async connection option */
  168. #define PGSQL_CONNECT_FORCE_NEW (1<<1)
  169. /* php_pgsql_convert options */
  170. #define PGSQL_CONV_IGNORE_DEFAULT (1<<1) /* Do not use DEAFULT value by removing field from returned array */
  171. #define PGSQL_CONV_FORCE_NULL (1<<2) /* Convert to NULL if string is null string */
  172. #define PGSQL_CONV_IGNORE_NOT_NULL (1<<3) /* Ignore NOT NULL constraints */
  173. #define PGSQL_CONV_OPTS (PGSQL_CONV_IGNORE_DEFAULT|PGSQL_CONV_FORCE_NULL|PGSQL_CONV_IGNORE_NOT_NULL)
  174. /* php_pgsql_insert/update/select/delete options */
  175. #define PGSQL_DML_NO_CONV (1<<8) /* Do not call php_pgsql_convert() */
  176. #define PGSQL_DML_EXEC (1<<9) /* Execute query */
  177. #define PGSQL_DML_ASYNC (1<<10) /* Do async query */
  178. #define PGSQL_DML_STRING (1<<11) /* Return query string */
  179. /* exported functions */
  180. PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC);
  181. PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC);
  182. PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *values, ulong opt, char **sql TSRMLS_DC);
  183. PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *values, zval *ids, ulong opt , char **sql TSRMLS_DC);
  184. PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids, ulong opt, char **sql TSRMLS_DC);
  185. PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids, zval *ret_array, ulong opt, char **sql TSRMLS_DC);
  186. PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC);
  187. /* internal functions */
  188. static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
  189. static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  190. static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  191. static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC);
  192. static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  193. static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  194. static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
  195. typedef enum _php_pgsql_data_type {
  196. /* boolean */
  197. PG_BOOL,
  198. /* number */
  199. PG_OID,
  200. PG_INT2,
  201. PG_INT4,
  202. PG_INT8,
  203. PG_FLOAT4,
  204. PG_FLOAT8,
  205. PG_NUMERIC,
  206. PG_MONEY,
  207. /* character */
  208. PG_TEXT,
  209. PG_CHAR,
  210. PG_VARCHAR,
  211. /* time and interval */
  212. PG_UNIX_TIME,
  213. PG_UNIX_TIME_INTERVAL,
  214. PG_DATE,
  215. PG_TIME,
  216. PG_TIME_WITH_TIMEZONE,
  217. PG_TIMESTAMP,
  218. PG_TIMESTAMP_WITH_TIMEZONE,
  219. PG_INTERVAL,
  220. /* binary */
  221. PG_BYTEA,
  222. /* network */
  223. PG_CIDR,
  224. PG_INET,
  225. PG_MACADDR,
  226. /* bit */
  227. PG_BIT,
  228. PG_VARBIT,
  229. /* geometoric */
  230. PG_LINE,
  231. PG_LSEG,
  232. PG_POINT,
  233. PG_BOX,
  234. PG_PATH,
  235. PG_POLYGON,
  236. PG_CIRCLE,
  237. /* unkown and system */
  238. PG_UNKNOWN
  239. } php_pgsql_data_type;
  240. typedef struct pgLofp {
  241. PGconn *conn;
  242. int lofd;
  243. } pgLofp;
  244. typedef struct _php_pgsql_result_handle {
  245. PGconn *conn;
  246. PGresult *result;
  247. int row;
  248. } pgsql_result_handle;
  249. typedef struct _php_pgsql_notice {
  250. char *message;
  251. size_t len;
  252. } php_pgsql_notice;
  253. ZEND_BEGIN_MODULE_GLOBALS(pgsql)
  254. long default_link; /* default link when connection is omitted */
  255. long num_links,num_persistent;
  256. long max_links,max_persistent;
  257. long allow_persistent;
  258. long auto_reset_persistent;
  259. int le_lofp,le_string;
  260. int ignore_notices,log_notices;
  261. HashTable notices; /* notice message for each connection */
  262. ZEND_END_MODULE_GLOBALS(pgsql)
  263. ZEND_EXTERN_MODULE_GLOBALS(pgsql)
  264. #ifdef ZTS
  265. # define PGG(v) TSRMG(pgsql_globals_id, zend_pgsql_globals *, v)
  266. #else
  267. # define PGG(v) (pgsql_globals.v)
  268. #endif
  269. #endif
  270. #else
  271. #define pgsql_module_ptr NULL
  272. #endif
  273. #define phpext_pgsql_ptr pgsql_module_ptr
  274. #endif /* PHP_PGSQL_H */