summaryrefslogtreecommitdiff
path: root/ext/pdo_firebird
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2016-12-07 21:07:14 +0100
committerAnatol Belski <ab@php.net>2016-12-07 21:07:14 +0100
commit67b7c5055cc869bba8555e5ce24317663ccd4a0e (patch)
tree3c1fcac1575ec7a05b57c820af7672b35a98fcd6 /ext/pdo_firebird
parent54f526be89c5d04edaabed23a4474df62755d99f (diff)
parent13ffa88e1f62c4407c55e1b82c299fc452211662 (diff)
downloadphp-git-67b7c5055cc869bba8555e5ce24317663ccd4a0e.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fixed bug #72931 PDO_FIREBIRD with Firebird 3.0 not work on returning statement
Diffstat (limited to 'ext/pdo_firebird')
-rw-r--r--ext/pdo_firebird/firebird_statement.c29
-rw-r--r--ext/pdo_firebird/tests/bug_72931.phpt18
2 files changed, 38 insertions, 9 deletions
diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c
index 994e92864c..f719ecc36d 100644
--- a/ext/pdo_firebird/firebird_statement.c
+++ b/ext/pdo_firebird/firebird_statement.c
@@ -98,9 +98,22 @@ static int firebird_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
break;
}
S->cursor_open = 0;
- /* assume all params have been bound */
- if (isc_dsql_execute(H->isc_status, &H->tr, &S->stmt, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
+ /* allocate storage for the output data */
+ if (S->out_sqlda.sqld) {
+ unsigned int i;
+ for (i = 0; i < S->out_sqlda.sqld; i++) {
+ XSQLVAR *var = &S->out_sqlda.sqlvar[i];
+ var->sqlind = (void*)ecalloc(1, var->sqllen + 2 * sizeof(short));
+ var->sqldata = &((char*)var->sqlind)[sizeof(short)];
+ }
+ }
+
+ if (S->statement_type == isc_info_sql_stmt_exec_procedure) {
+ if (isc_dsql_execute2(H->isc_status, &H->tr, &S->stmt, PDO_FB_SQLDA_VERSION, S->in_sqlda, &S->out_sqlda)) {
+ break;
+ }
+ } else if (isc_dsql_execute(H->isc_status, &H->tr, &S->stmt, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
break;
}
@@ -162,6 +175,11 @@ static int firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */
strcpy(stmt->error_code, "HY000");
H->last_app_error = "Cannot fetch from a closed cursor";
} else if (!S->exhausted) {
+ if (S->statement_type == isc_info_sql_stmt_exec_procedure) {
+ stmt->row_count = 1;
+ S->exhausted = 1;
+ return 1;
+ }
if (isc_dsql_fetch(H->isc_status, &S->stmt, PDO_FB_SQLDA_VERSION, &S->out_sqlda)) {
if (H->isc_status[0] && H->isc_status[1]) {
RECORD_ERROR(stmt);
@@ -169,9 +187,6 @@ static int firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */
S->exhausted = 1;
return 0;
}
- if (S->statement_type == isc_info_sql_stmt_exec_procedure) {
- S->exhausted = 1;
- }
stmt->row_count++;
return 1;
}
@@ -188,10 +203,6 @@ static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
int colname_len;
char *cp;
- /* allocate storage for the column */
- var->sqlind = (void*)ecalloc(1, var->sqllen + 2*sizeof(short));
- var->sqldata = &((char*)var->sqlind)[sizeof(short)];
-
colname_len = (S->H->fetch_table_names && var->relname_length)
? (var->aliasname_length + var->relname_length + 1)
: (var->aliasname_length);
diff --git a/ext/pdo_firebird/tests/bug_72931.phpt b/ext/pdo_firebird/tests/bug_72931.phpt
new file mode 100644
index 0000000000..10adf20ca7
--- /dev/null
+++ b/ext/pdo_firebird/tests/bug_72931.phpt
@@ -0,0 +1,18 @@
+--TEST--
+PDO_Firebird: Bug 72931 Insert returning fails on Firebird 3
+--SKIPIF--
+<?php if (!extension_loaded('interbase') || !extension_loaded('pdo_firebird')) die('skip'); ?>
+--FILE--
+<?php
+require 'testdb.inc';
+$C = new PDO('firebird:dbname='.$test_base, $user, $password) or die;
+$C->exec('create table tablea (id integer)');
+$S = $C->prepare('insert into tablea (id) values (1) returning id');
+$S->execute();
+$D = $S->fetch(PDO::FETCH_NUM);
+echo $D[0][0];
+unset($S);
+unset($C);
+?>
+--EXPECT--
+1