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