php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
php_pgsql.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Zeev Suraski <zeev@php.net> |
14 | Jouni Ahto <jouni.ahto@exdec.fi> |
15 +----------------------------------------------------------------------+
16 */
17
18#ifndef PHP_PGSQL_H
19#define PHP_PGSQL_H
20
21#ifdef HAVE_PGSQL
22
23extern zend_module_entry pgsql_module_entry;
24#define pgsql_module_ptr &pgsql_module_entry
25
26#include "php_version.h"
27#define PHP_PGSQL_VERSION PHP_VERSION
28
29#ifdef PHP_PGSQL_PRIVATE
30#undef SOCKET_SIZE_TYPE
31#include <libpq-fe.h>
32
33#include <libpq/libpq-fs.h>
34#ifdef PHP_WIN32
35#undef PHP_PGSQL_API
36#ifdef PGSQL_EXPORTS
37#define PHP_PGSQL_API __declspec(dllexport)
38#else
39#define PHP_PGSQL_API __declspec(dllimport)
40#endif
41#else
42# if defined(__GNUC__) && __GNUC__ >= 4
43# define PHP_PGSQL_API __attribute__ ((visibility("default")))
44# else
45# define PHP_PGSQL_API
46# endif
47#endif
48
54
55/* connection options - ToDo: Add async connection option */
56#define PGSQL_CONNECT_FORCE_NEW (1<<1)
57#define PGSQL_CONNECT_ASYNC (1<<2)
58/* php_pgsql_convert options */
59#define PGSQL_CONV_IGNORE_DEFAULT (1<<1) /* Do not use DEFAULT value by removing field from returned array */
60#define PGSQL_CONV_FORCE_NULL (1<<2) /* Convert to NULL if string is null string */
61#define PGSQL_CONV_IGNORE_NOT_NULL (1<<3) /* Ignore NOT NULL constraints */
62#define PGSQL_CONV_OPTS (PGSQL_CONV_IGNORE_DEFAULT|PGSQL_CONV_FORCE_NULL|PGSQL_CONV_IGNORE_NOT_NULL)
63/* php_pgsql_insert/update/select/delete options */
64#define PGSQL_DML_NO_CONV (1<<8) /* Do not call php_pgsql_convert() */
65#define PGSQL_DML_EXEC (1<<9) /* Execute query */
66#define PGSQL_DML_ASYNC (1<<10) /* Do async query */
67#define PGSQL_DML_STRING (1<<11) /* Return query string */
68#define PGSQL_DML_ESCAPE (1<<12) /* No convert, but escape only */
69
70/* exported functions */
71PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const zend_string *table_name, zval *meta, bool extended);
72PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *table_name, const zval *values, zval *result, zend_ulong opt);
73PHP_PGSQL_API zend_result php_pgsql_insert(PGconn *pg_link, const zend_string *table, zval *values, zend_ulong opt, zend_string **sql);
74PHP_PGSQL_API zend_result php_pgsql_update(PGconn *pg_link, const zend_string *table, zval *values, zval *ids, zend_ulong opt , zend_string **sql);
75PHP_PGSQL_API zend_result php_pgsql_delete(PGconn *pg_link, const zend_string *table, zval *ids, zend_ulong opt, zend_string **sql);
76PHP_PGSQL_API zend_result php_pgsql_select(PGconn *pg_link, const zend_string *table, zval *ids, zval *ret_array, zend_ulong opt, long fetch_option, zend_string **sql );
77PHP_PGSQL_API void php_pgsql_result2array(PGresult *pg_result, zval *ret_array, long fetch_option);
78
79/* internal functions */
80static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent);
81static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
82static void php_pgsql_get_result_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
83static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type);
84static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type, bool nullable_row);
85static void php_pgsql_do_async(INTERNAL_FUNCTION_PARAMETERS,int entry_type);
86
87static ssize_t php_pgsql_fd_write(php_stream *stream, const char *buf, size_t count);
88static ssize_t php_pgsql_fd_read(php_stream *stream, char *buf, size_t count);
89static int php_pgsql_fd_close(php_stream *stream, int close_handle);
90static int php_pgsql_fd_flush(php_stream *stream);
91static int php_pgsql_fd_set_option(php_stream *stream, int option, int value, void *ptrparam);
92static int php_pgsql_fd_cast(php_stream *stream, int cast_as, void **ret);
93
94typedef enum _php_pgsql_data_type {
95 /* boolean */
96 PG_BOOL,
97 /* number */
98 PG_OID,
99 PG_INT2,
100 PG_INT4,
101 PG_INT8,
102 PG_FLOAT4,
103 PG_FLOAT8,
104 PG_NUMERIC,
105 PG_MONEY,
106 /* character */
107 PG_TEXT,
108 PG_CHAR,
109 PG_VARCHAR,
110 /* time and interval */
111 PG_UNIX_TIME,
112 PG_UNIX_TIME_INTERVAL,
113 PG_DATE,
114 PG_TIME,
115 PG_TIME_WITH_TIMEZONE,
116 PG_TIMESTAMP,
117 PG_TIMESTAMP_WITH_TIMEZONE,
118 PG_INTERVAL,
119 /* binary */
120 PG_BYTEA,
121 /* network */
122 PG_CIDR,
123 PG_INET,
124 PG_MACADDR,
125 /* bit */
126 PG_BIT,
127 PG_VARBIT,
128 /* geometoric */
129 PG_LINE,
130 PG_LSEG,
131 PG_POINT,
132 PG_BOX,
133 PG_PATH,
134 PG_POLYGON,
135 PG_CIRCLE,
136 /* unknown and system */
137 PG_UNKNOWN
138} php_pgsql_data_type;
139
140typedef struct pgsql_link_handle {
141 PGconn *conn;
143 HashTable *notices;
144 bool persistent;
145 zend_object std;
146} pgsql_link_handle;
147
148typedef struct pgLofp {
149 PGconn *conn;
150 int lofd;
151 zend_object std;
152} pgLofp;
153
154typedef struct _php_pgsql_result_handle {
155 PGconn *conn;
156 PGresult *result;
157 int row;
158 zend_object std;
159} pgsql_result_handle;
160
161typedef struct _php_pgsql_notice {
162 char *message;
163 size_t len;
164} php_pgsql_notice;
165
166static const php_stream_ops php_stream_pgsql_fd_ops = {
167 php_pgsql_fd_write,
168 php_pgsql_fd_read,
169 php_pgsql_fd_close,
170 php_pgsql_fd_flush,
171 "PostgreSQL link",
172 NULL, /* seek */
173 php_pgsql_fd_cast, /* cast */
174 NULL, /* stat */
175 php_pgsql_fd_set_option
176};
177
178#define PGSQL_MAX_REGEXES 11
179
181 zend_long num_links,num_persistent;
183 bool allow_persistent;
184 int ignore_notices;
185 zend_long auto_reset_persistent;
186 int log_notices;
187 zend_object *default_link; /* default link when connection is omitted */
188 zend_string *regexes[PGSQL_MAX_REGEXES];
189 HashTable field_oids;
190 HashTable table_oids;
191 HashTable connections;
193
195# define PGG(v) ZEND_MODULE_GLOBALS_ACCESSOR(pgsql, v)
196
197#if defined(ZTS) && defined(COMPILE_DL_PGSQL)
199#endif
200
201#endif
202
203#else
204
205#define pgsql_module_ptr NULL
206
207#endif
208
209#define phpext_pgsql_ptr pgsql_module_ptr
210
211#endif /* PHP_PGSQL_H */
size_t len
Definition apprentice.c:174
count(Countable|array $value, int $mode=COUNT_NORMAL)
ffi persistent
Definition ffi.c:3633
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
#define NULL
Definition gdcache.h:45
hash(string $algo, string $data, bool $binary=false, array $options=[])
Definition hash.stub.php:12
pg_result(PgSql\Result $result, $row, string|int $field=UNKNOWN)
#define PHP_MSHUTDOWN_FUNCTION
Definition php.h:401
#define PHP_MINIT_FUNCTION
Definition php.h:400
#define PHP_MINFO_FUNCTION
Definition php.h:404
#define PHP_RINIT_FUNCTION
Definition php.h:402
#define PHP_RSHUTDOWN_FUNCTION
Definition php.h:403
zend_long num_links
Definition php_ldap.h:40
zend_long max_links
Definition php_ldap.h:41
zend_long max_persistent
bool allow_persistent
struct _php_stream php_stream
Definition php_streams.h:96
struct _php_stream_ops php_stream_ops
#define INTERNAL_FUNCTION_PARAMETERS
Definition zend.h:49
#define ZEND_TSRMLS_CACHE_EXTERN()
Definition zend.h:67
#define ZEND_END_MODULE_GLOBALS(module_name)
Definition zend_API.h:248
#define ZEND_EXTERN_MODULE_GLOBALS(module_name)
Definition zend_API.h:270
#define ZEND_BEGIN_MODULE_GLOBALS(module_name)
Definition zend_API.h:246
struct _zval_struct zval
int32_t zend_long
Definition zend_long.h:42
uint32_t zend_ulong
Definition zend_long.h:43
struct _zend_string zend_string
struct _zend_module_entry zend_module_entry
struct _zend_object zend_object
struct _zend_array HashTable
Definition zend_types.h:386
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
bool result
zval * ret
value