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.

307 lines
8.9 KiB

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