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.

257 lines
7.5 KiB

25 years ago
25 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. #undef PHPAPI
  33. #ifdef PGSQL_EXPORTS
  34. #define PHPAPI __declspec(dllexport)
  35. #else
  36. #define PHPAPI __declspec(dllimport)
  37. #endif
  38. #else
  39. #include <libpq/libpq-fs.h>
  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. /* query functions */
  65. PHP_FUNCTION(pg_query);
  66. PHP_FUNCTION(pg_send_query);
  67. PHP_FUNCTION(pg_cancel_query);
  68. /* result functions */
  69. PHP_FUNCTION(pg_fetch_array);
  70. PHP_FUNCTION(pg_fetch_object);
  71. PHP_FUNCTION(pg_fetch_result);
  72. PHP_FUNCTION(pg_fetch_row);
  73. PHP_FUNCTION(pg_affected_rows);
  74. PHP_FUNCTION(pg_get_result);
  75. PHP_FUNCTION(pg_result_status);
  76. PHP_FUNCTION(pg_free_result);
  77. PHP_FUNCTION(pg_last_oid);
  78. PHP_FUNCTION(pg_num_rows);
  79. PHP_FUNCTION(pg_num_fields);
  80. PHP_FUNCTION(pg_field_name);
  81. PHP_FUNCTION(pg_field_num);
  82. PHP_FUNCTION(pg_field_size);
  83. PHP_FUNCTION(pg_field_type);
  84. PHP_FUNCTION(pg_field_prtlen);
  85. PHP_FUNCTION(pg_field_is_null);
  86. /* error message functions */
  87. PHP_FUNCTION(pg_result_error);
  88. PHP_FUNCTION(pg_last_error);
  89. PHP_FUNCTION(pg_last_notice);
  90. /* copy functions */
  91. PHP_FUNCTION(pg_put_line);
  92. PHP_FUNCTION(pg_end_copy);
  93. PHP_FUNCTION(pg_copy_to);
  94. PHP_FUNCTION(pg_copy_from);
  95. /* large object functions */
  96. PHP_FUNCTION(pg_lo_create);
  97. PHP_FUNCTION(pg_lo_unlink);
  98. PHP_FUNCTION(pg_lo_open);
  99. PHP_FUNCTION(pg_lo_close);
  100. PHP_FUNCTION(pg_lo_read);
  101. PHP_FUNCTION(pg_lo_write);
  102. PHP_FUNCTION(pg_lo_read_all);
  103. PHP_FUNCTION(pg_lo_import);
  104. PHP_FUNCTION(pg_lo_export);
  105. PHP_FUNCTION(pg_lo_seek);
  106. PHP_FUNCTION(pg_lo_tell);
  107. /* debugging functions */
  108. PHP_FUNCTION(pg_trace);
  109. PHP_FUNCTION(pg_untrace);
  110. /* utility functions */
  111. PHP_FUNCTION(pg_client_encoding);
  112. PHP_FUNCTION(pg_set_client_encoding);
  113. #if HAVE_PQESCAPE
  114. PHP_FUNCTION(pg_escape_string);
  115. PHP_FUNCTION(pg_escape_bytea);
  116. #endif
  117. /* misc functions */
  118. PHP_FUNCTION(pg_metadata);
  119. PHP_FUNCTION(pg_convert);
  120. PHP_FUNCTION(pg_insert);
  121. PHP_FUNCTION(pg_update);
  122. PHP_FUNCTION(pg_delete);
  123. PHP_FUNCTION(pg_select);
  124. /* php_pgsql_convert options */
  125. #define PGSQL_CONV_IGNORE_DEFAULT (1<<1) /* Do not use DEAFULT value by removing field from returned array */
  126. #define PGSQL_CONV_FORCE_NULL (1<<2) /* Convert to NULL if string is null string */
  127. #define PGSQL_CONV_IGNORE_NOT_NULL (1<<3) /* Ignore NOT NULL constraints */
  128. #define PGSQL_CONV_OPTS (PGSQL_CONV_IGNORE_DEFAULT|PGSQL_CONV_FORCE_NULL|PGSQL_CONV_IGNORE_NOT_NULL)
  129. /* php_pgsql_insert/update/select/delete options */
  130. #define PGSQL_DML_NO_CONV (1<<8) /* Call php_pgsql_convert() */
  131. #define PGSQL_DML_EXEC (1<<9) /* Execute query */
  132. #define PGSQL_DML_ASYNC (1<<10) /* Do async query */
  133. #define PGSQL_DML_STRING (1<<11) /* Return query string */
  134. /* exported functions */
  135. PHPAPI int php_pgsql_metadata(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC);
  136. PHPAPI int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC);
  137. PHPAPI int php_pgsql_insert(PGconn *pg_link, const char *table, zval *values, ulong opt, char **sql TSRMLS_DC);
  138. PHPAPI int php_pgsql_update(PGconn *pg_link, const char *table, zval *values, zval *ids, ulong opt , char **sql TSRMLS_DC);
  139. PHPAPI int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids, ulong opt, char **sql TSRMLS_DC);
  140. PHPAPI int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids, zval *ret_array, ulong opt, char **sql TSRMLS_DC);
  141. /* internal functions */
  142. static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
  143. static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  144. static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  145. static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC);
  146. static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  147. static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  148. static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
  149. typedef enum _php_pgsql_data_type {
  150. /* boolean */
  151. PG_BOOL,
  152. /* number */
  153. PG_OID,
  154. PG_INT2,
  155. PG_INT4,
  156. PG_INT8,
  157. PG_FLOAT4,
  158. PG_FLOAT8,
  159. PG_NUMERIC,
  160. PG_MONEY,
  161. /* character */
  162. PG_TEXT,
  163. PG_CHAR,
  164. PG_VARCHAR,
  165. /* time and interval */
  166. PG_UNIX_TIME,
  167. PG_UNIX_TIME_INTERVAL,
  168. PG_DATE,
  169. PG_TIME,
  170. PG_TIME_WITH_TIMEZONE,
  171. PG_TIMESTAMP_WITH_TIMEZONE,
  172. PG_INTERVAL,
  173. /* binary */
  174. PG_BYTEA,
  175. /* network */
  176. PG_CIDR,
  177. PG_INET,
  178. PG_MACADDR,
  179. /* bit */
  180. PG_BIT,
  181. PG_VARBIT,
  182. /* geometoric */
  183. PG_LINE,
  184. PG_LSEG,
  185. PG_POINT,
  186. PG_BOX,
  187. PG_PATH,
  188. PG_POLYGON,
  189. PG_CIRCLE,
  190. /* unkown and system */
  191. PG_UNKNOWN
  192. } php_pgsql_data_type;
  193. typedef struct pgLofp {
  194. PGconn *conn;
  195. int lofd;
  196. } pgLofp;
  197. typedef struct _php_pgsql_result_handle {
  198. PGconn *conn;
  199. PGresult *result;
  200. int row;
  201. } pgsql_result_handle;
  202. typedef struct _php_pgsql_notice {
  203. char *message;
  204. size_t len;
  205. } php_pgsql_notice;
  206. typedef struct {
  207. long default_link; /* default link when connection is omitted */
  208. long num_links,num_persistent;
  209. long max_links,max_persistent;
  210. long allow_persistent;
  211. long auto_reset_persistent;
  212. int le_lofp,le_string;
  213. int ignore_notices,log_notices;
  214. HashTable notices; /* notice message for each connection */
  215. } php_pgsql_globals;
  216. #ifdef ZTS
  217. # define PGG(v) TSRMG(pgsql_globals_id, php_pgsql_globals *, v)
  218. extern int pgsql_globals_id;
  219. #else
  220. # define PGG(v) (pgsql_globals.v)
  221. extern php_pgsql_globals pgsql_globals;
  222. #endif
  223. #endif
  224. #else
  225. #define pgsql_module_ptr NULL
  226. #endif
  227. #define phpext_pgsql_ptr pgsql_module_ptr
  228. #endif /* PHP_PGSQL_H */