Skip to content

Commit 23a3bbb

Browse files
committed
Fix #44643: bound parameters ignore explicit type definitions
If `SQLDescribeParam()` fails for a parameter, we must not assume `SQL_LONGVARCHAR` for any param which is not `PDO_PARAM_LOB`. At least mapping `PDO_PARAM_INT` to `SQL_INTEGER` should be safe, and not introduce a BC break. Closes phpGH-6973.
1 parent ef3e0ee commit 23a3bbb

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ PHP NEWS
2424
- ODBC:
2525
. Fixed bug #80460 (ODBC doesn't account for SQL_NO_TOTAL indicator). (cmb)
2626

27+
- PDO_ODBC:
28+
. Fixed bug #44643 (bound parameters ignore explicit type definitions). (cmb)
29+
2730
- PDO_pgsql:
2831
. Reverted bug fix for #80892 (PDO::PARAM_INT is treated the same as
2932
PDO::PARAM_STR). (Matteo)

ext/pdo_odbc/odbc_stmt.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,16 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p
323323
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
324324
/* MS Access, for instance, doesn't support SQLDescribeParam,
325325
* so we need to guess */
326-
sqltype = PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB ?
327-
SQL_LONGVARBINARY :
328-
SQL_LONGVARCHAR;
326+
switch (PDO_PARAM_TYPE(param->param_type)) {
327+
case PDO_PARAM_INT:
328+
sqltype = SQL_INTEGER;
329+
break;
330+
case PDO_PARAM_LOB:
331+
sqltype = SQL_LONGVARBINARY;
332+
break;
333+
default:
334+
sqltype = SQL_LONGVARCHAR;
335+
}
329336
precision = 4000;
330337
scale = 5;
331338
nullable = 1;

ext/pdo_odbc/tests/bug44643.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #44643 (bound parameters ignore explicit type definitions)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_odbc')) die('skip pdo_odbc extension not available');
6+
require 'ext/pdo/tests/pdo_test.inc';
7+
PDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
require 'ext/pdo/tests/pdo_test.inc';
12+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
13+
$sql = "SELECT * FROM (SELECT 'test' = :id1) a WHERE a.test = :id2";
14+
$stmt = $db->prepare($sql);
15+
$id1 = 1;
16+
$stmt->bindParam(':id1', $id1, PDO::PARAM_INT);
17+
$id2 = 1;
18+
$stmt->bindParam(':id2', $id2, PDO::PARAM_INT);
19+
var_dump($stmt->execute());
20+
?>
21+
--EXPECT--
22+
bool(true)

0 commit comments

Comments
 (0)