xref: /PHP-7.4/ext/pdo_pgsql/php_pdo_pgsql_int.h (revision 92ac598a)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 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: Edin Kadribasic <edink@emini.dk>                            |
16   |          Ilia Alshanestsky <ilia@prohost.org>                        |
17   |          Wez Furlong <wez@php.net>                                   |
18   +----------------------------------------------------------------------+
19 */
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 /* stuff we use in a pgsql database handle */
38 typedef struct {
39 	PGconn		*server;
40 	unsigned 	attached:1;
41 	unsigned 	_reserved:31;
42 	pdo_pgsql_error_info	einfo;
43 	Oid 		pgoid;
44 	unsigned int	stmt_counter;
45 	/* The following two variables have the same purpose. Unfortunately we need
46 	   to keep track of two different attributes having the same effect. */
47 	zend_bool		emulate_prepares;
48 	zend_bool		disable_native_prepares; /* deprecated since 5.6 */
49 	zend_bool		disable_prepares;
50 } pdo_pgsql_db_handle;
51 
52 typedef struct {
53 	char         *def;
54 	zend_long    intval;
55 	Oid          pgsql_type;
56 	zend_bool    boolval;
57 } pdo_pgsql_column;
58 
59 typedef struct {
60 	pdo_pgsql_db_handle     *H;
61 	PGresult                *result;
62 	pdo_pgsql_column        *cols;
63 	char *cursor_name;
64 	char *stmt_name;
65 	char *query;
66 	char **param_values;
67 	int *param_lengths;
68 	int *param_formats;
69 	Oid *param_types;
70 	int                     current_row;
71 	zend_bool is_prepared;
72 } pdo_pgsql_stmt;
73 
74 typedef struct {
75 	Oid     oid;
76 } pdo_pgsql_bound_param;
77 
78 extern const pdo_driver_t pdo_pgsql_driver;
79 
80 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);
81 #define pdo_pgsql_error(d,e,z)	_pdo_pgsql_error(d, NULL, e, z, NULL, __FILE__, __LINE__)
82 #define pdo_pgsql_error_msg(d,e,m)	_pdo_pgsql_error(d, NULL, e, NULL, m, __FILE__, __LINE__)
83 #define pdo_pgsql_error_stmt(s,e,z)	_pdo_pgsql_error(s->dbh, s, e, z, NULL, __FILE__, __LINE__)
84 #define pdo_pgsql_error_stmt_msg(s,e,m)	_pdo_pgsql_error(s->dbh, s, e, NULL, m, __FILE__, __LINE__)
85 
86 extern const struct pdo_stmt_methods pgsql_stmt_methods;
87 
88 #define pdo_pgsql_sqlstate(r) PQresultErrorField(r, PG_DIAG_SQLSTATE)
89 
90 enum {
91 	PDO_PGSQL_ATTR_DISABLE_PREPARES = PDO_ATTR_DRIVER_SPECIFIC,
92 };
93 
94 struct pdo_pgsql_lob_self {
95 	zval dbh;
96 	PGconn *conn;
97 	int lfd;
98 	Oid oid;
99 };
100 
101 enum pdo_pgsql_specific_constants {
102 	PGSQL_TRANSACTION_IDLE = PQTRANS_IDLE,
103 	PGSQL_TRANSACTION_ACTIVE = PQTRANS_ACTIVE,
104 	PGSQL_TRANSACTION_INTRANS = PQTRANS_INTRANS,
105 	PGSQL_TRANSACTION_INERROR = PQTRANS_INERROR,
106 	PGSQL_TRANSACTION_UNKNOWN = PQTRANS_UNKNOWN
107 };
108 
109 php_stream *pdo_pgsql_create_lob_stream(zval *pdh, int lfd, Oid oid);
110 extern const php_stream_ops pdo_pgsql_lob_stream_ops;
111 
112 #endif /* PHP_PDO_PGSQL_INT_H */
113