From 74a139974c363be66a8aaab42aafd0d632df39f7 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 3 Jan 2012 05:14:44 +0100 Subject: [PATCH] DibiTranslator: fixed usage of modifier ? --- dibi/libs/DibiTranslator.php | 2 +- examples/nette-debug-and-exceptions.php | 2 +- examples/nette-debug-and-variables.php | 2 +- examples/query-language-and-conditions.php | 8 ++++---- examples/query-language-basic-examples.php | 6 +++--- examples/using-fluent-syntax.php | 6 +++--- examples/using-logger.php | 6 +++--- examples/using-profiler.php | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/dibi/libs/DibiTranslator.php b/dibi/libs/DibiTranslator.php index 0979cb5b..1b9a2924 100644 --- a/dibi/libs/DibiTranslator.php +++ b/dibi/libs/DibiTranslator.php @@ -102,7 +102,7 @@ final class DibiTranslator extends DibiObject // simple string means SQL if (is_string($arg)) { // speed-up - is regexp required? - $toSkip = strcspn($arg, '`[\'":%'); + $toSkip = strcspn($arg, '`[\'":%?'); if (strlen($arg) === $toSkip) { // needn't be translated $sql[] = $arg; diff --git a/examples/nette-debug-and-exceptions.php b/examples/nette-debug-and-exceptions.php index 426c30b8..1252ef37 100644 --- a/examples/nette-debug-and-exceptions.php +++ b/examples/nette-debug-and-exceptions.php @@ -28,4 +28,4 @@ dibi::connect(array( // throws error because SQL is bad -dibi::query('SELECT FROM customers WHERE customer_id < %i', 38); +dibi::query('SELECT FROM customers WHERE customer_id < ?', 38); diff --git a/examples/nette-debug-and-variables.php b/examples/nette-debug-and-variables.php index 7d0276a5..fed24944 100644 --- a/examples/nette-debug-and-variables.php +++ b/examples/nette-debug-and-variables.php @@ -27,4 +27,4 @@ dibi::connect(array( )); -Debugger::barDump( dibi::fetchAll('SELECT * FROM customers WHERE customer_id < %i', 38), '[customers]' ); +Debugger::barDump( dibi::fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]' ); diff --git a/examples/query-language-and-conditions.php b/examples/query-language-and-conditions.php index 64bb92e5..660c4301 100644 --- a/examples/query-language-and-conditions.php +++ b/examples/query-language-and-conditions.php @@ -27,7 +27,7 @@ $name = $cond1 ? 'K%' : NULL; dibi::test(' SELECT * FROM customers - %if', isset($name), 'WHERE name LIKE %s', $name, '%end' + %if', isset($name), 'WHERE name LIKE ?', $name, '%end' ); // -> SELECT * FROM customers WHERE name LIKE 'K%' @@ -39,8 +39,8 @@ dibi::test(" SELECT * FROM people WHERE id > 0 - %if", ($foo > 0), "AND foo=%i", $foo, " - %else %if", ($bar > 0), "AND bar=%i", $bar, " + %if", ($foo > 0), "AND foo=?", $foo, " + %else %if", ($bar > 0), "AND bar=?", $bar, " "); // -> SELECT * FROM people WHERE id > 0 AND bar=2 @@ -51,7 +51,7 @@ dibi::test(' SELECT * FROM customers WHERE - %if', isset($name), 'name LIKE %s', $name, ' + %if', isset($name), 'name LIKE ?', $name, ' %if', $cond2, 'AND admin=1 %end %else 1 LIMIT 10 %end' ); diff --git a/examples/query-language-basic-examples.php b/examples/query-language-basic-examples.php index 1b02a19f..790a9d1c 100644 --- a/examples/query-language-basic-examples.php +++ b/examples/query-language-basic-examples.php @@ -23,7 +23,7 @@ $timestamp = mktime(0, 0, 0, 10, 13, 1997); dibi::test(' SELECT COUNT(*) as [count] FROM [comments] - WHERE [ip] LIKE %s', $ipMask, ' + WHERE [ip] LIKE ?', $ipMask, ' AND [date] > ', new DibiDateTime($timestamp) ); // -> SELECT COUNT(*) as [count] FROM [comments] WHERE [ip] LIKE '192.168.%' AND [date] > 876693600 @@ -59,7 +59,7 @@ dibi::test(" 'color' => 'blue', 'order' => 12, ), " - WHERE id=%i", 123); + WHERE id=?", 123); // -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123 @@ -69,7 +69,7 @@ $array = array(1, 2, 3); dibi::test(" SELECT * FROM people - WHERE id IN (%i)", $array + WHERE id IN (?)", $array ); // -> SELECT * FROM people WHERE id IN ( 1, 2, 3 ) diff --git a/examples/using-fluent-syntax.php b/examples/using-fluent-syntax.php index 3b5b2f47..592dbcf2 100644 --- a/examples/using-fluent-syntax.php +++ b/examples/using-fluent-syntax.php @@ -54,7 +54,7 @@ dibi::insert('products', $record) // UPDATE ... dibi::update('products', $record) - ->where('product_id = %d', $id) + ->where('product_id = ?', $id) ->test(); // -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10 @@ -62,7 +62,7 @@ dibi::update('products', $record) // DELETE ... dibi::delete('products') - ->where('product_id = %d', $id) + ->where('product_id = ?', $id) ->test(); // -> DELETE FROM [products] WHERE product_id = 10 @@ -71,7 +71,7 @@ dibi::delete('products') // custom commands dibi::command() ->update('products') - ->where('product_id = %d', $id) + ->where('product_id = ?', $id) ->set($record) ->test(); // -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10 diff --git a/examples/using-logger.php b/examples/using-logger.php index bb7d02f8..ed6df206 100644 --- a/examples/using-logger.php +++ b/examples/using-logger.php @@ -23,11 +23,11 @@ dibi::connect(array( try { - $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] = %i', 1); + $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] = ?', 1); - $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < %i', 5); + $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < ?', 5); - $res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < %i', 38); + $res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < ?', 38); } catch (DibiException $e) { echo '

', get_class($e), ': ', $e->getMessage(), '

'; diff --git a/examples/using-profiler.php b/examples/using-profiler.php index 3128980d..d4856672 100644 --- a/examples/using-profiler.php +++ b/examples/using-profiler.php @@ -19,7 +19,7 @@ dibi::connect(array( // execute some queries... for ($i=0; $i<20; $i++) { - $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < %i', $i); + $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < ?', $i); } // display output