Skip to content

Commit 440bbcd

Browse files
committed
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: NEWS for bug #62593 Bug #62593 Updated to account for INOUT parameters Bug #62593 Updated test to verify bindParam doesn't change original value Bug #62593 Updated to always treat zval by value Bug #62593 Added test for change Bug #62593 Updated pdo_pgsql driver to convert boolean values to pg native format in emulation mode
2 parents 3342e72 + b3cd64a commit 440bbcd

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,20 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
362362
}
363363
break;
364364
}
365+
} else {
366+
#endif
367+
if (param->is_param) {
368+
/* We need to manually convert to a pg native boolean value */
369+
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL &&
370+
((param->param_type & PDO_PARAM_INPUT_OUTPUT) != PDO_PARAM_INPUT_OUTPUT)) {
371+
SEPARATE_ZVAL(&param->parameter);
372+
param->param_type = PDO_PARAM_STR;
373+
ZVAL_STRINGL(param->parameter, Z_BVAL_P(param->parameter) ? "t" : "f", 1, 1);
374+
}
375+
}
376+
#if HAVE_PQPREPARE
365377
}
366-
#endif
378+
#endif
367379
return 1;
368380
}
369381

ext/pdo_pgsql/tests/bug62593.phpt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
PDO PgSQL Bug #62593 (Emulate prepares behave strangely with PARAM_BOOL)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6+
require dirname(__FILE__) . '/config.inc';
7+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
14+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
15+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
16+
$errors = array();
17+
18+
$value = true;
19+
$query = $db->prepare('SELECT :foo IS FALSE as val_is_false');
20+
$query->bindValue(':foo', $value, PDO::PARAM_BOOL);
21+
$query->execute();
22+
$errors[] = $query->errorInfo();
23+
var_dump($value);
24+
25+
$query->bindValue(':foo', 0, PDO::PARAM_BOOL);
26+
$query->execute();
27+
$errors[] = $query->errorInfo();
28+
29+
// Verify bindParam maintains reference and only passes when execute is called
30+
$value = true;
31+
$query->bindParam(':foo', $value, PDO::PARAM_BOOL);
32+
$value = false;
33+
$query->execute();
34+
$errors[] = $query->errorInfo();
35+
var_dump($value);
36+
37+
$expect = 'No errors found';
38+
39+
foreach ($errors as $error)
40+
{
41+
if (strpos('Invalid text representation', $error[2]) !== false)
42+
{
43+
$expect = 'Invalid boolean found';
44+
}
45+
}
46+
echo $expect;
47+
?>
48+
--EXPECTF--
49+
bool(true)
50+
bool(false)
51+
No errors found

0 commit comments

Comments
 (0)