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 #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 bool emulate_prepares; 46 bool disable_native_prepares; /* deprecated since 5.6 */ 47 bool disable_prepares; 48 HashTable *lob_streams; 49 } pdo_pgsql_db_handle; 50 51 typedef struct { 52 Oid pgsql_type; 53 } pdo_pgsql_column; 54 55 typedef struct { 56 pdo_pgsql_db_handle *H; 57 PGresult *result; 58 pdo_pgsql_column *cols; 59 char *cursor_name; 60 char *stmt_name; 61 zend_string *query; 62 char **param_values; 63 int *param_lengths; 64 int *param_formats; 65 Oid *param_types; 66 int current_row; 67 bool is_prepared; 68 } pdo_pgsql_stmt; 69 70 typedef struct { 71 Oid oid; 72 } pdo_pgsql_bound_param; 73 74 extern const pdo_driver_t pdo_pgsql_driver; 75 76 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); 77 #define pdo_pgsql_error(d,e,z) _pdo_pgsql_error(d, NULL, e, z, NULL, __FILE__, __LINE__) 78 #define pdo_pgsql_error_msg(d,e,m) _pdo_pgsql_error(d, NULL, e, NULL, m, __FILE__, __LINE__) 79 #define pdo_pgsql_error_stmt(s,e,z) _pdo_pgsql_error(s->dbh, s, e, z, NULL, __FILE__, __LINE__) 80 #define pdo_pgsql_error_stmt_msg(stmt, e, sqlstate, msg) \ 81 _pdo_pgsql_error(stmt->dbh, stmt, e, sqlstate, msg, __FILE__, __LINE__) 82 83 extern const struct pdo_stmt_methods pgsql_stmt_methods; 84 85 #define pdo_pgsql_sqlstate(r) PQresultErrorField(r, PG_DIAG_SQLSTATE) 86 87 enum { 88 PDO_PGSQL_ATTR_DISABLE_PREPARES = PDO_ATTR_DRIVER_SPECIFIC, 89 }; 90 91 struct pdo_pgsql_lob_self { 92 zval dbh; 93 PGconn *conn; 94 int lfd; 95 Oid oid; 96 }; 97 98 enum pdo_pgsql_specific_constants { 99 PGSQL_TRANSACTION_IDLE = PQTRANS_IDLE, 100 PGSQL_TRANSACTION_ACTIVE = PQTRANS_ACTIVE, 101 PGSQL_TRANSACTION_INTRANS = PQTRANS_INTRANS, 102 PGSQL_TRANSACTION_INERROR = PQTRANS_INERROR, 103 PGSQL_TRANSACTION_UNKNOWN = PQTRANS_UNKNOWN 104 }; 105 106 php_stream *pdo_pgsql_create_lob_stream(zval *pdh, int lfd, Oid oid); 107 extern const php_stream_ops pdo_pgsql_lob_stream_ops; 108 109 void pdo_libpq_version(char *buf, size_t len); 110 void pdo_pgsql_close_lob_streams(pdo_dbh_t *dbh); 111 112 #endif /* PHP_PDO_PGSQL_INT_H */ 113