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.

312 lines
9.0 KiB

12 years ago
24 years ago
24 years ago
24 years ago
24 years ago
12 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2014 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. #if HAVE_PG_LO_TRUNCATE
  152. PHP_FUNCTION(pg_lo_truncate);
  153. #endif
  154. /* debugging functions */
  155. PHP_FUNCTION(pg_trace);
  156. PHP_FUNCTION(pg_untrace);
  157. /* utility functions */
  158. PHP_FUNCTION(pg_client_encoding);
  159. PHP_FUNCTION(pg_set_client_encoding);
  160. #if HAVE_PQSETERRORVERBOSITY
  161. PHP_FUNCTION(pg_set_error_verbosity);
  162. #endif
  163. #if HAVE_PQESCAPE
  164. PHP_FUNCTION(pg_escape_string);
  165. PHP_FUNCTION(pg_escape_bytea);
  166. PHP_FUNCTION(pg_unescape_bytea);
  167. PHP_FUNCTION(pg_escape_literal);
  168. PHP_FUNCTION(pg_escape_identifier);
  169. #endif
  170. /* misc functions */
  171. PHP_FUNCTION(pg_meta_data);
  172. PHP_FUNCTION(pg_convert);
  173. PHP_FUNCTION(pg_insert);
  174. PHP_FUNCTION(pg_update);
  175. PHP_FUNCTION(pg_delete);
  176. PHP_FUNCTION(pg_select);
  177. /* connection options - ToDo: Add async connection option */
  178. #define PGSQL_CONNECT_FORCE_NEW (1<<1)
  179. /* php_pgsql_convert options */
  180. #define PGSQL_CONV_IGNORE_DEFAULT (1<<1) /* Do not use DEAFULT value by removing field from returned array */
  181. #define PGSQL_CONV_FORCE_NULL (1<<2) /* Convert to NULL if string is null string */
  182. #define PGSQL_CONV_IGNORE_NOT_NULL (1<<3) /* Ignore NOT NULL constraints */
  183. #define PGSQL_CONV_OPTS (PGSQL_CONV_IGNORE_DEFAULT|PGSQL_CONV_FORCE_NULL|PGSQL_CONV_IGNORE_NOT_NULL)
  184. /* php_pgsql_insert/update/select/delete options */
  185. #define PGSQL_DML_NO_CONV (1<<8) /* Do not call php_pgsql_convert() */
  186. #define PGSQL_DML_EXEC (1<<9) /* Execute query */
  187. #define PGSQL_DML_ASYNC (1<<10) /* Do async query */
  188. #define PGSQL_DML_STRING (1<<11) /* Return query string */
  189. /* exported functions */
  190. PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC);
  191. PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC);
  192. PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *values, ulong opt, char **sql TSRMLS_DC);
  193. PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *values, zval *ids, ulong opt , char **sql TSRMLS_DC);
  194. PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids, ulong opt, char **sql TSRMLS_DC);
  195. PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids, zval *ret_array, ulong opt, char **sql TSRMLS_DC);
  196. PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC);
  197. /* internal functions */
  198. static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
  199. static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  200. static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  201. static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC);
  202. static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  203. static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  204. static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
  205. typedef enum _php_pgsql_data_type {
  206. /* boolean */
  207. PG_BOOL,
  208. /* number */
  209. PG_OID,
  210. PG_INT2,
  211. PG_INT4,
  212. PG_INT8,
  213. PG_FLOAT4,
  214. PG_FLOAT8,
  215. PG_NUMERIC,
  216. PG_MONEY,
  217. /* character */
  218. PG_TEXT,
  219. PG_CHAR,
  220. PG_VARCHAR,
  221. /* time and interval */
  222. PG_UNIX_TIME,
  223. PG_UNIX_TIME_INTERVAL,
  224. PG_DATE,
  225. PG_TIME,
  226. PG_TIME_WITH_TIMEZONE,
  227. PG_TIMESTAMP,
  228. PG_TIMESTAMP_WITH_TIMEZONE,
  229. PG_INTERVAL,
  230. /* binary */
  231. PG_BYTEA,
  232. /* network */
  233. PG_CIDR,
  234. PG_INET,
  235. PG_MACADDR,
  236. /* bit */
  237. PG_BIT,
  238. PG_VARBIT,
  239. /* geometoric */
  240. PG_LINE,
  241. PG_LSEG,
  242. PG_POINT,
  243. PG_BOX,
  244. PG_PATH,
  245. PG_POLYGON,
  246. PG_CIRCLE,
  247. /* unknown and system */
  248. PG_UNKNOWN
  249. } php_pgsql_data_type;
  250. typedef struct pgLofp {
  251. PGconn *conn;
  252. int lofd;
  253. } pgLofp;
  254. typedef struct _php_pgsql_result_handle {
  255. PGconn *conn;
  256. PGresult *result;
  257. int row;
  258. } pgsql_result_handle;
  259. typedef struct _php_pgsql_notice {
  260. char *message;
  261. size_t len;
  262. } php_pgsql_notice;
  263. ZEND_BEGIN_MODULE_GLOBALS(pgsql)
  264. long default_link; /* default link when connection is omitted */
  265. long num_links,num_persistent;
  266. long max_links,max_persistent;
  267. long allow_persistent;
  268. long auto_reset_persistent;
  269. int le_lofp,le_string;
  270. int ignore_notices,log_notices;
  271. HashTable notices; /* notice message for each connection */
  272. ZEND_END_MODULE_GLOBALS(pgsql)
  273. ZEND_EXTERN_MODULE_GLOBALS(pgsql)
  274. #ifdef ZTS
  275. # define PGG(v) TSRMG(pgsql_globals_id, zend_pgsql_globals *, v)
  276. #else
  277. # define PGG(v) (pgsql_globals.v)
  278. #endif
  279. #endif
  280. #else
  281. #define pgsql_module_ptr NULL
  282. #endif
  283. #define phpext_pgsql_ptr pgsql_module_ptr
  284. #endif /* PHP_PGSQL_H */