1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 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 	unsigned sql_dialect:2;
90 
91 	/* prepend table names on column names in fetch */
92 	unsigned fetch_table_names:1;
93 
94 	unsigned _reserved:29;
95 
96 } pdo_firebird_db_handle;
97 
98 
99 typedef struct {
100 
101 	/* the link that owns this statement */
102 	pdo_firebird_db_handle *H;
103 
104 	/* the statement handle */
105 	isc_stmt_handle stmt;
106 
107 	/* the name of the cursor (if it has one) */
108 	char name[32];
109 
110 	/* the type of statement that was issued */
111 	char statement_type:8;
112 
113 	/* whether EOF was reached for this statement */
114 	unsigned exhausted:1;
115 
116 	/* successful isc_dsql_execute opens a cursor */
117 	unsigned cursor_open:1;
118 
119 	unsigned _reserved:22;
120 
121 	/* the named params that were converted to ?'s by the driver */
122 	HashTable *named_params;
123 
124 	/* allocated space to convert fields values to other types */
125 	char **fetch_buf;
126 
127 	/* the input SQLDA */
128 	XSQLDA *in_sqlda;
129 
130 	/* the output SQLDA */
131 	XSQLDA out_sqlda; /* last member */
132 
133 } pdo_firebird_stmt;
134 
135 extern const pdo_driver_t pdo_firebird_driver;
136 
137 extern const struct pdo_stmt_methods firebird_stmt_methods;
138 
139 void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, zend_long line);
140 
141 enum {
142 	PDO_FB_ATTR_DATE_FORMAT = PDO_ATTR_DRIVER_SPECIFIC,
143 	PDO_FB_ATTR_TIME_FORMAT,
144 	PDO_FB_ATTR_TIMESTAMP_FORMAT,
145 };
146 
147 #endif	/* PHP_PDO_FIREBIRD_INT_H */
148