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