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 HashTable *lob_streams; 49 } pdo_pgsql_db_handle; 50 51 typedef struct { 52 char *def; 53 zend_long intval; 54 Oid pgsql_type; 55 zend_bool boolval; 56 } pdo_pgsql_column; 57 58 typedef struct { 59 pdo_pgsql_db_handle *H; 60 PGresult *result; 61 pdo_pgsql_column *cols; 62 char *cursor_name; 63 char *stmt_name; 64 char *query; 65 char **param_values; 66 int *param_lengths; 67 int *param_formats; 68 Oid *param_types; 69 int current_row; 70 zend_bool is_prepared; 71 } pdo_pgsql_stmt; 72 73 typedef struct { 74 Oid oid; 75 } pdo_pgsql_bound_param; 76 77 extern const pdo_driver_t pdo_pgsql_driver; 78 79 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); 80 #define pdo_pgsql_error(d,e,z) _pdo_pgsql_error(d, NULL, e, z, NULL, __FILE__, __LINE__) 81 #define pdo_pgsql_error_msg(d,e,m) _pdo_pgsql_error(d, NULL, e, NULL, m, __FILE__, __LINE__) 82 #define pdo_pgsql_error_stmt(s,e,z) _pdo_pgsql_error(s->dbh, s, e, z, NULL, __FILE__, __LINE__) 83 #define pdo_pgsql_error_stmt_msg(stmt, e, sqlstate, msg) \ 84 _pdo_pgsql_error(stmt->dbh, stmt, e, sqlstate, msg, __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 void pdo_libpq_version(char *buf, size_t len); 113 void pdo_pgsql_close_lob_streams(pdo_dbh_t *dbh); 114 115 #endif /* PHP_PDO_PGSQL_INT_H */ 116