xref: /PHP-5.4/ext/pdo_pgsql/php_pdo_pgsql_int.h (revision c0d060f5)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 5                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2014 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 /* $Id$ */
22 
23 #ifndef PHP_PDO_PGSQL_INT_H
24 #define PHP_PDO_PGSQL_INT_H
25 
26 #include <libpq-fe.h>
27 #include <libpq/libpq-fs.h>
28 #include <php.h>
29 
30 #define PHP_PDO_PGSQL_CONNECTION_FAILURE_SQLSTATE "08006"
31 
32 typedef struct {
33 	const char *file;
34 	int line;
35 	unsigned int errcode;
36 	char *errmsg;
37 } pdo_pgsql_error_info;
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 #if HAVE_PQPREPARE
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 	   It might be worth to deprecate the driver specific one soon. */
50 	int		emulate_prepares;
51 	int		disable_native_prepares;
52 #endif
53 	unsigned int stmt_counter;
54 } pdo_pgsql_db_handle;
55 
56 typedef struct {
57 	char         *def;
58 	Oid          pgsql_type;
59 	long         intval;
60 	zend_bool    boolval;
61 } pdo_pgsql_column;
62 
63 typedef struct {
64 	pdo_pgsql_db_handle     *H;
65 	PGresult                *result;
66 	int                     current_row;
67 	pdo_pgsql_column        *cols;
68 	char *cursor_name;
69 #if HAVE_PQPREPARE
70 	char *stmt_name;
71 	char *query;
72 	char **param_values;
73 	int *param_lengths;
74 	int *param_formats;
75 	Oid *param_types;
76 #endif
77 	zend_bool is_prepared;
78 } pdo_pgsql_stmt;
79 
80 typedef struct {
81 	Oid     oid;
82 } pdo_pgsql_bound_param;
83 
84 extern pdo_driver_t pdo_pgsql_driver;
85 
86 extern int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char *sqlstate, const char *file, int line TSRMLS_DC);
87 #define pdo_pgsql_error(d,e,z)	_pdo_pgsql_error(d, NULL, e, z, __FILE__, __LINE__ TSRMLS_CC)
88 #define pdo_pgsql_error_stmt(s,e,z)	_pdo_pgsql_error(s->dbh, s, e, z, __FILE__, __LINE__ TSRMLS_CC)
89 
90 extern struct pdo_stmt_methods pgsql_stmt_methods;
91 
92 #define pdo_pgsql_sqlstate(r) PQresultErrorField(r, PG_DIAG_SQLSTATE)
93 
94 enum {
95 	PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT = PDO_ATTR_DRIVER_SPECIFIC,
96 };
97 
98 struct pdo_pgsql_lob_self {
99 	pdo_dbh_t *dbh;
100 	PGconn *conn;
101 	int lfd;
102 	Oid oid;
103 };
104 
105 enum pdo_pgsql_specific_constants {
106 	PGSQL_TRANSACTION_IDLE = PQTRANS_IDLE,
107 	PGSQL_TRANSACTION_ACTIVE = PQTRANS_ACTIVE,
108 	PGSQL_TRANSACTION_INTRANS = PQTRANS_INTRANS,
109 	PGSQL_TRANSACTION_INERROR = PQTRANS_INERROR,
110 	PGSQL_TRANSACTION_UNKNOWN = PQTRANS_UNKNOWN
111 };
112 
113 php_stream *pdo_pgsql_create_lob_stream(pdo_dbh_t *stmt, int lfd, Oid oid TSRMLS_DC);
114 extern php_stream_ops pdo_pgsql_lob_stream_ops;
115 
116 #endif /* PHP_PDO_PGSQL_INT_H */
117 
118 /*
119  * Local variables:
120  * tab-width: 4
121  * c-basic-offset: 4
122  * End:
123  * vim600: noet sw=4 ts=4 fdm=marker
124  * vim<600: noet sw=4 ts=4
125  */
126