Skip to content

Commit 3fb42a3

Browse files
sim1984cmb69
authored andcommitted
Add support for Interbase 1 dialect
1 parent 9e4c5db commit 3fb42a3

File tree

6 files changed

+83
-8
lines changed

6 files changed

+83
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ PHP NEWS
2525
-Opcache:
2626
. Fixed bug #78512 (Cannot make preload work). (Dmitry)
2727

28+
- PDO_Firebird:
29+
. Implemented FR #65690 (PDO_Firebird should also support dialect 1).
30+
(Simonov Denis)
31+
2832
- Reflection:
2933
. Fixed bug #78697 (ReflectionClass::implementsInterface - inaccurate error
3034
message with traits). (villfa)

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,9 @@ PHP 7.4 UPGRADE NOTES
591591
exists "?" operator. For more details see the RFC:
592592
https://wiki.php.net/rfc/pdo_escape_placeholders
593593

594+
- PDO_Firebird:
595+
. The extension now also support dialect 1 in addition to dialect 3.
596+
594597
- Reflection:
595598
. Numeric value of class, property, function and constant modifiers was
596599
changed. Don't filter methods and properties through

ext/pdo_firebird/firebird_driver.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, size_t s
417417
}
418418

419419
/* prepare the statement */
420-
if (isc_dsql_prepare(H->isc_status, &H->tr, s, 0, new_sql, PDO_FB_DIALECT, out_sqlda)) {
420+
if (isc_dsql_prepare(H->isc_status, &H->tr, s, 0, new_sql, H->sql_dialect, out_sqlda)) {
421421
RECORD_ERROR(dbh);
422422
efree(new_sql);
423423
return 0;
@@ -624,6 +624,7 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /*
624624
{ "dbname", NULL, 0 },
625625
{ "charset", NULL, 0 },
626626
{ "role", NULL, 0 },
627+
{ "dialect", "3", 0 },
627628
{ "user", NULL, 0 },
628629
{ "password", NULL, 0 }
629630
};
@@ -632,14 +633,14 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /*
632633

633634
pdo_firebird_db_handle *H = dbh->driver_data = pecalloc(1,sizeof(*H),dbh->is_persistent);
634635

635-
php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 5);
636+
php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 6);
636637

637-
if (!dbh->username && vars[3].optval) {
638-
dbh->username = pestrdup(vars[3].optval, dbh->is_persistent);
638+
if (!dbh->username && vars[4].optval) {
639+
dbh->username = pestrdup(vars[4].optval, dbh->is_persistent);
639640
}
640641

641-
if (!dbh->password && vars[4].optval) {
642-
dbh->password = pestrdup(vars[4].optval, dbh->is_persistent);
642+
if (!dbh->password && vars[5].optval) {
643+
dbh->password = pestrdup(vars[5].optval, dbh->is_persistent);
643644
}
644645

645646
do {
@@ -660,6 +661,11 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /*
660661
}
661662
}
662663

664+
H->sql_dialect = PDO_FB_DIALECT;
665+
if (vars[3].optval) {
666+
H->sql_dialect = atoi(vars[3].optval);
667+
}
668+
663669
/* fire it up baby! */
664670
if (isc_attach_database(H->isc_status, 0, vars[0].optval, &H->db,(short)(dpb-dpb_buffer), dpb_buffer)) {
665671
break;

ext/pdo_firebird/firebird_statement.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{
374374

375375
*ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL);
376376

377-
if (n >= 0) {
377+
if ((var->sqltype & ~1) == SQL_DOUBLE) {
378+
*len = slprintf(*ptr, CHAR_BUF_LEN, "%.*F", -var->sqlscale, *(double*)var->sqldata);
379+
} else if (n >= 0) {
378380
*len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK "d.%0*" LL_MASK "d",
379381
n / f, -var->sqlscale, n % f);
380382
} else if (n <= -f) {

ext/pdo_firebird/php_pdo_firebird_int.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ typedef struct {
8686
char *time_format;
8787
char *timestamp_format;
8888

89+
unsigned sql_dialect:2;
90+
8991
/* prepend table names on column names in fetch */
9092
unsigned fetch_table_names:1;
9193

92-
unsigned _reserved:31;
94+
unsigned _reserved:29;
9395

9496
} pdo_firebird_db_handle;
9597

ext/pdo_firebird/tests/dialect_1.phpt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--TEST--
2+
PDO_Firebird: support 1 sql dialect
3+
--SKIPIF--
4+
<?php require('skipif.inc');
5+
if (strpos(getenv('PDO_FIREBIRD_TEST_DSN'), 'dialect=1')===false) {
6+
die('skip: PDO_FIREBIRD_TEST_DSN must contain a string "dialect=1"');
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
require("testdb.inc");
12+
13+
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
14+
$dbh->setAttribute(PDO::FB_ATTR_TIMESTAMP_FORMAT, '%Y-%m-%d %H:%M:%S');
15+
16+
$sql =
17+
'SELECT
18+
1 as N,
19+
2.0 as F,
20+
cast(0.76 as numeric(15, 2)) as K,
21+
cast(\'2019-06-12\' as date) as DT
22+
FROM RDB$DATABASE';
23+
$query = $dbh->prepare($sql);
24+
$query->execute();
25+
$row = $query->fetch(\PDO::FETCH_OBJ);
26+
var_dump($row->N);
27+
var_dump($row->F);
28+
var_dump($row->K);
29+
var_dump($row->DT);
30+
31+
unset($query);
32+
33+
$dbh->exec('RECREATE TABLE test_d1(K numeric(15, 2), DT date)');
34+
$sql='INSERT INTO test_d1(K, DT) values(?, ?)';
35+
$query = $dbh->prepare($sql);
36+
$query->execute([0.76, '2019-06-12']);
37+
unset($query);
38+
39+
$sql='SELECT * FROM test_d1';
40+
$query = $dbh->prepare($sql);
41+
$query->execute();
42+
$row = $query->fetch(\PDO::FETCH_OBJ);
43+
var_dump($row->K);
44+
var_dump($row->DT);
45+
46+
unset($query);
47+
unset($dbh);
48+
echo "done\n";
49+
50+
?>
51+
--EXPECT--
52+
int(1)
53+
string(8) "2.000000"
54+
string(4) "0.76"
55+
string(19) "2019-06-12 00:00:00"
56+
string(4) "0.76"
57+
string(19) "2019-06-12 00:00:00"
58+
done

0 commit comments

Comments
 (0)