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.

239 lines
6.6 KiB

25 years ago
25 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. 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. #else
  32. #include <libpq/libpq-fs.h>
  33. #endif
  34. #ifdef HAVE_PG_CONFIG_H
  35. #include <pg_config.h>
  36. #endif
  37. #ifdef HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT
  38. const char * pg_encoding_to_char(int encoding);
  39. #endif
  40. PHP_MINIT_FUNCTION(pgsql);
  41. PHP_MSHUTDOWN_FUNCTION(pgsql);
  42. PHP_RINIT_FUNCTION(pgsql);
  43. PHP_RSHUTDOWN_FUNCTION(pgsql);
  44. PHP_MINFO_FUNCTION(pgsql);
  45. /* connection functions */
  46. PHP_FUNCTION(pg_connect);
  47. PHP_FUNCTION(pg_pconnect);
  48. PHP_FUNCTION(pg_close);
  49. PHP_FUNCTION(pg_connection_reset);
  50. PHP_FUNCTION(pg_connection_status);
  51. PHP_FUNCTION(pg_connection_busy);
  52. PHP_FUNCTION(pg_host);
  53. PHP_FUNCTION(pg_dbname);
  54. PHP_FUNCTION(pg_port);
  55. PHP_FUNCTION(pg_tty);
  56. PHP_FUNCTION(pg_options);
  57. /* query functions */
  58. PHP_FUNCTION(pg_query);
  59. PHP_FUNCTION(pg_send_query);
  60. PHP_FUNCTION(pg_cancel_query);
  61. /* result functions */
  62. PHP_FUNCTION(pg_fetch_array);
  63. PHP_FUNCTION(pg_fetch_object);
  64. PHP_FUNCTION(pg_fetch_result);
  65. PHP_FUNCTION(pg_fetch_row);
  66. PHP_FUNCTION(pg_affected_rows);
  67. PHP_FUNCTION(pg_get_result);
  68. PHP_FUNCTION(pg_result_status);
  69. PHP_FUNCTION(pg_free_result);
  70. PHP_FUNCTION(pg_last_oid);
  71. PHP_FUNCTION(pg_num_rows);
  72. PHP_FUNCTION(pg_num_fields);
  73. PHP_FUNCTION(pg_field_name);
  74. PHP_FUNCTION(pg_field_num);
  75. PHP_FUNCTION(pg_field_size);
  76. PHP_FUNCTION(pg_field_type);
  77. PHP_FUNCTION(pg_field_prtlen);
  78. PHP_FUNCTION(pg_field_is_null);
  79. /* error message functions */
  80. PHP_FUNCTION(pg_result_error);
  81. PHP_FUNCTION(pg_last_error);
  82. PHP_FUNCTION(pg_last_notice);
  83. /* copy functions */
  84. PHP_FUNCTION(pg_put_line);
  85. PHP_FUNCTION(pg_end_copy);
  86. PHP_FUNCTION(pg_copy_to);
  87. PHP_FUNCTION(pg_copy_from);
  88. /* large object functions */
  89. PHP_FUNCTION(pg_lo_create);
  90. PHP_FUNCTION(pg_lo_unlink);
  91. PHP_FUNCTION(pg_lo_open);
  92. PHP_FUNCTION(pg_lo_close);
  93. PHP_FUNCTION(pg_lo_read);
  94. PHP_FUNCTION(pg_lo_write);
  95. PHP_FUNCTION(pg_lo_read_all);
  96. PHP_FUNCTION(pg_lo_import);
  97. PHP_FUNCTION(pg_lo_export);
  98. PHP_FUNCTION(pg_lo_seek);
  99. PHP_FUNCTION(pg_lo_tell);
  100. /* debugging functions */
  101. PHP_FUNCTION(pg_trace);
  102. PHP_FUNCTION(pg_untrace);
  103. /* utility functions */
  104. #if HAVE_PQCLIENTENCODING
  105. PHP_FUNCTION(pg_client_encoding);
  106. PHP_FUNCTION(pg_set_client_encoding);
  107. #endif
  108. #if HAVE_PQESCAPE
  109. PHP_FUNCTION(pg_escape_string);
  110. PHP_FUNCTION(pg_escape_bytea);
  111. #endif
  112. /* misc functions */
  113. PHP_FUNCTION(pg_metadata);
  114. PHP_FUNCTION(pg_convert);
  115. PHP_FUNCTION(pg_insert);
  116. PHP_FUNCTION(pg_update);
  117. PHP_FUNCTION(pg_delete);
  118. PHP_FUNCTION(pg_select);
  119. PHPAPI int php_pgsql_metadata(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC);
  120. PHPAPI int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result TSRMLS_DC);
  121. PHPAPI int php_pgsql_insert(PGconn *pg_link, const char *table, zval *values, zend_bool convert, zend_bool async TSRMLS_DC);
  122. PHPAPI int php_pgsql_update(PGconn *pg_link, const char *table, zval *values, zval *ids, zend_bool convert, zend_bool async TSRMLS_DC);
  123. PHPAPI int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids, zend_bool convert, zend_bool async TSRMLS_DC);
  124. PHPAPI int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids, zval *ret_array, zend_bool convert TSRMLS_DC);
  125. static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
  126. /* static int php_pgsql_get_default_link(INTERNAL_FUNCTION_PARAMETERS); */
  127. static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  128. static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  129. static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC);
  130. static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  131. static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
  132. static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
  133. typedef enum _php_pgsql_data_type {
  134. /* boolean */
  135. PG_BOOL,
  136. /* number */
  137. PG_OID,
  138. PG_INT2,
  139. PG_INT4,
  140. PG_INT8,
  141. PG_FLOAT4,
  142. PG_FLOAT8,
  143. PG_NUMERIC,
  144. PG_MONEY,
  145. /* character */
  146. PG_TEXT,
  147. PG_CHAR,
  148. PG_VARCHAR,
  149. /* time and interval */
  150. PG_UNIX_TIME,
  151. PG_UNIX_TIME_INTERVAL,
  152. PG_DATE,
  153. PG_TIME,
  154. PG_TIME_WITH_TIMEZONE,
  155. PG_TIMESTAMP_WITH_TIMEZONE,
  156. PG_INTERVAL,
  157. /* binary */
  158. PG_BYTEA,
  159. /* network */
  160. PG_CIDR,
  161. PG_INET,
  162. PG_MACADDR,
  163. /* bit */
  164. PG_BIT,
  165. PG_VARBIT,
  166. /* geometoric */
  167. PG_LINE,
  168. PG_LSEG,
  169. PG_POINT,
  170. PG_BOX,
  171. PG_PATH,
  172. PG_POLYGON,
  173. PG_CIRCLE,
  174. /* unkown and system */
  175. PG_UNKNOWN
  176. } php_pgsql_data_type;
  177. typedef struct pgLofp {
  178. PGconn *conn;
  179. int lofd;
  180. } pgLofp;
  181. typedef struct _php_pgsql_result_handle {
  182. PGconn *conn;
  183. PGresult *result;
  184. int row;
  185. } pgsql_result_handle;
  186. typedef struct _php_pgsql_notice {
  187. char *message;
  188. size_t len;
  189. } php_pgsql_notice;
  190. typedef struct {
  191. long default_link; /* default link when connection is omitted */
  192. long num_links,num_persistent;
  193. long max_links,max_persistent;
  194. long allow_persistent;
  195. long auto_reset_persistent;
  196. int le_lofp,le_string;
  197. int ignore_notices,log_notices;
  198. HashTable notices; /* notice message for each connection */
  199. } php_pgsql_globals;
  200. #ifdef ZTS
  201. # define PGG(v) TSRMG(pgsql_globals_id, php_pgsql_globals *, v)
  202. extern int pgsql_globals_id;
  203. #else
  204. # define PGG(v) (pgsql_globals.v)
  205. extern php_pgsql_globals pgsql_globals;
  206. #endif
  207. #endif
  208. #else
  209. #define pgsql_module_ptr NULL
  210. #endif
  211. #define phpext_pgsql_ptr pgsql_module_ptr
  212. #endif /* PHP_PGSQL_H */