Back to index

php5  5.3.10
php_pgsql.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Zeev Suraski <zeev@zend.com>                                |
00016    |          Jouni Ahto <jouni.ahto@exdec.fi>                            |
00017    +----------------------------------------------------------------------+
00018  */
00019  
00020 /* $Id: php_pgsql.h 321634 2012-01-01 13:15:04Z felipe $ */
00021 
00022 #ifndef PHP_PGSQL_H
00023 #define PHP_PGSQL_H
00024 
00025 #if HAVE_PGSQL
00026 
00027 extern zend_module_entry pgsql_module_entry;
00028 #define pgsql_module_ptr &pgsql_module_entry
00029 
00030 #ifdef PHP_PGSQL_PRIVATE
00031 #undef SOCKET_SIZE_TYPE
00032 #include <libpq-fe.h>
00033 
00034 #ifdef PHP_WIN32
00035 #define INV_WRITE            0x00020000
00036 #define INV_READ             0x00040000
00037 #undef PHP_PGSQL_API
00038 #ifdef PGSQL_EXPORTS
00039 #define PHP_PGSQL_API __declspec(dllexport)
00040 #else
00041 #define PHP_PGSQL_API __declspec(dllimport)
00042 #endif
00043 #else
00044 #include <libpq/libpq-fs.h>
00045 # if defined(__GNUC__) && __GNUC__ >= 4
00046 #  define PHP_PGSQL_API __attribute__ ((visibility("default")))
00047 # else
00048 #  define PHP_PGSQL_API
00049 # endif
00050 #endif
00051 
00052 #ifdef HAVE_PG_CONFIG_H
00053 #include <pg_config.h>
00054 #endif
00055 
00056 #ifdef HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT
00057 const char * pg_encoding_to_char(int encoding);
00058 #endif
00059 
00060 PHP_MINIT_FUNCTION(pgsql);
00061 PHP_MSHUTDOWN_FUNCTION(pgsql);
00062 PHP_RINIT_FUNCTION(pgsql);
00063 PHP_RSHUTDOWN_FUNCTION(pgsql);
00064 PHP_MINFO_FUNCTION(pgsql);
00065 /* connection functions */
00066 PHP_FUNCTION(pg_connect);
00067 PHP_FUNCTION(pg_pconnect);
00068 PHP_FUNCTION(pg_close);
00069 PHP_FUNCTION(pg_connection_reset);
00070 PHP_FUNCTION(pg_connection_status);
00071 PHP_FUNCTION(pg_connection_busy);
00072 PHP_FUNCTION(pg_host);
00073 PHP_FUNCTION(pg_dbname);
00074 PHP_FUNCTION(pg_port);
00075 PHP_FUNCTION(pg_tty);
00076 PHP_FUNCTION(pg_options);
00077 PHP_FUNCTION(pg_version);
00078 PHP_FUNCTION(pg_ping);
00079 #if HAVE_PQPARAMETERSTATUS
00080 PHP_FUNCTION(pg_parameter_status);
00081 #endif
00082 #if HAVE_PGTRANSACTIONSTATUS
00083 PHP_FUNCTION(pg_transaction_status);
00084 #endif
00085 /* query functions */
00086 PHP_FUNCTION(pg_query);
00087 #if HAVE_PQEXECPARAMS
00088 PHP_FUNCTION(pg_query_params);
00089 #endif
00090 #if HAVE_PQPREPARE
00091 PHP_FUNCTION(pg_prepare);
00092 #endif
00093 #if HAVE_PQEXECPREPARED
00094 PHP_FUNCTION(pg_execute);
00095 #endif
00096 PHP_FUNCTION(pg_send_query);
00097 #if HAVE_PQSENDQUERYPARAMS
00098 PHP_FUNCTION(pg_send_query_params);
00099 #endif
00100 #if HAVE_PQSENDPREPARE
00101 PHP_FUNCTION(pg_send_prepare);
00102 #endif
00103 #if HAVE_PQSENDQUERYPREPARED
00104 PHP_FUNCTION(pg_send_execute);
00105 #endif
00106 PHP_FUNCTION(pg_cancel_query);
00107 /* result functions */
00108 PHP_FUNCTION(pg_fetch_assoc);
00109 PHP_FUNCTION(pg_fetch_array);
00110 PHP_FUNCTION(pg_fetch_object);
00111 PHP_FUNCTION(pg_fetch_result);
00112 PHP_FUNCTION(pg_fetch_row);
00113 PHP_FUNCTION(pg_fetch_all);
00114 PHP_FUNCTION(pg_fetch_all_columns);
00115 #if HAVE_PQCMDTUPLES
00116 PHP_FUNCTION(pg_affected_rows);
00117 #endif
00118 PHP_FUNCTION(pg_get_result);
00119 PHP_FUNCTION(pg_result_seek);
00120 PHP_FUNCTION(pg_result_status);
00121 PHP_FUNCTION(pg_free_result);
00122 PHP_FUNCTION(pg_last_oid);
00123 PHP_FUNCTION(pg_num_rows);
00124 PHP_FUNCTION(pg_num_fields);
00125 PHP_FUNCTION(pg_field_name);
00126 PHP_FUNCTION(pg_field_num);
00127 PHP_FUNCTION(pg_field_size);
00128 PHP_FUNCTION(pg_field_type);
00129 PHP_FUNCTION(pg_field_type_oid);
00130 PHP_FUNCTION(pg_field_prtlen);
00131 PHP_FUNCTION(pg_field_is_null);
00132 PHP_FUNCTION(pg_field_table);
00133 /* async message functions */
00134 PHP_FUNCTION(pg_get_notify);
00135 PHP_FUNCTION(pg_get_pid);
00136 /* error message functions */
00137 PHP_FUNCTION(pg_result_error);
00138 #if HAVE_PQRESULTERRORFIELD
00139 PHP_FUNCTION(pg_result_error_field);
00140 #endif
00141 PHP_FUNCTION(pg_last_error);
00142 PHP_FUNCTION(pg_last_notice);
00143 /* copy functions */
00144 PHP_FUNCTION(pg_put_line);
00145 PHP_FUNCTION(pg_end_copy);
00146 PHP_FUNCTION(pg_copy_to);
00147 PHP_FUNCTION(pg_copy_from);
00148 /* large object functions */
00149 PHP_FUNCTION(pg_lo_create);
00150 PHP_FUNCTION(pg_lo_unlink);
00151 PHP_FUNCTION(pg_lo_open);
00152 PHP_FUNCTION(pg_lo_close);
00153 PHP_FUNCTION(pg_lo_read);
00154 PHP_FUNCTION(pg_lo_write);
00155 PHP_FUNCTION(pg_lo_read_all);
00156 PHP_FUNCTION(pg_lo_import);
00157 PHP_FUNCTION(pg_lo_export);
00158 PHP_FUNCTION(pg_lo_seek);
00159 PHP_FUNCTION(pg_lo_tell);
00160 
00161 /* debugging functions */
00162 PHP_FUNCTION(pg_trace);
00163 PHP_FUNCTION(pg_untrace);
00164 
00165 /* utility functions */
00166 PHP_FUNCTION(pg_client_encoding);
00167 PHP_FUNCTION(pg_set_client_encoding);
00168 #if HAVE_PQSETERRORVERBOSITY
00169 PHP_FUNCTION(pg_set_error_verbosity);
00170 #endif
00171 #if HAVE_PQESCAPE
00172 PHP_FUNCTION(pg_escape_string);
00173 PHP_FUNCTION(pg_escape_bytea);
00174 PHP_FUNCTION(pg_unescape_bytea);
00175 #endif
00176 
00177 /* misc functions */
00178 PHP_FUNCTION(pg_meta_data);
00179 PHP_FUNCTION(pg_convert);
00180 PHP_FUNCTION(pg_insert);
00181 PHP_FUNCTION(pg_update);
00182 PHP_FUNCTION(pg_delete);
00183 PHP_FUNCTION(pg_select);
00184 
00185 /* connection options - ToDo: Add async connection option */
00186 #define PGSQL_CONNECT_FORCE_NEW     (1<<1)
00187 /* php_pgsql_convert options */
00188 #define PGSQL_CONV_IGNORE_DEFAULT   (1<<1)     /* Do not use DEAFULT value by removing field from returned array */
00189 #define PGSQL_CONV_FORCE_NULL       (1<<2)     /* Convert to NULL if string is null string */
00190 #define PGSQL_CONV_IGNORE_NOT_NULL  (1<<3)     /* Ignore NOT NULL constraints */
00191 #define PGSQL_CONV_OPTS             (PGSQL_CONV_IGNORE_DEFAULT|PGSQL_CONV_FORCE_NULL|PGSQL_CONV_IGNORE_NOT_NULL)
00192 /* php_pgsql_insert/update/select/delete options */
00193 #define PGSQL_DML_NO_CONV           (1<<8)     /* Do not call php_pgsql_convert() */
00194 #define PGSQL_DML_EXEC              (1<<9)     /* Execute query */
00195 #define PGSQL_DML_ASYNC             (1<<10)    /* Do async query */
00196 #define PGSQL_DML_STRING            (1<<11)    /* Return query string */
00197 
00198 /* exported functions */
00199 PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, zval *meta TSRMLS_DC);
00200 PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, const zval *values, zval *result, ulong opt TSRMLS_DC);
00201 PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *values, ulong opt, char **sql TSRMLS_DC);
00202 PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *values, zval *ids, ulong opt , char **sql TSRMLS_DC);
00203 PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids, ulong opt, char **sql TSRMLS_DC);
00204 PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids, zval *ret_array, ulong opt, char **sql  TSRMLS_DC);
00205 PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC);
00206 
00207 /* internal functions */
00208 static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
00209 static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
00210 static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
00211 static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC);
00212 static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
00213 static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
00214 static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
00215 
00216 typedef enum _php_pgsql_data_type {
00217        /* boolean */
00218        PG_BOOL,
00219        /* number */
00220        PG_OID,
00221        PG_INT2,
00222        PG_INT4,
00223        PG_INT8,
00224        PG_FLOAT4,
00225        PG_FLOAT8,
00226        PG_NUMERIC,
00227        PG_MONEY,
00228        /* character */
00229        PG_TEXT,
00230        PG_CHAR,
00231        PG_VARCHAR,
00232        /* time and interval */
00233        PG_UNIX_TIME,
00234        PG_UNIX_TIME_INTERVAL,
00235        PG_DATE,
00236        PG_TIME,
00237        PG_TIME_WITH_TIMEZONE,
00238        PG_TIMESTAMP,
00239        PG_TIMESTAMP_WITH_TIMEZONE,
00240        PG_INTERVAL,
00241        /* binary */
00242        PG_BYTEA,
00243        /* network */
00244        PG_CIDR,
00245        PG_INET,
00246        PG_MACADDR,
00247        /* bit */
00248        PG_BIT,
00249        PG_VARBIT,
00250        /* geometoric */
00251        PG_LINE,
00252        PG_LSEG,
00253        PG_POINT,
00254        PG_BOX,
00255        PG_PATH,
00256        PG_POLYGON,
00257        PG_CIRCLE,
00258        /* unkown and system */
00259        PG_UNKNOWN
00260 } php_pgsql_data_type;
00261 
00262 typedef struct pgLofp {
00263        PGconn *conn;
00264        int lofd;
00265 } pgLofp;
00266 
00267 typedef struct _php_pgsql_result_handle {
00268        PGconn *conn;
00269        PGresult *result;
00270        int row;
00271 } pgsql_result_handle;
00272 
00273 typedef struct _php_pgsql_notice {
00274        char *message;
00275        size_t len;
00276 } php_pgsql_notice;
00277 
00278 ZEND_BEGIN_MODULE_GLOBALS(pgsql)
00279        long default_link; /* default link when connection is omitted */
00280        long num_links,num_persistent;
00281        long max_links,max_persistent;
00282        long allow_persistent;
00283        long auto_reset_persistent;
00284        int le_lofp,le_string;
00285        int ignore_notices,log_notices;
00286        HashTable notices;  /* notice message for each connection */
00287 ZEND_END_MODULE_GLOBALS(pgsql)
00288 
00289 ZEND_EXTERN_MODULE_GLOBALS(pgsql)
00290 
00291 #ifdef ZTS
00292 # define PGG(v) TSRMG(pgsql_globals_id, zend_pgsql_globals *, v)
00293 #else
00294 # define PGG(v) (pgsql_globals.v)
00295 #endif
00296 
00297 #endif
00298 
00299 #else
00300 
00301 #define pgsql_module_ptr NULL
00302 
00303 #endif
00304 
00305 #define phpext_pgsql_ptr pgsql_module_ptr
00306 
00307 #endif /* PHP_PGSQL_H */