Skip to content

Support SQLite3 @name notation #3636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ static int register_bound_parameter_to_sqlite(struct php_sqlite3_bound_param *pa

/* We need a : prefix to resolve a name to a parameter number */
if (param->name) {
if (ZSTR_VAL(param->name)[0] != ':') {
if (ZSTR_VAL(param->name)[0] != ':' && ZSTR_VAL(param->name)[0] != '@') {
/* pre-increment for character + 1 for null */
zend_string *temp = zend_string_alloc(ZSTR_LEN(param->name) + 1, 0);
ZSTR_VAL(temp)[0] = ':';
Expand Down
51 changes: 51 additions & 0 deletions ext/sqlite3/tests/sqlite3_bound_value_at_name.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
SQLite3::prepare Bound Value test
--SKIPIF--
<?php require_once(__DIR__ . '/skipif.inc'); ?>
--FILE--
<?php

require_once(__DIR__ . '/new_db.inc');
define('TIMENOW', time());

echo "Creating Table\n";
var_dump($db->exec('CREATE TABLE test (time INTEGER, id STRING)'));

echo "INSERT into table\n";
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'a')"));
var_dump($db->exec("INSERT INTO test (time, id) VALUES (" . TIMENOW . ", 'b')"));

echo "SELECTING results\n";
$stmt = $db->prepare("SELECT * FROM test WHERE id = @id ORDER BY id ASC");
$foo = 'a';
echo "BINDING Value\n";
var_dump($stmt->bindValue('@id', $foo, SQLITE3_TEXT));
$results = $stmt->execute();
while ($result = $results->fetchArray(SQLITE3_NUM))
{
var_dump($result);
}
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
echo "Done\n";
?>
--EXPECTF--
Creating Table
bool(true)
INSERT into table
bool(true)
bool(true)
SELECTING results
BINDING Value
bool(true)
array(2) {
[0]=>
int(%d)
[1]=>
string(1) "a"
}
Closing database
bool(true)
Done