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.

253 lines
7.4 KiB

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