diff --git a/src/Database/SqlPreprocessor.php b/src/Database/SqlPreprocessor.php index dc37f4762..32632d39a 100644 --- a/src/Database/SqlPreprocessor.php +++ b/src/Database/SqlPreprocessor.php @@ -113,29 +113,16 @@ public function callback($m) private function formatValue($value, $mode = NULL) { if (!$mode || $mode === 'auto') { - if (is_string($value)) { - if (strlen($value) > 20) { - $this->remaining[] = $value; - return '?'; - - } else { - return $this->connection->quote($value); - } - - } elseif (is_int($value)) { - return (string) $value; - - } elseif (is_float($value)) { - return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.'); - - } elseif (is_bool($value)) { - return $this->driver->formatBool($value); + if (is_scalar($value) || is_resource($value)) { + $this->remaining[] = $value; + return '?'; } elseif ($value === NULL) { return 'NULL'; } elseif ($value instanceof Table\IRow) { - return $this->formatValue($value->getPrimary()); + $this->remaining[] = $value->getPrimary(); + return '?'; } elseif ($value instanceof SqlLiteral) { $prep = clone $this; @@ -150,10 +137,7 @@ private function formatValue($value, $mode = NULL) return $this->driver->formatDateInterval($value); } elseif (is_object($value) && method_exists($value, '__toString')) { - return $this->formatValue((string) $value); - - } elseif (is_resource($value)) { - $this->remaining[] = $value; + $this->remaining[] = (string) $value; return '?'; } diff --git a/tests/Database/Connection.preprocess.phpt b/tests/Database/Connection.preprocess.phpt index 7d912a53f..25f204573 100644 --- a/tests/Database/Connection.preprocess.phpt +++ b/tests/Database/Connection.preprocess.phpt @@ -12,4 +12,4 @@ require __DIR__ . '/connect.inc.php'; // create $connection Assert::same(['SELECT name FROM author', []], $connection->preprocess('SELECT name FROM author')); -Assert::same(["SELECT 'string'", []], $connection->preprocess('SELECT ?', 'string')); +Assert::same(["SELECT ?", ['string']], $connection->preprocess('SELECT ?', 'string')); diff --git a/tests/Database/Connection.query.phpt b/tests/Database/Connection.query.phpt index 2f138c229..2ef67ebd4 100644 --- a/tests/Database/Connection.query.phpt +++ b/tests/Database/Connection.query.phpt @@ -15,17 +15,20 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName test(function () use ($connection) { $res = $connection->query('SELECT id FROM author WHERE id = ?', 11); Assert::type(Nette\Database\ResultSet::class, $res); - Assert::same('SELECT id FROM author WHERE id = 11', $res->getQueryString()); + Assert::same('SELECT id FROM author WHERE id = ?', $res->getQueryString()); + Assert::same([11], $res->getParameters()); }); test(function () use ($connection) { $res = $connection->query('SELECT id FROM author WHERE id = ? OR id = ?', 11, 12); - Assert::same('SELECT id FROM author WHERE id = 11 OR id = 12', $res->getQueryString()); + Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $res->getQueryString()); + Assert::same([11, 12], $res->getParameters()); }); test(function () use ($connection) { $res = $connection->queryArgs('SELECT id FROM author WHERE id = ? OR id = ?', [11, 12]); - Assert::same('SELECT id FROM author WHERE id = 11 OR id = 12', $res->getQueryString()); + Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $res->getQueryString()); + Assert::same([11, 12], $res->getParameters()); }); diff --git a/tests/Database/Context.query.phpt b/tests/Database/Context.query.phpt index bf923f9b9..2cfa150ba 100644 --- a/tests/Database/Context.query.phpt +++ b/tests/Database/Context.query.phpt @@ -15,17 +15,20 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName test(function () use ($context) { $res = $context->query('SELECT id FROM author WHERE id = ?', 11); Assert::type(Nette\Database\ResultSet::class, $res); - Assert::same('SELECT id FROM author WHERE id = 11', $res->getQueryString()); + Assert::same('SELECT id FROM author WHERE id = ?', $res->getQueryString()); + Assert::same([11], $res->getParameters()); }); test(function () use ($context) { $res = $context->query('SELECT id FROM author WHERE id = ? OR id = ?', 11, 12); - Assert::same('SELECT id FROM author WHERE id = 11 OR id = 12', $res->getQueryString()); + Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $res->getQueryString()); + Assert::same([11, 12], $res->getParameters()); }); test(function () use ($context) { $res = $context->queryArgs('SELECT id FROM author WHERE id = ? OR id = ?', [11, 12]); - Assert::same('SELECT id FROM author WHERE id = 11 OR id = 12', $res->getQueryString()); + Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $res->getQueryString()); + Assert::same([11, 12], $res->getParameters()); }); diff --git a/tests/Database/SqlPreprocessor.phpt b/tests/Database/SqlPreprocessor.phpt index 14b8f158f..12f110d5c 100644 --- a/tests/Database/SqlPreprocessor.phpt +++ b/tests/Database/SqlPreprocessor.phpt @@ -15,44 +15,44 @@ $preprocessor = new Nette\Database\SqlPreprocessor($connection); test(function () use ($preprocessor) { // basic list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id = ?', 11]); - Assert::same('SELECT id FROM author WHERE id = 11', $sql); - Assert::same([], $params); + Assert::same('SELECT id FROM author WHERE id = ?', $sql); + Assert::same([11], $params); }); test(function () use ($preprocessor) { // arg without placeholder list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id =', 11]); - Assert::same('SELECT id FROM author WHERE id = 11', $sql); - Assert::same([], $params); + Assert::same('SELECT id FROM author WHERE id = ?', $sql); + Assert::same([11], $params); list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id =', '11']); - Assert::same("SELECT id FROM author WHERE id = '11'", $sql); - Assert::same([], $params); + Assert::same('SELECT id FROM author WHERE id = ?', $sql); + Assert::same(['11'], $params); }); test(function () use ($preprocessor) { list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id = ? OR id = ?', 11, 12]); - Assert::same('SELECT id FROM author WHERE id = 11 OR id = 12', $sql); - Assert::same([], $params); + Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $sql); + Assert::same([11, 12], $params); }); test(function () use ($preprocessor) { list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id = ?', 11, 'OR id = ?', 12]); - Assert::same('SELECT id FROM author WHERE id = 11 OR id = 12', $sql); - Assert::same([], $params); + Assert::same('SELECT id FROM author WHERE id = ? OR id = ?', $sql); + Assert::same([11, 12], $params); }); test(function () use ($preprocessor) { // IN list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id IN (?)', [10, 11]]); - Assert::same('SELECT id FROM author WHERE id IN (10, 11)', $sql); - Assert::same([], $params); + Assert::same('SELECT id FROM author WHERE id IN (?, ?)', $sql); + Assert::same([10, 11], $params); list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE (id, name) IN (?)', [[10, 'a'], [11, 'b']]]); - Assert::same("SELECT id FROM author WHERE (id, name) IN ((10, 'a'), (11, 'b'))", $sql); - Assert::same([], $params); + Assert::same('SELECT id FROM author WHERE (id, name) IN ((?, ?), (?, ?))', $sql); + Assert::same([10, 'a', 11, 'b'], $params); list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE', [ @@ -62,37 +62,37 @@ test(function () use ($preprocessor) { // IN 'd NOT IN' => [], ]]); - Assert::same(reformat('SELECT id FROM author WHERE ([a] IN (NULL, 1, 2, 3)) AND (1=0) AND ([c] NOT IN (NULL, 1, 2, 3))'), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT id FROM author WHERE ([a] IN (NULL, ?, ?, ?)) AND (1=0) AND ([c] NOT IN (NULL, ?, ?, ?))'), $sql); + Assert::same([1, 2, 3, 1, 2, 3], $params); }); test(function () use ($preprocessor) { // ?name list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE ?name = ? OR ?name = ?', 'id', 12, 'table.number', 23]); - Assert::same(reformat('SELECT id FROM author WHERE [id] = 12 OR [table].[number] = 23'), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT id FROM author WHERE [id] = ? OR [table].[number] = ?'), $sql); + Assert::same([12, 23], $params); }); test(function () use ($preprocessor) { // comments list($sql, $params) = $preprocessor->process(["SELECT id --?\nFROM author WHERE id = ?", 11]); - Assert::same("SELECT id --?\nFROM author WHERE id = 11", $sql); - Assert::same([], $params); + Assert::same("SELECT id --?\nFROM author WHERE id = ?", $sql); + Assert::same([11], $params); list($sql, $params) = $preprocessor->process(["SELECT id /* ? \n */FROM author WHERE id = ? --*/", 11]); - Assert::same("SELECT id /* ? \n */FROM author WHERE id = 11 --*/", $sql); - Assert::same([], $params); + Assert::same("SELECT id /* ? \n */FROM author WHERE id = ? --*/", $sql); + Assert::same([11], $params); }); test(function () use ($preprocessor) { // strings list($sql, $params) = $preprocessor->process(["SELECT id, '?' FROM author WHERE id = ?", 11]); - Assert::same("SELECT id, '?' FROM author WHERE id = 11", $sql); - Assert::same([], $params); + Assert::same("SELECT id, '?' FROM author WHERE id = ?", $sql); + Assert::same([11], $params); list($sql, $params) = $preprocessor->process(['SELECT id, "?" FROM author WHERE id = ?', 11]); - Assert::same('SELECT id, "?" FROM author WHERE id = 11', $sql); - Assert::same([], $params); + Assert::same('SELECT id, "?" FROM author WHERE id = ?', $sql); + Assert::same([11], $params); }); @@ -104,8 +104,8 @@ test(function () use ($preprocessor) { // where 'web' => [], ]]); - Assert::same(reformat("SELECT id FROM author WHERE ([id] IS NULL) AND ([x].[name] <> 'a') AND ([born] IN (NULL, 1, 2, 3)) AND (1=0)"), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([x].[name] <> ?) AND ([born] IN (NULL, ?, ?, ?)) AND (1=0)'), $sql); + Assert::same(['a', 1, 2, 3], $params); }); @@ -116,8 +116,8 @@ test(function () use ($preprocessor) { // tuples [5, 6], ]]); - Assert::same(reformat('SELECT * FROM book_tag WHERE (book_id, tag_id) IN ((1, 2), (3, 4), (5, 6))'), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT * FROM book_tag WHERE (book_id, tag_id) IN ((?, ?), (?, ?), (?, ?))'), $sql); + Assert::same([1, 2, 3, 4, 5, 6], $params); }); @@ -151,8 +151,8 @@ test(function () use ($preprocessor) { // mix of where & order 'name' => FALSE, ]]); - Assert::same(reformat("SELECT id FROM author WHERE ([id] = 1) AND ([web] = 'web') ORDER BY [name] DESC"), $sql); - Assert::same([], $params); + Assert::same(reformat("SELECT id FROM author WHERE ([id] = ?) AND ([web] = ?) ORDER BY [name] DESC"), $sql); + Assert::same([1, 'web'], $params); }); @@ -195,15 +195,15 @@ test(function () use ($preprocessor) { // unknown placeholder test(function () use ($preprocessor) { // SqlLiteral list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE id =', new SqlLiteral('? OR ?name = ?', [11, 'id', 12]) ]); - Assert::same(reformat('SELECT id FROM author WHERE id = 11 OR [id] = 12'), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT id FROM author WHERE id = ? OR [id] = ?'), $sql); + Assert::same([11, 12], $params); }); test(function () use ($preprocessor) { list($sql, $params) = $preprocessor->process(['SELECT id FROM author WHERE', new SqlLiteral('id=11'), 'OR', new SqlLiteral('id=?', [12])]); - Assert::same('SELECT id FROM author WHERE id=11 OR id=12', $sql); - Assert::same([], $params); + Assert::same('SELECT id FROM author WHERE id=11 OR id=?', $sql); + Assert::same([12], $params); }); @@ -214,8 +214,8 @@ test(function () use ($preprocessor) { // and 'web' => new SqlLiteral('NOW()'), ]]); - Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([born] IN (1, 2, 3+1)) AND ([web] = NOW())'), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([born] IN (?, ?, 3+1)) AND ([web] = NOW())'), $sql); + Assert::same([1, 2], $params); }); @@ -233,8 +233,8 @@ test(function () use ($preprocessor) { // ?and 'born' => [1, 2], ]]); - Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([born] IN (1, 2))'), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([born] IN (?, ?))'), $sql); + Assert::same([1, 2], $params); }); @@ -244,8 +244,8 @@ test(function () use ($preprocessor) { // ?or 'born' => [1, 2], ]]); - Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) OR ([born] IN (1, 2))'), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) OR ([born] IN (?, ?))'), $sql); + Assert::same([1, 2], $params); }); @@ -283,29 +283,32 @@ test(function () use ($preprocessor) { // insert ]); Assert::same(reformat([ - 'sqlite' => "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', 1320966000)", - 'sqlsrv' => "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11T00:00:00')", - "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11 00:00:00')", + 'sqlite' => 'INSERT INTO author ([name], [born]) VALUES (?, 1320966000)', + 'sqlsrv' => "INSERT INTO author ([name], [born]) VALUES (?, '2011-11-11T00:00:00')", + "INSERT INTO author ([name], [born]) VALUES (?, '2011-11-11 00:00:00')", ]), $sql); - Assert::same([], $params); + Assert::same(['Catelyn Stark'], $params); list($sql, $params) = $preprocessor->process(["\r\n INSERT INTO author", ['name' => 'Catelyn Stark'], ]); - Assert::same(reformat("\r\n INSERT INTO author ([name]) VALUES ('Catelyn Stark')"), $sql); + Assert::same(reformat("\r\n INSERT INTO author ([name]) VALUES (?)"), $sql); + Assert::same(['Catelyn Stark'], $params); list($sql, $params) = $preprocessor->process(['REPLACE author ?', ['name' => 'Catelyn Stark'], ]); - Assert::same(reformat("REPLACE author ([name]) VALUES ('Catelyn Stark')"), $sql); + Assert::same(reformat('REPLACE author ([name]) VALUES (?)'), $sql); + Assert::same(['Catelyn Stark'], $params); list($sql, $params) = $preprocessor->process(['/* comment */ INSERT INTO author', ['name' => 'Catelyn Stark'], ]); - Assert::same(reformat("/* comment */ INSERT INTO author [name]='Catelyn Stark'"), $sql); // autodetection not used + Assert::same(reformat('/* comment */ INSERT INTO author [name]=?'), $sql); // autodetection not used + Assert::same(['Catelyn Stark'], $params); }); @@ -314,8 +317,8 @@ test(function () use ($preprocessor) { // ?values ['name' => 'Catelyn Stark'], ]); - Assert::same(reformat("INSERT INTO update ([name]) VALUES ('Catelyn Stark')"), $sql); - Assert::same([], $params); + Assert::same(reformat('INSERT INTO update ([name]) VALUES (?)'), $sql); + Assert::same(['Catelyn Stark'], $params); }); @@ -326,11 +329,11 @@ test(function () use ($preprocessor) { // multi insert ]]); Assert::same(reformat([ - 'sqlite' => "INSERT INTO author ([name], [born]) SELECT 'Catelyn Stark', 1320966000 UNION ALL SELECT 'Sansa Stark', 1636585200", - 'sqlsrv' => "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11T00:00:00'), ('Sansa Stark', '2021-11-11T00:00:00')", - "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11 00:00:00'), ('Sansa Stark', '2021-11-11 00:00:00')", + 'sqlite' => 'INSERT INTO author ([name], [born]) SELECT ?, 1320966000 UNION ALL SELECT ?, 1636585200', + 'sqlsrv' => "INSERT INTO author ([name], [born]) VALUES (?, '2011-11-11T00:00:00'), (?, '2021-11-11T00:00:00')", + "INSERT INTO author ([name], [born]) VALUES (?, '2011-11-11 00:00:00'), (?, '2021-11-11 00:00:00')", ]), $sql); - Assert::same([], $params); + Assert::same(['Catelyn Stark', 'Sansa Stark'], $params); }); @@ -341,11 +344,12 @@ test(function () use ($preprocessor) { // multi insert ?values ]]); Assert::same(reformat([ - 'sqlite' => "INSERT INTO author ([name], [born]) SELECT 'Catelyn Stark', 1320966000 UNION ALL SELECT 'Sansa Stark', 1636585200", - 'sqlsrv' => "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11T00:00:00'), ('Sansa Stark', '2021-11-11T00:00:00')", - "INSERT INTO author ([name], [born]) VALUES ('Catelyn Stark', '2011-11-11 00:00:00'), ('Sansa Stark', '2021-11-11 00:00:00')", + 'sqlite' => 'INSERT INTO author ([name], [born]) SELECT ?, 1320966000 UNION ALL SELECT ?, 1636585200', + 'sqlsrv' => "INSERT INTO author ([name], [born]) VALUES (?, '2011-11-11T00:00:00'), (?, '2021-11-11T00:00:00')", + + "INSERT INTO author ([name], [born]) VALUES (?, '2011-11-11 00:00:00'), (?, '2021-11-11 00:00:00')", ]), $sql); - Assert::same([], $params); + Assert::same(['Catelyn Stark', 'Sansa Stark'], $params); }); @@ -356,26 +360,29 @@ test(function () use ($preprocessor) { // update new SqlLiteral('UPPER(?) = ?', ['John', 'DOE']), ]]); - Assert::same(reformat("UPDATE author SET [id]=12, [name]=UPPER('John Doe'), UPPER('John') = 'DOE'"), $sql); - Assert::same([], $params); + Assert::same(reformat('UPDATE author SET [id]=?, [name]=UPPER(?), UPPER(?) = ?'), $sql); + Assert::same([12, 'John Doe', 'John', 'DOE'], $params); list($sql, $params) = $preprocessor->process(["UPDATE author SET \n", ['id' => 12, 'name' => 'John Doe'], ]); - Assert::same(reformat("UPDATE author SET \n [id]=12, [name]='John Doe'"), $sql); + Assert::same(reformat("UPDATE author SET \n [id]=?, [name]=?"), $sql); + Assert::same([12, 'John Doe'], $params); list($sql, $params) = $preprocessor->process(['UPDATE author SET', ['id' => 12, 'name' => 'John Doe'], ]); - Assert::same(reformat("UPDATE author SET [id]=12, [name]='John Doe'"), $sql); + Assert::same(reformat('UPDATE author SET [id]=?, [name]=?'), $sql); + Assert::same([12, 'John Doe'], $params); list($sql, $params) = $preprocessor->process(['UPDATE author SET a=1,', ['id' => 12, 'name' => 'John Doe'], ]); - Assert::same(reformat("UPDATE author SET a=1, [id]=12, [name]='John Doe'"), $sql); + Assert::same(reformat('UPDATE author SET a=1, [id]=?, [name]=?'), $sql); + Assert::same([12, 'John Doe'], $params); }); @@ -384,8 +391,8 @@ test(function () use ($preprocessor) { // ?set ['id' => 12, 'name' => 'John Doe'], ]); - Assert::same(reformat("UPDATE insert SET [id]=12, [name]='John Doe'"), $sql); - Assert::same([], $params); + Assert::same(reformat('UPDATE insert SET [id]=?, [name]=?'), $sql); + Assert::same([12, 'John Doe'], $params); }); @@ -394,7 +401,8 @@ test(function () use ($preprocessor) { // update += ['id+=' => 1, 'id-=' => -1], ]); - Assert::same(reformat('UPDATE author SET [id]=[id] + 1, [id]=[id] - -1'), $sql); + Assert::same(reformat('UPDATE author SET [id]=[id] + ?, [id]=[id] - ?'), $sql); + Assert::same([1, -1], $params); }); @@ -404,8 +412,8 @@ test(function () use ($preprocessor) { // insert & update ['web' => 'http://nette.org', 'name' => 'Dave Lister'], ]); - Assert::same(reformat("INSERT INTO author ([id], [name]) VALUES (12, 'John Doe') ON DUPLICATE KEY UPDATE [web]='http://nette.org', [name]='Dave Lister'"), $sql); - Assert::same([], $params); + Assert::same(reformat('INSERT INTO author ([id], [name]) VALUES (?, ?) ON DUPLICATE KEY UPDATE [web]=?, [name]=?'), $sql); + Assert::same([12, 'John Doe', 'http://nette.org', 'Dave Lister'], $params); }); @@ -427,7 +435,8 @@ test(function () use ($preprocessor) { new SqlLiteral('max > ?', [10]), new SqlLiteral('min < ?', [20]), ]]); - Assert::same(reformat('SELECT id FROM author WHERE (max > 10) OR (min < 20)'), $sql); + Assert::same(reformat('SELECT id FROM author WHERE (max > ?) OR (min < ?)'), $sql); + Assert::same([10, 20], $params); }); @@ -436,8 +445,8 @@ test(function () use ($preprocessor) { new SqlLiteral('?and', [['a' => 1, 'b' => 2]]), new SqlLiteral('?and', [['c' => 3, 'd' => 4]]), ]])]); - Assert::same(reformat('SELECT id FROM author WHERE (([a] = 1) AND ([b] = 2)) OR (([c] = 3) AND ([d] = 4))'), $sql); - Assert::same([], $params); + Assert::same(reformat('SELECT id FROM author WHERE (([a] = ?) AND ([b] = ?)) OR (([c] = ?) AND ([d] = ?))'), $sql); + Assert::same([1, 2, 3, 4], $params); }); @@ -451,8 +460,8 @@ class ToString test(function () use ($preprocessor) { // object list($sql, $params) = $preprocessor->process(['SELECT ?', new ToString]); - Assert::same("SELECT 'hello'", $sql); - Assert::same([], $params); + Assert::same('SELECT ?', $sql); + Assert::same(['hello'], $params); }); diff --git a/tests/Database/Table/Table.cache.phpt b/tests/Database/Table/Table.cache.phpt index 03b2675b6..bbd20364c 100644 --- a/tests/Database/Table/Table.cache.phpt +++ b/tests/Database/Table/Table.cache.phpt @@ -208,12 +208,11 @@ test(function () use ($context) { // Test multiple use of same selection Assert::same([ reformat('SELECT * FROM [book]'), //First round - reformat('SELECT * FROM [book] WHERE ([author_id] = 11)'), + reformat('SELECT * FROM [book] WHERE ([author_id] = ?)'), reformat('SELECT [id] FROM [book]'), //Second round - reformat('SELECT [id], [title] FROM [book] WHERE ([author_id] = 11)'), - reformat('SELECT * FROM [book] WHERE ([author_id] = 11)'), //Missing translator_id + reformat('SELECT [id], [title] FROM [book] WHERE ([author_id] = ?)'), + reformat('SELECT * FROM [book] WHERE ([author_id] = ?)'), //Missing translator_id reformat('SELECT [id] FROM [book]'), //Third round - reformat('SELECT [id], [title], [translator_id] FROM [book] WHERE ([author_id] = 11)'), - + reformat('SELECT [id], [title], [translator_id] FROM [book] WHERE ([author_id] = ?)'), ], $sql); }); diff --git a/tests/Database/Table/Table.placeholders.phpt b/tests/Database/Table/Table.placeholders.phpt index c961ec909..203fdfc21 100644 --- a/tests/Database/Table/Table.placeholders.phpt +++ b/tests/Database/Table/Table.placeholders.phpt @@ -34,11 +34,9 @@ test(function () use ($context, $driverName) { $selection = $context ->table('book') - ->select('? AS col1', 'hi there!') ->select('? AS col2', $literal); $row = $selection->fetch(); - Assert::same('hi there!', $row['col1']); Assert::same((int) date('Y'), $row['col2']); });