1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2018 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   | Author: Ard Biesheuvel <abies@php.net>                               |
16   +----------------------------------------------------------------------+
17 */
18 
19 #ifndef PHP_PDO_FIREBIRD_INT_H
20 #define PHP_PDO_FIREBIRD_INT_H
21 
22 #include <ibase.h>
23 
24 #ifdef SQLDA_VERSION
25 #define PDO_FB_SQLDA_VERSION SQLDA_VERSION
26 #else
27 #define PDO_FB_SQLDA_VERSION 1
28 #endif
29 
30 #define PDO_FB_DIALECT 3
31 
32 #define PDO_FB_DEF_DATE_FMT "%Y-%m-%d"
33 #define PDO_FB_DEF_TIME_FMT "%H:%M:%S"
34 #define PDO_FB_DEF_TIMESTAMP_FMT PDO_FB_DEF_DATE_FMT " " PDO_FB_DEF_TIME_FMT
35 
36 #define SHORT_MAX (1 << (8*sizeof(short)-1))
37 
38 #if SIZEOF_ZEND_LONG == 8 && !defined(PHP_WIN32)
39 # define LL_MASK "l"
40 # define LL_LIT(lit) lit ## L
41 #else
42 # ifdef PHP_WIN32
43 #  define LL_MASK "I64"
44 #  define LL_LIT(lit) lit ## I64
45 # else
46 #  define LL_MASK "ll"
47 #  define LL_LIT(lit) lit ## LL
48 # endif
49 #endif
50 
51 /* Firebird API has a couple of missing const decls in its API */
52 #define const_cast(s) ((char*)(s))
53 
54 #ifdef PHP_WIN32
55 typedef void (__stdcall *info_func_t)(char*);
56 #else
57 typedef void (*info_func_t)(char*);
58 #endif
59 
60 #ifndef min
61 #define min(a,b) ((a)<(b)?(a):(b))
62 #endif
63 
64 #if defined(_LP64) || defined(__LP64__) || defined(__arch64__) || defined(_WIN64)
65 # define PDO_FIREBIRD_HANDLE_INITIALIZER 0U
66 #else
67 # define PDO_FIREBIRD_HANDLE_INITIALIZER NULL
68 #endif
69 
70 typedef struct {
71 
72 	/* the result of the last API call */
73 	ISC_STATUS isc_status[20];
74 
75 	/* the connection handle */
76 	isc_db_handle db;
77 
78 	/* the transaction handle */
79 	isc_tr_handle tr;
80 
81 	/* the last error that didn't come from the API */
82 	char const *last_app_error;
83 
84 	/* date and time format strings, can be set by the set_attribute method */
85 	char *date_format;
86 	char *time_format;
87 	char *timestamp_format;
88 
89 	/* prepend table names on column names in fetch */
90 	unsigned fetch_table_names:1;
91 
92 	unsigned _reserved:31;
93 
94 } pdo_firebird_db_handle;
95 
96 
97 typedef struct {
98 
99 	/* the link that owns this statement */
100 	pdo_firebird_db_handle *H;
101 
102 	/* the statement handle */
103 	isc_stmt_handle stmt;
104 
105 	/* the name of the cursor (if it has one) */
106 	char name[32];
107 
108 	/* the type of statement that was issued */
109 	char statement_type:8;
110 
111 	/* whether EOF was reached for this statement */
112 	unsigned exhausted:1;
113 
114 	/* successful isc_dsql_execute opens a cursor */
115 	unsigned cursor_open:1;
116 
117 	unsigned _reserved:22;
118 
119 	/* the named params that were converted to ?'s by the driver */
120 	HashTable *named_params;
121 
122 	/* allocated space to convert fields values to other types */
123 	char **fetch_buf;
124 
125 	/* the input SQLDA */
126 	XSQLDA *in_sqlda;
127 
128 	/* the output SQLDA */
129 	XSQLDA out_sqlda; /* last member */
130 
131 } pdo_firebird_stmt;
132 
133 extern const pdo_driver_t pdo_firebird_driver;
134 
135 extern const struct pdo_stmt_methods firebird_stmt_methods;
136 
137 void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, zend_long line);
138 
139 enum {
140 	PDO_FB_ATTR_DATE_FORMAT = PDO_ATTR_DRIVER_SPECIFIC,
141 	PDO_FB_ATTR_TIME_FORMAT,
142 	PDO_FB_ATTR_TIMESTAMP_FORMAT,
143 };
144 
145 #endif	/* PHP_PDO_FIREBIRD_INT_H */
146 
147 /*
148  * Local variables:
149  * tab-width: 4
150  * c-basic-offset: 4
151  * End:
152  * vim600: noet sw=4 ts=4 fdm=marker
153  * vim<600: noet sw=4 ts=4
154  */
155