xref: /php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h (revision 68537fd9)
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: Edin Kadribasic <edink@emini.dk>                            |
14   |          Ilia Alshanestsky <ilia@prohost.org>                        |
15   |          Wez Furlong <wez@php.net>                                   |
16   +----------------------------------------------------------------------+
17 */
18 
19 /* internal header; not supposed to be installed */
20 
21 #ifndef PHP_PDO_PGSQL_INT_H
22 #define PHP_PDO_PGSQL_INT_H
23 
24 #include <libpq-fe.h>
25 #include <libpq/libpq-fs.h>
26 #include <php.h>
27 
28 #define PHP_PDO_PGSQL_CONNECTION_FAILURE_SQLSTATE "08006"
29 
30 typedef struct {
31 	const char *file;
32 	int line;
33 	unsigned int errcode;
34 	char *errmsg;
35 } pdo_pgsql_error_info;
36 
37 typedef struct pdo_pgsql_stmt pdo_pgsql_stmt;
38 
39 /* stuff we use in a pgsql database handle */
40 typedef struct {
41 	PGconn		*server;
42 	unsigned 	attached:1;
43 	unsigned 	_reserved:31;
44 	pdo_pgsql_error_info	einfo;
45 	Oid 		pgoid;
46 	unsigned int	stmt_counter;
47 	/* The following two variables have the same purpose. Unfortunately we need
48 	   to keep track of two different attributes having the same effect. */
49 	bool		emulate_prepares;
50 	bool		disable_native_prepares; /* deprecated since 5.6 */
51 	bool		disable_prepares;
52 	HashTable       *lob_streams;
53 	zend_fcall_info_cache *notice_callback;
54 	bool		default_fetching_laziness;
55 	pdo_pgsql_stmt  *running_stmt;
56 } pdo_pgsql_db_handle;
57 
58 typedef struct {
59 	Oid          pgsql_type;
60 } pdo_pgsql_column;
61 
62 struct pdo_pgsql_stmt {
63 	pdo_pgsql_db_handle     *H;
64 	PGresult                *result;
65 	pdo_pgsql_column        *cols;
66 	char *cursor_name;
67 	char *stmt_name;
68 	zend_string *query;
69 	char **param_values;
70 	int *param_lengths;
71 	int *param_formats;
72 	Oid *param_types;
73 	int                     current_row;
74 	bool is_prepared;
75 	bool is_unbuffered;
76 	bool is_running_unbuffered;
77 };
78 
79 typedef struct {
80 	Oid     oid;
81 } pdo_pgsql_bound_param;
82 
83 extern const pdo_driver_t pdo_pgsql_driver;
84 
85 extern int pdo_pgsql_scanner(pdo_scanner_t *s);
86 
87 extern int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char *sqlstate, const char *msg, const char *file, int line);
88 #define pdo_pgsql_error(d,e,z)	_pdo_pgsql_error(d, NULL, e, z, NULL, __FILE__, __LINE__)
89 #define pdo_pgsql_error_msg(d,e,m)	_pdo_pgsql_error(d, NULL, e, NULL, m, __FILE__, __LINE__)
90 #define pdo_pgsql_error_stmt(s,e,z)	_pdo_pgsql_error(s->dbh, s, e, z, NULL, __FILE__, __LINE__)
91 #define pdo_pgsql_error_stmt_msg(stmt, e, sqlstate, msg) \
92 	_pdo_pgsql_error(stmt->dbh, stmt, e, sqlstate, msg, __FILE__, __LINE__)
93 
94 extern const struct pdo_stmt_methods pgsql_stmt_methods;
95 
96 #define pdo_pgsql_sqlstate(r) PQresultErrorField(r, PG_DIAG_SQLSTATE)
97 
98 enum {
99 	PDO_PGSQL_ATTR_DISABLE_PREPARES = PDO_ATTR_DRIVER_SPECIFIC,
100 	PDO_PGSQL_ATTR_RESULT_MEMORY_SIZE,
101 };
102 
103 struct pdo_pgsql_lob_self {
104 	zval dbh;
105 	PGconn *conn;
106 	int lfd;
107 	Oid oid;
108 };
109 
110 enum pdo_pgsql_specific_constants {
111 	PGSQL_TRANSACTION_IDLE = PQTRANS_IDLE,
112 	PGSQL_TRANSACTION_ACTIVE = PQTRANS_ACTIVE,
113 	PGSQL_TRANSACTION_INTRANS = PQTRANS_INTRANS,
114 	PGSQL_TRANSACTION_INERROR = PQTRANS_INERROR,
115 	PGSQL_TRANSACTION_UNKNOWN = PQTRANS_UNKNOWN
116 };
117 
118 php_stream *pdo_pgsql_create_lob_stream(zval *pdh, int lfd, Oid oid);
119 extern const php_stream_ops pdo_pgsql_lob_stream_ops;
120 
121 void pdo_pgsql_cleanup_notice_callback(pdo_pgsql_db_handle *H);
122 
123 void pdo_libpq_version(char *buf, size_t len);
124 void pdo_pgsql_close_lob_streams(pdo_dbh_t *dbh);
125 
126 void pgsqlCopyFromArray_internal(INTERNAL_FUNCTION_PARAMETERS);
127 void pgsqlCopyFromFile_internal(INTERNAL_FUNCTION_PARAMETERS);
128 void pgsqlCopyToArray_internal(INTERNAL_FUNCTION_PARAMETERS);
129 void pgsqlCopyToFile_internal(INTERNAL_FUNCTION_PARAMETERS);
130 void pgsqlLOBCreate_internal(INTERNAL_FUNCTION_PARAMETERS);
131 void pgsqlLOBOpen_internal(INTERNAL_FUNCTION_PARAMETERS);
132 void pgsqlLOBUnlink_internal(INTERNAL_FUNCTION_PARAMETERS);
133 void pgsqlGetNotify_internal(INTERNAL_FUNCTION_PARAMETERS);
134 void pgsqlGetPid_internal(INTERNAL_FUNCTION_PARAMETERS);
135 
136 #endif /* PHP_PDO_PGSQL_INT_H */
137