Skip to content

Commit 13ffa88

Browse files
madorinweltling
authored andcommitted
Fixed bug #72931 PDO_FIREBIRD with Firebird 3.0 not work on returning statement
1 parent dd77116 commit 13ffa88

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

ext/pdo_firebird/firebird_statement.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,22 @@ static int firebird_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
9898
break;
9999
}
100100
S->cursor_open = 0;
101-
/* assume all params have been bound */
102101

103-
if (isc_dsql_execute(H->isc_status, &H->tr, &S->stmt, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
102+
/* allocate storage for the output data */
103+
if (S->out_sqlda.sqld) {
104+
unsigned int i;
105+
for (i = 0; i < S->out_sqlda.sqld; i++) {
106+
XSQLVAR *var = &S->out_sqlda.sqlvar[i];
107+
var->sqlind = (void*)ecalloc(1, var->sqllen + 2 * sizeof(short));
108+
var->sqldata = &((char*)var->sqlind)[sizeof(short)];
109+
}
110+
}
111+
112+
if (S->statement_type == isc_info_sql_stmt_exec_procedure) {
113+
if (isc_dsql_execute2(H->isc_status, &H->tr, &S->stmt, PDO_FB_SQLDA_VERSION, S->in_sqlda, &S->out_sqlda)) {
114+
break;
115+
}
116+
} else if (isc_dsql_execute(H->isc_status, &H->tr, &S->stmt, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
104117
break;
105118
}
106119

@@ -162,16 +175,18 @@ static int firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */
162175
strcpy(stmt->error_code, "HY000");
163176
H->last_app_error = "Cannot fetch from a closed cursor";
164177
} else if (!S->exhausted) {
178+
if (S->statement_type == isc_info_sql_stmt_exec_procedure) {
179+
stmt->row_count = 1;
180+
S->exhausted = 1;
181+
return 1;
182+
}
165183
if (isc_dsql_fetch(H->isc_status, &S->stmt, PDO_FB_SQLDA_VERSION, &S->out_sqlda)) {
166184
if (H->isc_status[0] && H->isc_status[1]) {
167185
RECORD_ERROR(stmt);
168186
}
169187
S->exhausted = 1;
170188
return 0;
171189
}
172-
if (S->statement_type == isc_info_sql_stmt_exec_procedure) {
173-
S->exhausted = 1;
174-
}
175190
stmt->row_count++;
176191
return 1;
177192
}
@@ -188,10 +203,6 @@ static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
188203
int colname_len;
189204
char *cp;
190205

191-
/* allocate storage for the column */
192-
var->sqlind = (void*)ecalloc(1, var->sqllen + 2*sizeof(short));
193-
var->sqldata = &((char*)var->sqlind)[sizeof(short)];
194-
195206
colname_len = (S->H->fetch_table_names && var->relname_length)
196207
? (var->aliasname_length + var->relname_length + 1)
197208
: (var->aliasname_length);

ext/pdo_firebird/tests/bug_72931.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
PDO_Firebird: Bug 72931 Insert returning fails on Firebird 3
3+
--SKIPIF--
4+
<?php if (!extension_loaded('interbase') || !extension_loaded('pdo_firebird')) die('skip'); ?>
5+
--FILE--
6+
<?php
7+
require 'testdb.inc';
8+
$C = new PDO('firebird:dbname='.$test_base, $user, $password) or die;
9+
$C->exec('create table tablea (id integer)');
10+
$S = $C->prepare('insert into tablea (id) values (1) returning id');
11+
$S->execute();
12+
$D = $S->fetch(PDO::FETCH_NUM);
13+
echo $D[0][0];
14+
unset($S);
15+
unset($C);
16+
?>
17+
--EXPECT--
18+
1

0 commit comments

Comments
 (0)