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