php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
firebird_driver.c
Go to the documentation of this file.
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#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21#ifndef _GNU_SOURCE
22# define _GNU_SOURCE
23#endif
24
25#include "php.h"
26#include "zend_exceptions.h"
27#include "php_ini.h"
28#include "ext/standard/info.h"
29#include "ext/pdo/php_pdo.h"
31#include "php_pdo_firebird.h"
33#include "pdo_firebird_utils.h"
34
35static int php_firebird_alloc_prepare_stmt(pdo_dbh_t*, const zend_string*, XSQLDA*, isc_stmt_handle*,
36 HashTable*);
37static bool php_firebird_rollback_transaction(pdo_dbh_t *dbh);
38
39const char CHR_LETTER = 1;
40const char CHR_DIGIT = 2;
41const char CHR_IDENT = 4;
42const char CHR_QUOTE = 8;
43const char CHR_WHITE = 16;
44const char CHR_HEX = 32;
45const char CHR_INTRODUCER = 64;
46
47static const char classes_array[] = {
48 /* 000 */ 0,
49 /* 001 */ 0,
50 /* 002 */ 0,
51 /* 003 */ 0,
52 /* 004 */ 0,
53 /* 005 */ 0,
54 /* 006 */ 0,
55 /* 007 */ 0,
56 /* 008 */ 0,
57 /* 009 */ 16, /* CHR_WHITE */
58 /* 010 */ 16, /* CHR_WHITE */
59 /* 011 */ 0,
60 /* 012 */ 0,
61 /* 013 */ 16, /* CHR_WHITE */
62 /* 014 */ 0,
63 /* 015 */ 0,
64 /* 016 */ 0,
65 /* 017 */ 0,
66 /* 018 */ 0,
67 /* 019 */ 0,
68 /* 020 */ 0,
69 /* 021 */ 0,
70 /* 022 */ 0,
71 /* 023 */ 0,
72 /* 024 */ 0,
73 /* 025 */ 0,
74 /* 026 */ 0,
75 /* 027 */ 0,
76 /* 028 */ 0,
77 /* 029 */ 0,
78 /* 030 */ 0,
79 /* 031 */ 0,
80 /* 032 */ 16, /* CHR_WHITE */
81 /* 033 ! */ 0,
82 /* 034 " */ 8, /* CHR_QUOTE */
83 /* 035 # */ 0,
84 /* 036 $ */ 4, /* CHR_IDENT */
85 /* 037 % */ 0,
86 /* 038 & */ 0,
87 /* 039 ' */ 8, /* CHR_QUOTE */
88 /* 040 ( */ 0,
89 /* 041 ) */ 0,
90 /* 042 * */ 0,
91 /* 043 + */ 0,
92 /* 044 , */ 0,
93 /* 045 - */ 0,
94 /* 046 . */ 0,
95 /* 047 / */ 0,
96 /* 048 0 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
97 /* 049 1 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
98 /* 050 2 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
99 /* 051 3 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
100 /* 052 4 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
101 /* 053 5 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
102 /* 054 6 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
103 /* 055 7 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
104 /* 056 8 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
105 /* 057 9 */ 38, /* CHR_DIGIT | CHR_IDENT | CHR_HEX */
106 /* 058 : */ 0,
107 /* 059 ; */ 0,
108 /* 060 < */ 0,
109 /* 061 = */ 0,
110 /* 062 > */ 0,
111 /* 063 ? */ 0,
112 /* 064 @ */ 0,
113 /* 065 A */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
114 /* 066 B */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
115 /* 067 C */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
116 /* 068 D */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
117 /* 069 E */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
118 /* 070 F */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
119 /* 071 G */ 5, /* CHR_LETTER | CHR_IDENT */
120 /* 072 H */ 5, /* CHR_LETTER | CHR_IDENT */
121 /* 073 I */ 5, /* CHR_LETTER | CHR_IDENT */
122 /* 074 J */ 5, /* CHR_LETTER | CHR_IDENT */
123 /* 075 K */ 5, /* CHR_LETTER | CHR_IDENT */
124 /* 076 L */ 5, /* CHR_LETTER | CHR_IDENT */
125 /* 077 M */ 5, /* CHR_LETTER | CHR_IDENT */
126 /* 078 N */ 5, /* CHR_LETTER | CHR_IDENT */
127 /* 079 O */ 5, /* CHR_LETTER | CHR_IDENT */
128 /* 080 P */ 5, /* CHR_LETTER | CHR_IDENT */
129 /* 081 Q */ 5, /* CHR_LETTER | CHR_IDENT */
130 /* 082 R */ 5, /* CHR_LETTER | CHR_IDENT */
131 /* 083 S */ 5, /* CHR_LETTER | CHR_IDENT */
132 /* 084 T */ 5, /* CHR_LETTER | CHR_IDENT */
133 /* 085 U */ 5, /* CHR_LETTER | CHR_IDENT */
134 /* 086 V */ 5, /* CHR_LETTER | CHR_IDENT */
135 /* 087 W */ 5, /* CHR_LETTER | CHR_IDENT */
136 /* 088 X */ 5, /* CHR_LETTER | CHR_IDENT */
137 /* 089 Y */ 5, /* CHR_LETTER | CHR_IDENT */
138 /* 090 Z */ 5, /* CHR_LETTER | CHR_IDENT */
139 /* 091 [ */ 0,
140 /* 092 \ */ 0,
141 /* 093 ] */ 0,
142 /* 094 ^ */ 0,
143 /* 095 _ */ 68, /* CHR_IDENT | CHR_INTRODUCER */
144 /* 096 ` */ 0,
145 /* 097 a */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
146 /* 098 b */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
147 /* 099 c */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
148 /* 100 d */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
149 /* 101 e */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
150 /* 102 f */ 37, /* CHR_LETTER | CHR_IDENT | CHR_HEX */
151 /* 103 g */ 5, /* CHR_LETTER | CHR_IDENT */
152 /* 104 h */ 5, /* CHR_LETTER | CHR_IDENT */
153 /* 105 i */ 5, /* CHR_LETTER | CHR_IDENT */
154 /* 106 j */ 5, /* CHR_LETTER | CHR_IDENT */
155 /* 107 k */ 5, /* CHR_LETTER | CHR_IDENT */
156 /* 108 l */ 5, /* CHR_LETTER | CHR_IDENT */
157 /* 109 m */ 5, /* CHR_LETTER | CHR_IDENT */
158 /* 110 n */ 5, /* CHR_LETTER | CHR_IDENT */
159 /* 111 o */ 5, /* CHR_LETTER | CHR_IDENT */
160 /* 112 p */ 5, /* CHR_LETTER | CHR_IDENT */
161 /* 113 q */ 5, /* CHR_LETTER | CHR_IDENT */
162 /* 114 r */ 5, /* CHR_LETTER | CHR_IDENT */
163 /* 115 s */ 5, /* CHR_LETTER | CHR_IDENT */
164 /* 116 t */ 5, /* CHR_LETTER | CHR_IDENT */
165 /* 117 u */ 5, /* CHR_LETTER | CHR_IDENT */
166 /* 118 v */ 5, /* CHR_LETTER | CHR_IDENT */
167 /* 119 w */ 5, /* CHR_LETTER | CHR_IDENT */
168 /* 120 x */ 5, /* CHR_LETTER | CHR_IDENT */
169 /* 121 y */ 5, /* CHR_LETTER | CHR_IDENT */
170 /* 122 z */ 5, /* CHR_LETTER | CHR_IDENT */
171 /* 123 { */ 5, /* CHR_LETTER | CHR_IDENT */
172 /* 124 | */ 0,
173 /* 125 } */ 5, /* CHR_LETTER | CHR_IDENT */
174 /* 126 ~ */ 0,
175 /* 127 */ 0
176};
177
178static inline char php_firebird_classes(char idx)
179{
180 unsigned char uidx = (unsigned char) idx;
181 if (uidx > 127) return 0;
182 return classes_array[uidx];
183}
184
195
196static FbTokenType php_firebird_get_token(const char** begin, const char* end)
197{
199 const char* p = *begin;
200
201 char c = *p++;
202 switch (c)
203 {
204 case ':':
205 case '?':
207 break;
208
209 case '\'':
210 case '"':
211 while (p < end)
212 {
213 if (*p++ == c)
214 {
215 ret = ttString;
216 break;
217 }
218 }
219 break;
220
221 case '/':
222 if (p < end && *p == '*')
223 {
225 p++;
226 while (p < end)
227 {
228 if (*p++ == '*' && p < end && *p == '/')
229 {
230 p++;
231 ret = ttComment;
232 break;
233 }
234 }
235 }
236 else {
237 ret = ttOther;
238 }
239 break;
240
241 case '-':
242 if (p < end && *p == '-')
243 {
244 while (++p < end)
245 {
246 if (*p == '\r')
247 {
248 p++;
249 if (p < end && *p == '\n')
250 p++;
251 break;
252 }
253 else if (*p == '\n')
254 break;
255 }
256
257 ret = ttComment;
258 }
259 else
260 ret = ttOther;
261 break;
262
263 default:
264 if (php_firebird_classes(c) & CHR_DIGIT)
265 {
266 while (p < end && (php_firebird_classes(*p) & CHR_DIGIT))
267 p++;
268 ret = ttOther;
269 }
270 else if (php_firebird_classes(c) & CHR_IDENT)
271 {
272 while (p < end && (php_firebird_classes(*p) & CHR_IDENT))
273 p++;
274 ret = ttIdent;
275 }
276 else if (php_firebird_classes(c) & CHR_WHITE)
277 {
278 while (p < end && (php_firebird_classes(*p) & CHR_WHITE))
279 p++;
280 ret = ttWhite;
281 }
282 else
283 {
284 while (p < end && !(php_firebird_classes(*p) & (CHR_DIGIT | CHR_IDENT | CHR_WHITE)) &&
285 (*p != '/') && (*p != '-') && (*p != ':') && (*p != '?') &&
286 (*p != '\'') && (*p != '"'))
287 {
288 p++;
289 }
290 ret = ttOther;
291 }
292 }
293
294 *begin = p;
295 return ret;
296}
297
298static int php_firebird_preprocess(const zend_string* sql, char* sql_out, HashTable* named_params)
299{
300 bool passAsIs = 1, execBlock = 0;
301 zend_long pindex = -1;
302 char pname[254], ident[253], ident2[253];
303 unsigned int l;
304 const char* p = ZSTR_VAL(sql), * end = ZSTR_VAL(sql) + ZSTR_LEN(sql);
305 const char* start = p;
306 FbTokenType tok = php_firebird_get_token(&p, end);
307
308 const char* i = start;
309 while (p < end && (tok == ttComment || tok == ttWhite))
310 {
311 i = p;
312 tok = php_firebird_get_token(&p, end);
313 }
314
315 if (p >= end || tok != ttIdent)
316 {
317 /* Execute statement preprocess SQL error */
318 /* Statement expected */
319 return 0;
320 }
321 /* skip leading comments ?? */
322 start = i;
323 l = p - i;
324 /* check the length of the identifier */
325 /* in Firebird 4.0 it is 63 characters, in previous versions 31 bytes */
326 if (l > 252) {
327 return 0;
328 }
329 strncpy(ident, i, l);
330 ident[l] = '\0';
331 if (!strcasecmp(ident, "EXECUTE"))
332 {
333 /* For EXECUTE PROCEDURE and EXECUTE BLOCK statements, named parameters must be processed. */
334 /* However, in EXECUTE BLOCK this is done in a special way. */
335 const char* i2 = p;
336 tok = php_firebird_get_token(&p, end);
337 while (p < end && (tok == ttComment || tok == ttWhite))
338 {
339 i2 = p;
340 tok = php_firebird_get_token(&p, end);
341 }
342 if (p >= end || tok != ttIdent)
343 {
344 /* Execute statement preprocess SQL error */
345 /* Statement expected */
346 return 0;
347 }
348 l = p - i2;
349 /* check the length of the identifier */
350 /* in Firebird 4.0 it is 63 characters, in previous versions 31 bytes */
351 if (l > 252) {
352 return 0;
353 }
354 strncpy(ident2, i2, l);
355 ident2[l] = '\0';
356 execBlock = !strcasecmp(ident2, "BLOCK");
357 passAsIs = 0;
358 }
359 else
360 {
361 /* Named parameters must be processed in the INSERT, UPDATE, DELETE, MERGE statements. */
362 /* If CTEs are present in the query, they begin with the WITH keyword. */
363 passAsIs = strcasecmp(ident, "INSERT") && strcasecmp(ident, "UPDATE") &&
364 strcasecmp(ident, "DELETE") && strcasecmp(ident, "MERGE") &&
365 strcasecmp(ident, "SELECT") && strcasecmp(ident, "WITH");
366 }
367
368 if (passAsIs)
369 {
370 strcpy(sql_out, ZSTR_VAL(sql));
371 return 1;
372 }
373
374 strncat(sql_out, start, p - start);
375
376 while (p < end)
377 {
378 start = p;
379 tok = php_firebird_get_token(&p, end);
380 switch (tok)
381 {
382 case ttParamMark:
383 tok = php_firebird_get_token(&p, end);
384 if (tok == ttIdent /*|| tok == ttString*/)
385 {
386 ++pindex;
387 l = p - start;
388 /* check the length of the identifier */
389 /* in Firebird 4.0 it is 63 characters, in previous versions 31 bytes */
390 /* + symbol ":" */
391 if (l > 253) {
392 return 0;
393 }
394 strncpy(pname, start, l);
395 pname[l] = '\0';
396
397 if (named_params) {
398 zval tmp;
399 ZVAL_LONG(&tmp, pindex);
400 zend_hash_str_update(named_params, pname, l, &tmp);
401 }
402
403 strcat(sql_out, "?");
404 }
405 else
406 {
407 if (strncmp(start, "?", 1)) {
408 /* Execute statement preprocess SQL error */
409 /* Parameter name expected */
410 return 0;
411 }
412 ++pindex;
413 strncat(sql_out, start, p - start);
414 }
415 break;
416
417 case ttIdent:
418 if (execBlock)
419 {
420 /* In the EXECUTE BLOCK statement, processing must be */
421 /* carried out up to the keyword AS. */
422 l = p - start;
423 /* check the length of the identifier */
424 /* in Firebird 4.0 it is 63 characters, in previous versions 31 bytes */
425 if (l > 252) {
426 return 0;
427 }
428 strncpy(ident, start, l);
429 ident[l] = '\0';
430 if (!strcasecmp(ident, "AS"))
431 {
432 strncat(sql_out, start, end - start);
433 return 1;
434 }
435 }
436 /* TODO Check this is correct? */
438
439 case ttWhite:
440 case ttComment:
441 case ttString:
442 case ttOther:
443 strncat(sql_out, start, p - start);
444 break;
445
446 case ttBrokenComment:
447 {
448 /* Execute statement preprocess SQL error */
449 /* Unclosed comment found near ''@1'' */
450 return 0;
451 }
452 break;
453
454
455 case ttNone:
456 /* Execute statement preprocess SQL error */
457 return 0;
458 break;
459 }
460 }
461 return 1;
462}
463
464#if FB_API_VER >= 40
465/* set coercing a data type */
466static void set_coercing_output_data_types(XSQLDA* sqlda)
467{
468 /* Data types introduced in Firebird 4.0 are difficult to process using the Firebird Legacy API. */
469 /* These data types include DECFLOAT(16), DECFLOAT(34), INT128 (NUMERIC/DECIMAL(38, x)). */
470 /* In any case, at this data types can only be mapped to strings. */
471 /* This function allows you to ensure minimal performance of queries if they contain columns of the above types. */
472 unsigned int i;
473 short dtype;
474 short nullable;
475 XSQLVAR* var;
476 unsigned fb_client_version = fb_get_client_version();
477 unsigned fb_client_major_version = (fb_client_version >> 8) & 0xFF;
478 for (i=0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++) {
479 dtype = (var->sqltype & ~1); /* drop flag bit */
480 nullable = (var->sqltype & 1);
481 switch(dtype) {
482 case SQL_INT128:
483 var->sqltype = SQL_VARYING + nullable;
484 var->sqllen = 46;
485 var->sqlscale = 0;
486 break;
487
488 case SQL_DEC16:
489 var->sqltype = SQL_VARYING + nullable;
490 var->sqllen = 24;
491 break;
492
493 case SQL_DEC34:
494 var->sqltype = SQL_VARYING + nullable;
495 var->sqllen = 43;
496 break;
497
498 case SQL_TIMESTAMP_TZ:
499 if (fb_client_major_version < 4) {
500 /* If the client version is below 4.0, then it is impossible to handle time zones natively, */
501 /* so we convert these types to a string. */
502 var->sqltype = SQL_VARYING + nullable;
503 var->sqllen = 58;
504 }
505 break;
506
507 case SQL_TIME_TZ:
508 if (fb_client_major_version < 4) {
509 /* If the client version is below 4.0, then it is impossible to handle time zones natively, */
510 /* so we convert these types to a string. */
511 var->sqltype = SQL_VARYING + nullable;
512 var->sqllen = 46;
513 }
514 break;
515
516 default:
517 break;
518 }
519 }
520}
521#endif
522
523/* map driver specific error message to PDO error */
524void php_firebird_set_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *state, const size_t state_len,
525 const char *msg, const size_t msg_len) /* {{{ */
526{
527 pdo_error_type *const error_code = stmt ? &stmt->error_code : &dbh->error_code;
529 pdo_firebird_error_info *einfo = &H->einfo;
530 int sqlcode = -999;
531
532 if (einfo->errmsg) {
533 pefree(einfo->errmsg, dbh->is_persistent);
534 einfo->errmsg = NULL;
535 einfo->errmsg_length = 0;
536 }
537
538 if (H->isc_status && (H->isc_status[0] == 1 && H->isc_status[1] > 0)) {
539 char buf[512];
540 size_t buf_size = sizeof(buf), read_len = 0;
541 ssize_t tmp_len;
542 const ISC_STATUS *s = H->isc_status;
543 sqlcode = isc_sqlcode(s);
544
545 while ((buf_size > (read_len + 1)) && (tmp_len = fb_interpret(&buf[read_len], (buf_size - read_len - 1), &s)) && tmp_len > 0) {
546 read_len += tmp_len;
547 buf[read_len++] = ' ';
548 }
549
550 /* remove last space */
551 if (read_len) {
552 buf[read_len--] = '\0';
553 }
554
555 einfo->errmsg_length = read_len;
556 einfo->errmsg = pestrndup(buf, read_len, dbh->is_persistent);
557
558 char sqlstate[sizeof(pdo_error_type)];
559 fb_sqlstate(sqlstate, H->isc_status);
560 if (sqlstate != NULL && strlen(sqlstate) < sizeof(pdo_error_type)) {
561 strcpy(*error_code, sqlstate);
562 goto end;
563 }
564 } else if (msg && msg_len) {
565 einfo->errmsg_length = msg_len;
566 einfo->errmsg = pestrndup(msg, einfo->errmsg_length, dbh->is_persistent);
567 }
568
569 if (state && state_len && state_len < sizeof(pdo_error_type)) {
570 memcpy(*error_code, state, state_len + 1);
571 } else {
572 memcpy(*error_code, "HY000", sizeof("HY000"));
573 }
574
575end:
576 einfo->sqlcode = sqlcode;
577 if (!dbh->methods) {
579 }
580}
581/* }}} */
582
583/* called by PDO to close a db handle */
584static void firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
585{
587
588 if (H->tr) {
589 if (dbh->auto_commit) {
590 php_firebird_commit_transaction(dbh, /* retain */ false);
591 } else {
592 php_firebird_rollback_transaction(dbh);
593 }
594 }
595 H->in_manually_txn = 0;
596
597 /* isc_detach_database returns 0 on success, 1 on failure. */
598 if (H->db && isc_detach_database(H->isc_status, &H->db)) {
600 }
601
602 if (H->date_format) {
603 pefree(H->date_format, dbh->is_persistent);
604 }
605 if (H->time_format) {
606 pefree(H->time_format, dbh->is_persistent);
607 }
608 if (H->timestamp_format) {
609 pefree(H->timestamp_format, dbh->is_persistent);
610 }
611
612 if (H->einfo.errmsg) {
613 pefree(H->einfo.errmsg, dbh->is_persistent);
614 H->einfo.errmsg = NULL;
615 }
616
617 pefree(H, dbh->is_persistent);
618}
619/* }}} */
620
621/* called by PDO to prepare an SQL query */
622static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */
623 pdo_stmt_t *stmt, zval *driver_options)
624{
627 HashTable *np;
628
629 do {
630 isc_stmt_handle s = PDO_FIREBIRD_HANDLE_INITIALIZER;
631 XSQLDA num_sqlda;
632 static char const info[] = { isc_info_sql_stmt_type };
633 char result[8];
634
635 num_sqlda.version = PDO_FB_SQLDA_VERSION;
636 num_sqlda.sqln = 1;
637
638 ALLOC_HASHTABLE(np);
639 zend_hash_init(np, 8, NULL, NULL, 0);
640
641 /* allocate and prepare statement */
642 if (!php_firebird_alloc_prepare_stmt(dbh, sql, &num_sqlda, &s, np)) {
643 break;
644 }
645
646 /* allocate a statement handle struct of the right size (struct out_sqlda is inlined) */
647 S = ecalloc(1, sizeof(*S)-sizeof(XSQLDA) + XSQLDA_LENGTH(num_sqlda.sqld));
648 S->H = H;
649 S->stmt = s;
650 S->out_sqlda.version = PDO_FB_SQLDA_VERSION;
651 S->out_sqlda.sqln = stmt->column_count = num_sqlda.sqld;
652 S->named_params = np;
653
654 /* determine the statement type */
655 if (isc_dsql_sql_info(H->isc_status, &s, sizeof(info), const_cast(info), sizeof(result),
656 result)) {
657 break;
658 }
659 S->statement_type = result[3];
660
661 /* fill the output sqlda with information about the prepared query */
662 if (isc_dsql_describe(H->isc_status, &s, PDO_FB_SQLDA_VERSION, &S->out_sqlda)) {
664 break;
665 }
666
667#if FB_API_VER >= 40
668 /* set coercing a data type */
669 set_coercing_output_data_types(&S->out_sqlda);
670#endif
671
672 /* allocate the input descriptors */
673 if (isc_dsql_describe_bind(H->isc_status, &s, PDO_FB_SQLDA_VERSION, &num_sqlda)) {
674 break;
675 }
676
677 if (num_sqlda.sqld) {
678 S->in_sqlda = ecalloc(1,XSQLDA_LENGTH(num_sqlda.sqld));
679 S->in_sqlda->version = PDO_FB_SQLDA_VERSION;
680 S->in_sqlda->sqln = num_sqlda.sqld;
681
682 if (isc_dsql_describe_bind(H->isc_status, &s, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
683 break;
684 }
685
686 /* make all parameters nullable */
687 unsigned int i;
688 XSQLVAR* var;
689 for (i = 0, var = S->in_sqlda->sqlvar; i < S->in_sqlda->sqld; i++, var++) {
690 /* The low bit of sqltype indicates that the parameter can take a NULL value */
691 var->sqltype |= 1;
692 }
693 }
694
695 stmt->driver_data = S;
696 stmt->methods = &firebird_stmt_methods;
697 stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
698
699 return true;
700
701 } while (0);
702
704
706 FREE_HASHTABLE(np);
707
708 if (S) {
709 if (S->in_sqlda) {
710 efree(S->in_sqlda);
711 }
712 efree(S);
713 }
714
715 return false;
716}
717/* }}} */
718
719/* called by PDO to execute a statement that doesn't produce a result set */
720static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) /* {{{ */
721{
723 isc_stmt_handle stmt = PDO_FIREBIRD_HANDLE_INITIALIZER;
724 static char const info_count[] = { isc_info_sql_records };
725 char result[64];
726 int ret = 0;
727 XSQLDA in_sqlda, out_sqlda;
728
729 /* TODO no placeholders in exec() for now */
730 in_sqlda.version = out_sqlda.version = PDO_FB_SQLDA_VERSION;
731 in_sqlda.sqld = out_sqlda.sqld = 0;
732 out_sqlda.sqln = 1;
733
734 /* allocate and prepare statement */
735 if (!php_firebird_alloc_prepare_stmt(dbh, sql, &out_sqlda, &stmt, 0)) {
736 return -1;
737 }
738
739 /* execute the statement */
740 if (isc_dsql_execute2(H->isc_status, &H->tr, &stmt, PDO_FB_SQLDA_VERSION, &in_sqlda, &out_sqlda)) {
742 ret = -1;
743 goto free_statement;
744 }
745
746 /* find out how many rows were affected */
747 if (isc_dsql_sql_info(H->isc_status, &stmt, sizeof(info_count), const_cast(info_count),
748 sizeof(result), result)) {
750 ret = -1;
751 goto free_statement;
752 }
753
754 if (result[0] == isc_info_sql_records) {
755 unsigned i = 3, result_size = isc_vax_integer(&result[1],2);
756
757 if (result_size > sizeof(result)) {
758 ret = -1;
759 goto free_statement;
760 }
761 while (result[i] != isc_info_end && i < result_size) {
762 short len = (short)isc_vax_integer(&result[i+1],2);
763 /* bail out on bad len */
764 if (len != 1 && len != 2 && len != 4) {
765 ret = -1;
766 goto free_statement;
767 }
768 if (result[i] != isc_info_req_select_count) {
769 ret += isc_vax_integer(&result[i+3],len);
770 }
771 i += len+3;
772 }
773 }
774
775 if (dbh->auto_commit && !H->in_manually_txn) {
776 if (!php_firebird_commit_transaction(dbh, /* retain */ true)) {
777 ret = -1;
778 }
779 }
780
781free_statement:
782
783 if (isc_dsql_free_statement(H->isc_status, &stmt, DSQL_drop)) {
785 }
786
787 return ret;
788}
789/* }}} */
790
791/* called by the PDO SQL parser to add quotes to values that are copied into SQL */
792static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype)
793{
794 size_t qcount = 0;
795 char const *co, *l, *r;
796 char *c;
797 size_t quotedlen;
798 zend_string *quoted_str;
799
800 if (ZSTR_LEN(unquoted) == 0) {
801 return ZSTR_INIT_LITERAL("''", 0);
802 }
803
804 /* Firebird only requires single quotes to be doubled if string lengths are used */
805 /* count the number of ' characters */
806 for (co = ZSTR_VAL(unquoted); (co = strchr(co,'\'')); qcount++, co++);
807
808 if (UNEXPECTED(ZSTR_LEN(unquoted) + 2 > ZSTR_MAX_LEN - qcount)) {
809 return NULL;
810 }
811
812 quotedlen = ZSTR_LEN(unquoted) + qcount + 2;
813 quoted_str = zend_string_alloc(quotedlen, 0);
814 c = ZSTR_VAL(quoted_str);
815 *c++ = '\'';
816
817 /* foreach (chunk that ends in a quote) */
818 for (l = ZSTR_VAL(unquoted); (r = strchr(l,'\'')); l = r+1) {
819 strncpy(c, l, r-l+1);
820 c += (r-l+1);
821 /* add the second quote */
822 *c++ = '\'';
823 }
824
825 /* copy the remainder */
826 strncpy(c, l, quotedlen-(c-ZSTR_VAL(quoted_str))-1);
827 ZSTR_VAL(quoted_str)[quotedlen-1] = '\'';
828 ZSTR_VAL(quoted_str)[quotedlen] = '\0';
829
830 return quoted_str;
831}
832/* }}} */
833
834/* php_firebird_begin_transaction */
835static bool php_firebird_begin_transaction(pdo_dbh_t *dbh, bool is_auto_commit_txn) /* {{{ */
836{
838
839 /* isc_xxx are all 1 byte. */
840 char tpb[4] = { isc_tpb_version3 };
841 size_t tpb_size;
842
843 /* access mode. writable or readonly */
844 tpb[1] = H->is_writable_txn ? isc_tpb_write : isc_tpb_read;
845
846 if (is_auto_commit_txn) {
847 /*
848 * In autocommit mode, we need to always read the latest information, so we set `read committed`.
849 */
850 tpb[2] = isc_tpb_read_committed;
851 /* Ignore indeterminate data from other transactions. This option only required with `read committed`. */
852 tpb[3] = isc_tpb_rec_version;
853 tpb_size = 4;
854 } else {
855 switch (H->txn_isolation_level) {
856 /*
857 * firebird's `read committed` has the option to wait until other transactions
858 * commit or rollback if there is indeterminate data.
859 * Introducing too many configuration values at once can cause confusion, so
860 * we don't support in PDO that feature yet.
861 */
863 tpb[2] = isc_tpb_read_committed;
864 /* Ignore indeterminate data from other transactions. This option only required with `read committed`. */
865 tpb[3] = isc_tpb_rec_version;
866 tpb_size = 4;
867 break;
868
870 tpb[2] = isc_tpb_consistency;
871 tpb_size = 3;
872 break;
873
875 default:
876 tpb[2] = isc_tpb_concurrency;
877 tpb_size = 3;
878 break;
879 }
880 }
881
882 if (isc_start_transaction(H->isc_status, &H->tr, 1, &H->db, tpb_size, tpb)) {
884 return false;
885 }
886 return true;
887}
888/* }}} */
889
890/* called by PDO to start a transaction */
891static bool firebird_handle_manually_begin(pdo_dbh_t *dbh) /* {{{ */
892{
894
898 if (dbh->auto_commit && H->tr) {
899 if (!php_firebird_commit_transaction(dbh, /* retain */ false)) {
900 return false;
901 }
902 }
903
904 if (!php_firebird_begin_transaction(dbh, /* auto commit mode */ false)) {
905 return false;
906 }
907 H->in_manually_txn = 1;
908 return true;
909}
910/* }}} */
911
912/* php_firebird_commit_transaction */
913bool php_firebird_commit_transaction(pdo_dbh_t *dbh, bool retain) /* {{{ */
914{
916
925 if (retain) {
926 if (isc_commit_retaining(H->isc_status, &H->tr)) {
928 return false;
929 }
930 } else {
931 if (isc_commit_transaction(H->isc_status, &H->tr)) {
933 return false;
934 }
935 }
936 return true;
937}
938/* }}} */
939
940/* called by PDO to commit a transaction */
941static bool firebird_handle_manually_commit(pdo_dbh_t *dbh) /* {{{ */
942{
944 if (!php_firebird_commit_transaction(dbh, /*release*/ false)) {
945 return false;
946 }
947
952 if (dbh->auto_commit) {
953 if (!php_firebird_begin_transaction(dbh, /* auto commit mode */ true)) {
954 return false;
955 }
956 }
957 H->in_manually_txn = 0;
958 return true;
959}
960/* }}} */
961
962/* php_firebird_rollback_transaction */
963static bool php_firebird_rollback_transaction(pdo_dbh_t *dbh) /* {{{ */
964{
966
967 if (isc_rollback_transaction(H->isc_status, &H->tr)) {
969 return false;
970 }
971 return true;
972}
973/* }}} */
974
975/* called by PDO to rollback a transaction */
976static bool firebird_handle_manually_rollback(pdo_dbh_t *dbh) /* {{{ */
977{
979
980 if (!php_firebird_rollback_transaction(dbh)) {
981 return false;
982 }
983
988 if (dbh->auto_commit) {
989 if (!php_firebird_begin_transaction(dbh, /* auto commit mode */ true)) {
990 return false;
991 }
992 }
993 H->in_manually_txn = 0;
994 return true;
995}
996/* }}} */
997
998/* used by prepare and exec to allocate a statement handle and prepare the SQL */
999static int php_firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const zend_string *sql,
1000 XSQLDA *out_sqlda, isc_stmt_handle *s, HashTable *named_params)
1001{
1003 char *new_sql;
1004
1005 /* allocate the statement */
1006 if (isc_dsql_allocate_statement(H->isc_status, &H->db, s)) {
1007 php_firebird_error(dbh);
1008 return 0;
1009 }
1010
1011 /* in order to support named params, which Firebird itself doesn't,
1012 we need to replace :foo by ?, and store the name we just replaced */
1013 new_sql = emalloc(ZSTR_LEN(sql)+1);
1014 new_sql[0] = '\0';
1015 if (!php_firebird_preprocess(sql, new_sql, named_params)) {
1016 php_firebird_error_with_info(dbh, "07000", strlen("07000"), NULL, 0);
1017 efree(new_sql);
1018 return 0;
1019 }
1020
1021 /* prepare the statement */
1022 if (isc_dsql_prepare(H->isc_status, &H->tr, s, 0, new_sql, H->sql_dialect, out_sqlda)) {
1023 php_firebird_error(dbh);
1024 efree(new_sql);
1025 return 0;
1026 }
1027
1028 efree(new_sql);
1029 return 1;
1030}
1031
1032/* called by PDO to set a driver-specific dbh attribute */
1033static bool pdo_firebird_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */
1034{
1036 bool bval;
1037 zend_long lval;
1038
1039 switch (attr) {
1041 {
1042 if (!pdo_get_bool_param(&bval, val)) {
1043 return false;
1044 }
1045
1046 if (H->in_manually_txn) {
1047 /* change auto commit mode with an open transaction is illegal, because
1048 we won't know what to do with it */
1049 pdo_raise_impl_error(dbh, NULL, "HY000", "Cannot change autocommit mode while a transaction is already open");
1050 return false;
1051 }
1052
1053 /* ignore if the new value equals the old one */
1054 if (dbh->auto_commit ^ bval) {
1055 if (bval) {
1056 /*
1057 * change to auto commit mode.
1058 * If the transaction is not started, start it.
1059 */
1060 if (!H->tr) {
1061 if (!php_firebird_begin_transaction(dbh, /* auto commit mode */ true)) {
1062 return false;
1063 }
1064 }
1065 } else {
1066 /*
1067 * change to not auto commit mode.
1068 * close the transaction if exists.
1069 */
1070 if (H->tr) {
1071 if (!php_firebird_commit_transaction(dbh, /* retain */ false)) {
1072 return false;
1073 }
1074 }
1075 }
1076 dbh->auto_commit = bval;
1077 }
1078 }
1079 return true;
1080
1082 if (!pdo_get_bool_param(&bval, val)) {
1083 return false;
1084 }
1085 H->fetch_table_names = bval;
1086 return true;
1087
1089 {
1090 zend_string *str = zval_try_get_string(val);
1091 if (UNEXPECTED(!str)) {
1092 return false;
1093 }
1094 if (H->date_format) {
1095 pefree(H->date_format, dbh->is_persistent);
1096 H->date_format = NULL;
1097 }
1098 H->date_format = pestrndup(ZSTR_VAL(str), ZSTR_LEN(str),dbh->is_persistent);
1099 zend_string_release_ex(str, 0);
1100 }
1101 return true;
1102
1104 {
1105 zend_string *str = zval_try_get_string(val);
1106 if (UNEXPECTED(!str)) {
1107 return false;
1108 }
1109 if (H->time_format) {
1110 pefree(H->time_format, dbh->is_persistent);
1111 H->time_format = NULL;
1112 }
1113 H->time_format = pestrndup(ZSTR_VAL(str), ZSTR_LEN(str),dbh->is_persistent);
1114 zend_string_release_ex(str, 0);
1115 }
1116 return true;
1117
1119 {
1120 zend_string *str = zval_try_get_string(val);
1121 if (UNEXPECTED(!str)) {
1122 return false;
1123 }
1124 if (H->timestamp_format) {
1125 pefree(H->timestamp_format, dbh->is_persistent);
1126 H->timestamp_format = NULL;
1127 }
1128 H->timestamp_format = pestrndup(ZSTR_VAL(str), ZSTR_LEN(str),dbh->is_persistent);
1129 zend_string_release_ex(str, 0);
1130 }
1131 return true;
1132
1134 {
1135 if (!pdo_get_long_param(&lval, val)) {
1136 return false;
1137 }
1138
1139 if (H->in_manually_txn) {
1140 pdo_raise_impl_error(dbh, NULL, "HY000", "Cannot change transaction isolation level while a transaction is already open");
1141 return false;
1142 }
1143
1144 /* ignore if the new value equals the old one */
1145 if (H->txn_isolation_level != lval) {
1146 if (lval == PDO_FB_READ_COMMITTED ||
1147 lval == PDO_FB_REPEATABLE_READ ||
1148 lval == PDO_FB_SERIALIZABLE
1149 ) {
1150 /*
1151 * Autocommit mode is always read-committed, so this setting is used the next time
1152 * a manual transaction starts. Therefore, there is no need to immediately reopen the transaction.
1153 */
1154 H->txn_isolation_level = lval;
1155 } else {
1156 zend_value_error("Pdo\\Firebird::TRANSACTION_ISOLATION_LEVEL must be a valid transaction isolation level "
1157 "(Pdo\\Firebird::READ_COMMITTED, Pdo\\Firebird::REPEATABLE_READ, or Pdo\\Firebird::SERIALIZABLE)");
1158 return false;
1159 }
1160 }
1161 }
1162 return true;
1163
1165 {
1166 if (!pdo_get_bool_param(&bval, val)) {
1167 return false;
1168 }
1169
1170 if (H->in_manually_txn) {
1171 pdo_raise_impl_error(dbh, NULL, "HY000", "Cannot change access mode while a transaction is already open");
1172 return false;
1173 }
1174
1175 /* ignore if the new value equals the old one */
1176 if (H->is_writable_txn != bval) {
1177 H->is_writable_txn = bval;
1178 if (dbh->auto_commit) {
1179 if (H->tr) {
1180 if (!php_firebird_commit_transaction(dbh, /* retain */ false)) {
1181 /* In case of error, revert the setting */
1182 H->is_writable_txn = !bval;
1183 return false;
1184 }
1185 }
1186 if (!php_firebird_begin_transaction(dbh, /* auto commit mode */ true)) {
1187 /* In case of error, revert the setting */
1188 H->is_writable_txn = !bval;
1189 return false;
1190 }
1191 }
1192 }
1193 }
1194 return true;
1195 }
1196 return false;
1197}
1198/* }}} */
1199
1200#define INFO_BUF_LEN 512
1201
1202/* callback to used to report database server info */
1203static void php_firebird_info_cb(void *arg, char const *s) /* {{{ */
1204{
1205 if (arg) {
1206 if (*(char*)arg) { /* second call */
1207 strlcat(arg, " ", INFO_BUF_LEN);
1208 }
1210 }
1211}
1212/* }}} */
1213
1214/* called by PDO to get a driver-specific dbh attribute */
1215static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */
1216{
1218
1219 switch (attr) {
1220 char tmp[INFO_BUF_LEN];
1221
1224 return 1;
1225
1227 ZVAL_BOOL(val, !isc_version(&H->db, php_firebird_info_cb, NULL));
1228 return 1;
1229
1231#if defined(__GNUC__) || defined(PHP_WIN32)
1232 info_func_t info_func = NULL;
1233#ifdef __GNUC__
1234 info_func = (info_func_t)dlsym(RTLD_DEFAULT, "isc_get_client_version");
1235#else
1236 HMODULE l = GetModuleHandle("fbclient");
1237
1238 if (!l) {
1239 break;
1240 }
1241 info_func = (info_func_t)GetProcAddress(l, "isc_get_client_version");
1242#endif
1243 if (info_func) {
1244 info_func(tmp);
1245 ZVAL_STRING(val, tmp);
1246 }
1247#else
1248 ZVAL_NULL(val);
1249#endif
1250 }
1251 return 1;
1252
1255 *tmp = 0;
1256
1257 if (!isc_version(&H->db, php_firebird_info_cb, (void*)tmp)) {
1258 ZVAL_STRING(val, tmp);
1259 return 1;
1260 }
1261 return -1;
1262
1264 ZVAL_BOOL(val, H->fetch_table_names);
1265 return 1;
1266
1268 ZVAL_STRING(val, H->date_format ? H->date_format : PDO_FB_DEF_DATE_FMT);
1269 return 1;
1270
1272 ZVAL_STRING(val, H->time_format ? H->time_format : PDO_FB_DEF_TIME_FMT);
1273 return 1;
1274
1276 ZVAL_STRING(val, H->timestamp_format ? H->timestamp_format : PDO_FB_DEF_TIMESTAMP_FMT);
1277 return 1;
1278
1280 ZVAL_LONG(val, H->txn_isolation_level);
1281 return 1;
1282
1284 ZVAL_BOOL(val, H->is_writable_txn);
1285 return 1;
1286 }
1287 return 0;
1288}
1289/* }}} */
1290
1291/* called by PDO to check liveness */
1292static zend_result pdo_firebird_check_liveness(pdo_dbh_t *dbh) /* {{{ */
1293{
1295
1296 /* fb_ping return 0 if the connection is alive */
1297 return fb_ping(H->isc_status, &H->db) ? FAILURE : SUCCESS;
1298}
1299/* }}} */
1300
1301/* called by PDO to retrieve driver-specific information about an error that has occurred */
1302static void pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
1303{
1305 if (H->einfo.sqlcode != IS_NULL) {
1306 add_next_index_long(info, H->einfo.sqlcode);
1307 }
1308 if (H->einfo.errmsg && H->einfo.errmsg_length) {
1309 add_next_index_stringl(info, H->einfo.errmsg, H->einfo.errmsg_length);
1310 }
1311}
1312/* }}} */
1313
1314/* {{{ firebird_in_manually_transaction */
1315static bool pdo_firebird_in_manually_transaction(pdo_dbh_t *dbh)
1316{
1323 return H->in_manually_txn;
1324}
1325/* }}} */
1326
1327static const struct pdo_dbh_methods firebird_methods = { /* {{{ */
1328 firebird_handle_closer,
1329 firebird_handle_preparer,
1330 firebird_handle_doer,
1331 firebird_handle_quoter,
1332 firebird_handle_manually_begin,
1333 firebird_handle_manually_commit,
1334 firebird_handle_manually_rollback,
1335 pdo_firebird_set_attribute,
1336 NULL, /* last_id not supported */
1337 pdo_firebird_fetch_error_func,
1338 pdo_firebird_get_attribute,
1339 pdo_firebird_check_liveness,
1340 NULL, /* get driver methods */
1341 NULL, /* request shutdown */
1342 pdo_firebird_in_manually_transaction,
1343 NULL, /* get gc */
1344 NULL /* scanner */
1345};
1346/* }}} */
1347
1348/* the driver-specific PDO handle constructor */
1349static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ */
1350{
1351 struct pdo_data_src_parser vars[] = {
1352 { "dbname", NULL, 0 },
1353 { "charset", NULL, 0 },
1354 { "role", NULL, 0 },
1355 { "dialect", "3", 0 },
1356 { "user", NULL, 0 },
1357 { "password", NULL, 0 }
1358 };
1359 int i, ret = 0;
1360 short buf_len = 256, dpb_len;
1361
1362 pdo_firebird_db_handle *H = dbh->driver_data = pecalloc(1,sizeof(*H),dbh->is_persistent);
1363
1365
1366 if (!dbh->username && vars[4].optval) {
1367 dbh->username = pestrdup(vars[4].optval, dbh->is_persistent);
1368 }
1369
1370 if (!dbh->password && vars[5].optval) {
1371 dbh->password = pestrdup(vars[5].optval, dbh->is_persistent);
1372 }
1373
1374 H->in_manually_txn = 0;
1375 H->is_writable_txn = pdo_attr_lval(driver_options, PDO_FB_WRITABLE_TRANSACTION, 1);
1376 zend_long txn_isolation_level = pdo_attr_lval(driver_options, PDO_FB_TRANSACTION_ISOLATION_LEVEL, PDO_FB_REPEATABLE_READ);
1377 if (txn_isolation_level == PDO_FB_READ_COMMITTED ||
1378 txn_isolation_level == PDO_FB_REPEATABLE_READ ||
1379 txn_isolation_level == PDO_FB_SERIALIZABLE
1380 ) {
1381 H->txn_isolation_level = txn_isolation_level;
1382 } else {
1383 zend_value_error("Pdo\\Firebird::TRANSACTION_ISOLATION_LEVEL must be a valid transaction isolation level "
1384 "(Pdo\\Firebird::READ_COMMITTED, Pdo\\Firebird::REPEATABLE_READ, or Pdo\\Firebird::SERIALIZABLE)");
1385 ret = 0;
1386 }
1387
1388 do {
1389 static char const dpb_flags[] = {
1390 isc_dpb_user_name, isc_dpb_password, isc_dpb_lc_ctype, isc_dpb_sql_role_name };
1391 char const *dpb_values[] = { dbh->username, dbh->password, vars[1].optval, vars[2].optval };
1392 char dpb_buffer[256] = { isc_dpb_version1 }, *dpb;
1393
1394 dpb = dpb_buffer + 1;
1395
1396 /* loop through all the provided arguments and set dpb fields accordingly */
1397 for (i = 0; i < sizeof(dpb_flags); ++i) {
1398 if (dpb_values[i] && buf_len > 0) {
1399 dpb_len = slprintf(dpb, buf_len, "%c%c%s", dpb_flags[i], (unsigned char)strlen(dpb_values[i]),
1400 dpb_values[i]);
1401 dpb += dpb_len;
1402 buf_len -= dpb_len;
1403 }
1404 }
1405
1406 H->sql_dialect = PDO_FB_DIALECT;
1407 if (vars[3].optval) {
1408 H->sql_dialect = atoi(vars[3].optval);
1409 }
1410
1411 /* fire it up baby! */
1412 if (isc_attach_database(H->isc_status, 0, vars[0].optval, &H->db,(short)(dpb-dpb_buffer), dpb_buffer)) {
1413 break;
1414 }
1415
1416 dbh->methods = &firebird_methods;
1417 dbh->native_case = PDO_CASE_UPPER;
1418 dbh->alloc_own_columns = 1;
1419
1420 ret = 1;
1421
1422 } while (0);
1423
1424 for (i = 0; i < sizeof(vars)/sizeof(vars[0]); ++i) {
1425 if (vars[i].freeme) {
1426 efree(vars[i].optval);
1427 }
1428 }
1429
1430 if (!dbh->methods) {
1431 char errmsg[512];
1432 const ISC_STATUS *s = H->isc_status;
1433 fb_interpret(errmsg, sizeof(errmsg),&s);
1434 zend_throw_exception_ex(php_pdo_get_exception(), H->isc_status[1], "SQLSTATE[%s] [%ld] %s",
1435 "HY000", H->isc_status[1], errmsg);
1436 }
1437
1438 if (ret && dbh->auto_commit && !H->tr) {
1439 ret = php_firebird_begin_transaction(dbh, /* auto commit mode */ true);
1440 }
1441
1442 if (!ret) {
1443 firebird_handle_closer(dbh);
1444 }
1445
1446 return ret;
1447}
1448/* }}} */
1449
1450
1452 PDO_DRIVER_HEADER(firebird),
1453 pdo_firebird_handle_factory
1454};
1455/* }}} */
strcat($n)
Definition bench.php:337
size_t len
Definition apprentice.c:174
strchr(string $haystack, string $needle, bool $before_needle=false)
char s[4]
Definition cdf.c:77
int begin
Definition eaw_table.h:20
memcpy(ptr1, ptr2, size)
zval * arg
Definition ffi.c:3975
new_type attr
Definition ffi.c:4364
zval * val
Definition ffi.c:4262
buf start
Definition ffi.c:4687
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
const char CHR_QUOTE
bool php_firebird_commit_transaction(pdo_dbh_t *dbh, bool retain)
const char CHR_INTRODUCER
FbTokenType
@ ttWhite
@ ttIdent
@ ttBrokenComment
@ ttOther
@ ttParamMark
@ ttComment
@ ttString
@ ttNone
const char CHR_LETTER
const char CHR_DIGIT
void php_firebird_set_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *state, const size_t state_len, const char *msg, const size_t msg_len)
const char CHR_HEX
#define INFO_BUF_LEN
const pdo_driver_t pdo_firebird_driver
const char CHR_WHITE
const char CHR_IDENT
const struct pdo_stmt_methods firebird_stmt_methods
#define NULL
Definition gdcache.h:45
#define S(s, l, r)
Definition hash_gost.c:121
#define SUCCESS
Definition hash_sha3.c:261
#define H(x, y, z)
Definition md5.c:146
PDO_API int php_pdo_parse_data_source(const char *data_source, zend_ulong data_source_len, struct pdo_data_src_parser *parsed, int nparams)
Definition pdo.c:157
PDO_API zend_class_entry * php_pdo_get_exception(void)
Definition pdo.c:62
PDO_API bool pdo_get_long_param(zend_long *lval, zval *value)
Definition pdo_dbh.c:774
void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, pdo_error_type sqlstate, const char *supp)
Definition pdo_dbh.c:68
PDO_API bool pdo_get_bool_param(bool *bval, zval *value)
Definition pdo_dbh.c:792
void pdo_throw_exception(unsigned int driver_errcode, char *driver_errmsg, pdo_error_type *pdo_error)
Definition pdo_dbh.c:41
unsigned fb_get_client_version(void)
#define strlcat
Definition php.h:169
unsigned const char * end
Definition php_ffi.h:51
php_json_error_code error_code
Definition php_json.h:92
char sqlstate[6]
struct _pdo_dbh_t pdo_dbh_t
#define PDO_DRIVER_HEADER(name)
struct _pdo_stmt_t pdo_stmt_t
pdo_param_type
@ PDO_CASE_UPPER
char pdo_error_type[6]
@ PDO_PLACEHOLDER_POSITIONAL
@ PDO_ATTR_CONNECTION_STATUS
@ PDO_ATTR_SERVER_VERSION
@ PDO_ATTR_SERVER_INFO
@ PDO_ATTR_AUTOCOMMIT
@ PDO_ATTR_FETCH_TABLE_NAMES
@ PDO_ATTR_CLIENT_VERSION
#define PDO_FIREBIRD_HANDLE_INITIALIZER
#define PDO_FB_DEF_DATE_FMT
#define PDO_FB_SQLDA_VERSION
#define php_firebird_error(d)
#define PDO_FB_DEF_TIMESTAMP_FMT
@ PDO_FB_ATTR_TIME_FORMAT
@ PDO_FB_SERIALIZABLE
@ PDO_FB_READ_COMMITTED
@ PDO_FB_TRANSACTION_ISOLATION_LEVEL
@ PDO_FB_ATTR_TIMESTAMP_FORMAT
@ PDO_FB_WRITABLE_TRANSACTION
@ PDO_FB_REPEATABLE_READ
@ PDO_FB_ATTR_DATE_FORMAT
#define php_firebird_error_with_info(d, e, el, m, ml)
#define PDO_FB_DEF_TIME_FMT
#define const_cast(s)
#define PDO_FB_DIALECT
char * msg
Definition phpdbg.h:289
#define RTLD_DEFAULT
p
Definition session.c:1105
#define slprintf
Definition snprintf.h:89
const char * data_source
unsigned is_persistent
size_t data_source_len
void * driver_data
pdo_error_type error_code
unsigned alloc_own_columns
unsigned auto_commit
const struct pdo_dbh_methods * methods
pdo_error_type error_code
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
Definition zend.c:1849
ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length)
Definition zend_API.c:2195
ZEND_API zend_result add_next_index_long(zval *arg, zend_long n)
Definition zend_API.c:2132
#define ZVAL_STRING(z, s)
Definition zend_API.h:956
#define pestrdup(s, persistent)
Definition zend_alloc.h:206
#define ecalloc(nmemb, size)
Definition zend_alloc.h:158
#define pestrndup(s, length, persistent)
Definition zend_alloc.h:207
#define efree(ptr)
Definition zend_alloc.h:155
#define pefree(ptr, persistent)
Definition zend_alloc.h:191
#define FREE_HASHTABLE(ht)
Definition zend_alloc.h:234
#define pecalloc(nmemb, size, persistent)
Definition zend_alloc.h:200
#define ALLOC_HASHTABLE(ht)
Definition zend_alloc.h:231
#define emalloc(size)
Definition zend_alloc.h:151
struct _zval_struct zval
strlen(string $string)
strncmp(string $string1, string $string2, int $length)
zend_string_release_ex(func->internal_function.function_name, 0)
#define strcasecmp(s1, s2)
ZEND_API ZEND_COLD zend_object * zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format,...)
uint32_t(* info_func_t)(const zend_call_info *call_info, const zend_ssa *ssa)
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
Definition zend_hash.c:1727
ZEND_API zval *ZEND_FASTCALL zend_hash_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
Definition zend_hash.c:1031
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
Definition zend_hash.h:108
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
#define ZEND_FALLTHROUGH
#define UNEXPECTED(condition)
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
#define ZSTR_INIT_LITERAL(s, persistent)
#define ZSTR_MAX_LEN
#define ZSTR_LEN(zstr)
Definition zend_string.h:69
#define ZVAL_NULL(z)
#define ZVAL_LONG(z, l)
struct _zend_array HashTable
Definition zend_types.h:386
#define IS_NULL
Definition zend_types.h:601
@ FAILURE
Definition zend_types.h:61
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
#define ZVAL_BOOL(z, b)
bool result
zval * ret