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 | http://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 #ifndef PHP_PDO_PGSQL_INT_H 20 #define PHP_PDO_PGSQL_INT_H 21 22 #include <libpq-fe.h> 23 #include <libpq/libpq-fs.h> 24 #include <php.h> 25 26 #define PHP_PDO_PGSQL_CONNECTION_FAILURE_SQLSTATE "08006" 27 28 typedef struct { 29 const char *file; 30 int line; 31 unsigned int errcode; 32 char *errmsg; 33 } pdo_pgsql_error_info; 34 35 /* stuff we use in a pgsql database handle */ 36 typedef struct { 37 PGconn *server; 38 unsigned attached:1; 39 unsigned _reserved:31; 40 pdo_pgsql_error_info einfo; 41 Oid pgoid; 42 unsigned int stmt_counter; 43 /* The following two variables have the same purpose. Unfortunately we need 44 to keep track of two different attributes having the same effect. */ 45 zend_bool emulate_prepares; 46 zend_bool disable_native_prepares; /* deprecated since 5.6 */ 47 zend_bool disable_prepares; 48 } pdo_pgsql_db_handle; 49 50 typedef struct { 51 char *def; 52 zend_long intval; 53 Oid pgsql_type; 54 zend_bool boolval; 55 } pdo_pgsql_column; 56 57 typedef struct { 58 pdo_pgsql_db_handle *H; 59 PGresult *result; 60 pdo_pgsql_column *cols; 61 char *cursor_name; 62 char *stmt_name; 63 char *query; 64 char **param_values; 65 int *param_lengths; 66 int *param_formats; 67 Oid *param_types; 68 int current_row; 69 zend_bool is_prepared; 70 } pdo_pgsql_stmt; 71 72 typedef struct { 73 Oid oid; 74 } pdo_pgsql_bound_param; 75 76 extern const pdo_driver_t pdo_pgsql_driver; 77 78 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); 79 #define pdo_pgsql_error(d,e,z) _pdo_pgsql_error(d, NULL, e, z, NULL, __FILE__, __LINE__) 80 #define pdo_pgsql_error_msg(d,e,m) _pdo_pgsql_error(d, NULL, e, NULL, m, __FILE__, __LINE__) 81 #define pdo_pgsql_error_stmt(s,e,z) _pdo_pgsql_error(s->dbh, s, e, z, NULL, __FILE__, __LINE__) 82 #define pdo_pgsql_error_stmt_msg(stmt, e, sqlstate, msg) \ 83 _pdo_pgsql_error(stmt->dbh, stmt, e, sqlstate, msg, __FILE__, __LINE__) 84 85 extern const struct pdo_stmt_methods pgsql_stmt_methods; 86 87 #define pdo_pgsql_sqlstate(r) PQresultErrorField(r, PG_DIAG_SQLSTATE) 88 89 enum { 90 PDO_PGSQL_ATTR_DISABLE_PREPARES = PDO_ATTR_DRIVER_SPECIFIC, 91 }; 92 93 struct pdo_pgsql_lob_self { 94 zval dbh; 95 PGconn *conn; 96 int lfd; 97 Oid oid; 98 }; 99 100 enum pdo_pgsql_specific_constants { 101 PGSQL_TRANSACTION_IDLE = PQTRANS_IDLE, 102 PGSQL_TRANSACTION_ACTIVE = PQTRANS_ACTIVE, 103 PGSQL_TRANSACTION_INTRANS = PQTRANS_INTRANS, 104 PGSQL_TRANSACTION_INERROR = PQTRANS_INERROR, 105 PGSQL_TRANSACTION_UNKNOWN = PQTRANS_UNKNOWN 106 }; 107 108 php_stream *pdo_pgsql_create_lob_stream(zval *pdh, int lfd, Oid oid); 109 extern const php_stream_ops pdo_pgsql_lob_stream_ops; 110 111 void pdo_libpq_version(char *buf, size_t len); 112 113 #endif /* PHP_PDO_PGSQL_INT_H */ 114