Skip to content

Commit 6609966

Browse files
committed
Switch sqlite tests from "" to '' and re-enable for FreeBSD
FreeBSD builds without DQS (double-quote support). Transform tests so we can re-eanble them for FreeBSD. Add separate tests for DQS. Closes GH-21495
1 parent 32c1931 commit 6609966

28 files changed

+139
-71
lines changed

.github/actions/freebsd/action.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ runs:
4646
pkgconf \
4747
webp \
4848
libavif \
49-
`#sqlite3` \
49+
sqlite3 \
5050
curl \
5151
$OPCACHE_TLS_TESTS_DEPS
5252
@@ -57,9 +57,7 @@ runs:
5757
--enable-debug \
5858
--enable-option-checking=fatal \
5959
--enable-fpm \
60-
`#--with-pdo-sqlite` \
61-
--without-sqlite3 \
62-
--without-pdo-sqlite \
60+
--with-pdo-sqlite \
6361
--without-pear \
6462
--with-bz2 \
6563
--with-avif \

ext/pdo_sqlite/tests/bug38334.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ pdo_sqlite
77

88
$db = new PDO('sqlite::memory:');
99
$db->exec('CREATE TABLE test_38334 (i INTEGER , f DOUBLE, s VARCHAR(255))');
10-
$db->exec('INSERT INTO test_38334 VALUES (42, 46.7, "test")');
10+
$db->exec("INSERT INTO test_38334 VALUES (42, 46.7, 'test')");
1111
var_dump($db->query('SELECT * FROM test_38334')->fetch(PDO::FETCH_ASSOC));
1212

1313
// Check handling of integers larger than 32-bit.
14-
$db->exec('INSERT INTO test_38334 VALUES (10000000000, 0.0, "")');
14+
$db->exec("INSERT INTO test_38334 VALUES (10000000000, 0.0, '')");
1515
$i = $db->query('SELECT i FROM test_38334 WHERE f = 0.0')->fetchColumn(0);
1616
if (PHP_INT_SIZE >= 8) {
1717
var_dump($i === 10000000000);
@@ -20,8 +20,8 @@ if (PHP_INT_SIZE >= 8) {
2020
}
2121

2222
// Check storing of strings into integer/float columns.
23-
$db->exec('INSERT INTO test_38334 VALUES ("test", "test", "x")');
24-
var_dump($db->query('SELECT * FROM test_38334 WHERE s = "x"')->fetch(PDO::FETCH_ASSOC));
23+
$db->exec("INSERT INTO test_38334 VALUES ('test', 'test', 'x')");
24+
var_dump($db->query("SELECT * FROM test_38334 WHERE s = 'x'")->fetch(PDO::FETCH_ASSOC));
2525

2626
?>
2727
--EXPECT--

ext/pdo_sqlite/tests/bug_42589.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if(!in_array('ENABLE_COLUMN_METADATA', $options, true))
1515
$db = new PDO("sqlite::memory:");
1616

1717
$db->exec('CREATE TABLE test_42589 (field1 VARCHAR(10))');
18-
$db->exec('INSERT INTO test_42589 VALUES("test")');
18+
$db->exec("INSERT INTO test_42589 VALUES('test')");
1919

2020
$result = $db->query('SELECT * FROM test_42589 t1 LEFT JOIN test_42589 t2 ON t1.field1 = t2.field1');
2121
$meta1 = $result->getColumnMeta(0);

ext/pdo_sqlite/tests/pdo_sqlite_createaggregate.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $db = new PDO('sqlite::memory:');
99

1010
$db->query('CREATE TABLE test_pdo_sqlite_createaggregate (id INT AUTO INCREMENT, name TEXT)');
1111

12-
$db->query('INSERT INTO test_pdo_sqlite_createaggregate VALUES (NULL, "PHP"), (NULL, "PHP6")');
12+
$db->query("INSERT INTO test_pdo_sqlite_createaggregate VALUES (NULL, 'PHP'), (NULL, 'PHP6')");
1313

1414
$db->sqliteCreateAggregate('testing', function(&$a, $b) { $a .= $b; return $a; }, function(&$v) { return $v; });
1515

ext/pdo_sqlite/tests/pdo_sqlite_createcollation.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1010

1111
$db->query('CREATE TABLE test_pdo_sqlite_createcollation (id INT AUTO INCREMENT, name TEXT)');
1212

13-
$db->query('INSERT INTO test_pdo_sqlite_createcollation VALUES (NULL, "1"), (NULL, "2"), (NULL, "10")');
13+
$db->query("INSERT INTO test_pdo_sqlite_createcollation VALUES (NULL, '1'), (NULL, '2'), (NULL, '10')");
1414

1515
$db->sqliteCreateCollation('MYCOLLATE', function($a, $b) { return strnatcmp($a, $b); });
1616

ext/pdo_sqlite/tests/pdo_sqlite_createfunction.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $db = new PDO('sqlite::memory:');
99

1010
$db->query('CREATE TABLE test_pdo_sqlite_createfunction (id INT AUTO INCREMENT, name TEXT)');
1111

12-
$db->query('INSERT INTO test_pdo_sqlite_createfunction VALUES (NULL, "PHP"), (NULL, "PHP6")');
12+
$db->query("INSERT INTO test_pdo_sqlite_createfunction VALUES (NULL, 'PHP'), (NULL, 'PHP6')");
1313

1414

1515
$db->sqliteCreateFunction('testing', function($v) { return strtolower($v); });

ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $db = new PDO('sqlite::memory:');
1313

1414
$db->query('CREATE TABLE test_pdo_sqlite_createfunction_with_flags (id INT AUTO INCREMENT, name TEXT)');
1515

16-
$db->query('INSERT INTO test_pdo_sqlite_createfunction_with_flags VALUES (NULL, "PHP"), (NULL, "PHP6")');
16+
$db->query("INSERT INTO test_pdo_sqlite_createfunction_with_flags VALUES (NULL, 'PHP'), (NULL, 'PHP6')");
1717

1818

1919
$db->sqliteCreateFunction('testing', function($v) { return strtolower($v); }, 1, Pdo\Sqlite::DETERMINISTIC);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
PDO_sqlite: Testing DQS support
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--SKIPIF--
6+
<?php
7+
$db = new PDO('sqlite::memory:');
8+
try {
9+
$db->exec('SELECT "test"');
10+
} catch (\PDOException) {
11+
die('skip SQLite is lacking DQS');
12+
}
13+
?>
14+
--FILE--
15+
<?php
16+
$db = new PDO('sqlite::memory:');
17+
$db->exec('CREATE TABLE test (s1 VARCHAR(255), s2 VARCHAR(255))');
18+
$db->exec('INSERT INTO test VALUES (\'test\', "test")');
19+
var_dump($db->query('SELECT * FROM test')->fetch(PDO::FETCH_ASSOC));
20+
?>
21+
--EXPECT--
22+
array(2) {
23+
["s1"]=>
24+
string(4) "test"
25+
["s2"]=>
26+
string(4) "test"
27+
}

ext/pdo_sqlite/tests/pdo_sqlite_lastinsertid.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pdo_sqlite
77

88
$db = new PDO('sqlite::memory:');
99
$db->query('CREATE TABLE test_pdo_sqlite_lastinsertid (id INT AUTO INCREMENT, name TEXT)');
10-
$db->query('INSERT INTO test_pdo_sqlite_lastinsertid VALUES (NULL, "PHP"), (NULL, "PHP6")');
10+
$db->query("INSERT INTO test_pdo_sqlite_lastinsertid VALUES (NULL, 'PHP'), (NULL, 'PHP6')");
1111
var_dump($db->query('SELECT * FROM test_pdo_sqlite_lastinsertid'));
1212
var_dump($db->errorInfo());
1313
var_dump($db->lastInsertId());

ext/pdo_sqlite/tests/pdo_sqlite_parser.phpt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ foreach ($queries as $k => $query) {
3131
// One parameter
3232
$queries = [
3333
"SELECT * FROM {$table} WHERE '1' = ?",
34-
"SELECT * FROM {$table} WHERE \"?\" IN (?, \"?\")",
34+
"SELECT * FROM {$table} WHERE '?' IN (?, '?')",
3535
"SELECT * FROM {$table} WHERE `a``?` = ?",
36-
"SELECT * FROM {$table} WHERE \"a`?\" = ?",
3736
"SELECT * FROM {$table} WHERE [a`?] = ?",
3837
];
3938

@@ -43,6 +42,22 @@ foreach ($queries as $k => $query) {
4342
var_dump($stmt->fetch(PDO::FETCH_NUM) === [0 => 1]);
4443
}
4544

45+
// Check if DQS are enabled.
46+
$dqs = true;
47+
try {
48+
$db->exec('SELECT "test"');
49+
} catch (\PDOException) {
50+
$dqs = false;
51+
}
52+
53+
if ($dqs) {
54+
$stmt = $db->prepare("SELECT * FROM {$table} WHERE \"a`?\" = ?");
55+
$stmt->execute([1]);
56+
var_dump($stmt->fetch(PDO::FETCH_NUM) === [0 => 1]);
57+
} else {
58+
var_dump(true);
59+
}
60+
4661
?>
4762
--CLEAN--
4863
<?php

0 commit comments

Comments
 (0)