From 15b329783da7cd8ff90001cd6b35c1106483534a Mon Sep 17 00:00:00 2001 From: Simonov Denis Date: Tue, 1 Oct 2019 00:14:54 +0300 Subject: [PATCH 1/6] support 1 dialect --- ext/pdo_firebird/firebird_driver.c | 18 ++++++++++++------ ext/pdo_firebird/firebird_statement.c | 4 +++- ext/pdo_firebird/php_pdo_firebird_int.h | 2 ++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index c31a32bd37fa2..22719d89bf948 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -415,7 +415,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, size_t s } /* prepare the statement */ - if (isc_dsql_prepare(H->isc_status, &H->tr, s, 0, new_sql, PDO_FB_DIALECT, out_sqlda)) { + if (isc_dsql_prepare(H->isc_status, &H->tr, s, 0, new_sql, H->sql_dialect, out_sqlda)) { RECORD_ERROR(dbh); efree(new_sql); return 0; @@ -622,6 +622,7 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* { "dbname", NULL, 0 }, { "charset", NULL, 0 }, { "role", NULL, 0 }, + { "dialect", "3", 0 }, { "user", NULL, 0 }, { "password", NULL, 0 } }; @@ -630,14 +631,14 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* pdo_firebird_db_handle *H = dbh->driver_data = pecalloc(1,sizeof(*H),dbh->is_persistent); - php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 5); + php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 6); - if (!dbh->username && vars[3].optval) { - dbh->username = pestrdup(vars[3].optval, dbh->is_persistent); + if (!dbh->username && vars[4].optval) { + dbh->username = pestrdup(vars[4].optval, dbh->is_persistent); } - if (!dbh->password && vars[4].optval) { - dbh->password = pestrdup(vars[4].optval, dbh->is_persistent); + if (!dbh->password && vars[5].optval) { + dbh->password = pestrdup(vars[5].optval, dbh->is_persistent); } do { @@ -657,6 +658,11 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* buf_len -= dpb_len; } } + + H->sql_dialect = PDO_FB_DIALECT; + if (vars[3].optval) { + H->sql_dialect = atoi(vars[3].optval); + } /* fire it up baby! */ if (isc_attach_database(H->isc_status, 0, vars[0].optval, &H->db,(short)(dpb-dpb_buffer), dpb_buffer)) { diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index e84ad7c4f05d4..4b45ea8c7d01e 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -372,7 +372,9 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ *ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL); - if (n >= 0) { + if((var->sqltype & ~1)==SQL_DOUBLE) { + *len = slprintf(*ptr, CHAR_BUF_LEN, "%.*F", -var->sqlscale, *(double*)var->sqldata); + } else if (n >= 0) { *len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -var->sqlscale, n % f); } else if (n <= -f) { diff --git a/ext/pdo_firebird/php_pdo_firebird_int.h b/ext/pdo_firebird/php_pdo_firebird_int.h index f846922eb49dd..5c38d1d03e65e 100644 --- a/ext/pdo_firebird/php_pdo_firebird_int.h +++ b/ext/pdo_firebird/php_pdo_firebird_int.h @@ -83,6 +83,8 @@ typedef struct { char *date_format; char *time_format; char *timestamp_format; + + unsigned sql_dialect; /* prepend table names on column names in fetch */ unsigned fetch_table_names:1; From c81f0380b728532eddf3bc596aec59d459b21b7f Mon Sep 17 00:00:00 2001 From: Simonov Denis Date: Fri, 4 Oct 2019 18:49:12 +0300 Subject: [PATCH 2/6] pad space --- ext/pdo_firebird/firebird_statement.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index 4b45ea8c7d01e..685b9d62ea277 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -372,7 +372,7 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ *ptr = FETCH_BUF(S->fetch_buf[colno], char, CHAR_BUF_LEN, NULL); - if((var->sqltype & ~1)==SQL_DOUBLE) { + if ((var->sqltype & ~1) == SQL_DOUBLE) { *len = slprintf(*ptr, CHAR_BUF_LEN, "%.*F", -var->sqlscale, *(double*)var->sqldata); } else if (n >= 0) { *len = slprintf(*ptr, CHAR_BUF_LEN, "%" LL_MASK "d.%0*" LL_MASK "d", From febbbe406fd5c92b2f3c282cb0b582d4454e533b Mon Sep 17 00:00:00 2001 From: Simonov Denis Date: Tue, 8 Oct 2019 20:17:55 +0300 Subject: [PATCH 3/6] store dialect as bitfield --- ext/pdo_firebird/php_pdo_firebird_int.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/pdo_firebird/php_pdo_firebird_int.h b/ext/pdo_firebird/php_pdo_firebird_int.h index 5c38d1d03e65e..1da6def31e58d 100644 --- a/ext/pdo_firebird/php_pdo_firebird_int.h +++ b/ext/pdo_firebird/php_pdo_firebird_int.h @@ -84,12 +84,12 @@ typedef struct { char *time_format; char *timestamp_format; - unsigned sql_dialect; + unsigned sql_dialect:2; /* prepend table names on column names in fetch */ unsigned fetch_table_names:1; - unsigned _reserved:31; + unsigned _reserved:29; } pdo_firebird_db_handle; From e5a211cc27f649b64116bd632442264885912fa1 Mon Sep 17 00:00:00 2001 From: Simonov Denis Date: Fri, 18 Oct 2019 21:52:12 +0300 Subject: [PATCH 4/6] Create dialect_1.phpt test sql dialect 1 --- ext/pdo_firebird/tests/dialect_1.phpt | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 ext/pdo_firebird/tests/dialect_1.phpt diff --git a/ext/pdo_firebird/tests/dialect_1.phpt b/ext/pdo_firebird/tests/dialect_1.phpt new file mode 100644 index 0000000000000..fae85973c7c70 --- /dev/null +++ b/ext/pdo_firebird/tests/dialect_1.phpt @@ -0,0 +1,41 @@ +--TEST-- +PDO_Firebird: support 1 sql dialect +--SKIPIF-- + +--FILE-- +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); + $dbh->setAttribute(PDO::FB_ATTR_TIMESTAMP_FORMAT, '%Y-%m-%d %H:%M:%S'); + + $sql = + 'SELECT + 1 as N, + 2.0 as F, + cast(0.76 as numeric(15, 2)) as K, + cast(\'2019-06-12\' as date) as DT + FROM RDB$DATABASE'; + $query = $dbh->prepare($sql); + $query->execute(); + $row = $query->fetch(\PDO::FETCH_OBJ); + var_dump($row->N); + var_dump($row->F); + var_dump($row->K); + var_dump($row->DT); + + unset($query); + unset($dbh); + echo "done\n"; + +?> +--EXPECT-- +int(1) +string(8) "2.000000" +string(3) "0.76" +string(19) "2019-06-12 00:00:00" +done From e7fe5a140fb9f09fa879a4f173fa6da5fec51d9d Mon Sep 17 00:00:00 2001 From: Simonov Denis Date: Fri, 18 Oct 2019 22:24:13 +0300 Subject: [PATCH 5/6] Update dialect_1.phpt test 1 dialect with parameters --- ext/pdo_firebird/tests/dialect_1.phpt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ext/pdo_firebird/tests/dialect_1.phpt b/ext/pdo_firebird/tests/dialect_1.phpt index fae85973c7c70..89f9be1ca0977 100644 --- a/ext/pdo_firebird/tests/dialect_1.phpt +++ b/ext/pdo_firebird/tests/dialect_1.phpt @@ -18,7 +18,7 @@ if (strpos(getenv('PDO_FIREBIRD_TEST_DSN'), 'dialect=1')===false) { 1 as N, 2.0 as F, cast(0.76 as numeric(15, 2)) as K, - cast(\'2019-06-12\' as date) as DT + cast(\'2019-06-12\' as date) as DT FROM RDB$DATABASE'; $query = $dbh->prepare($sql); $query->execute(); @@ -28,6 +28,21 @@ if (strpos(getenv('PDO_FIREBIRD_TEST_DSN'), 'dialect=1')===false) { var_dump($row->K); var_dump($row->DT); + unset($query); + + $dbh->exec('RECREATE TABLE test_d1(K numeric(15, 2), DT date)'); + $sql='INSERT INTO test_d1(K, DT) values(?, ?)'; + $query = $dbh->prepare($sql); + $query->execute([0.76, '2019-06-12']); + unset($query); + + $sql='SELECT * FROM test_d1'; + $query = $dbh->prepare($sql); + $query->execute(); + $row = $query->fetch(\PDO::FETCH_OBJ); + var_dump($row->K); + var_dump($row->DT); + unset($query); unset($dbh); echo "done\n"; @@ -38,4 +53,6 @@ int(1) string(8) "2.000000" string(3) "0.76" string(19) "2019-06-12 00:00:00" +string(3) "0.76" +string(19) "2019-06-12 00:00:00" done From bc7965748cd71af3823de10919dd951ee7f50c88 Mon Sep 17 00:00:00 2001 From: Simonov Denis Date: Fri, 25 Oct 2019 19:38:01 +0300 Subject: [PATCH 6/6] Update dialect_1.phpt --- ext/pdo_firebird/tests/dialect_1.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/pdo_firebird/tests/dialect_1.phpt b/ext/pdo_firebird/tests/dialect_1.phpt index 89f9be1ca0977..e2f9ec4de171b 100644 --- a/ext/pdo_firebird/tests/dialect_1.phpt +++ b/ext/pdo_firebird/tests/dialect_1.phpt @@ -51,8 +51,8 @@ if (strpos(getenv('PDO_FIREBIRD_TEST_DSN'), 'dialect=1')===false) { --EXPECT-- int(1) string(8) "2.000000" -string(3) "0.76" +string(4) "0.76" string(19) "2019-06-12 00:00:00" -string(3) "0.76" +string(4) "0.76" string(19) "2019-06-12 00:00:00" done