Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

DibiTranslator: fixed usage of modifier ?

  • Loading branch information...
commit 74a139974c363be66a8aaab42aafd0d632df39f7 1 parent dbb72b7
@dg authored
View
2  dibi/libs/DibiTranslator.php
@@ -102,7 +102,7 @@ public function translate(array $args)
// 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;
View
2  examples/nette-debug-and-exceptions.php
@@ -28,4 +28,4 @@
// 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);
View
2  examples/nette-debug-and-variables.php
@@ -27,4 +27,4 @@
));
-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]' );
View
8 examples/query-language-and-conditions.php
@@ -27,7 +27,7 @@
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 @@
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 @@
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'
);
View
6 examples/query-language-basic-examples.php
@@ -23,7 +23,7 @@
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 @@
'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 @@
dibi::test("
SELECT *
FROM people
- WHERE id IN (%i)", $array
+ WHERE id IN (?)", $array
);
// -> SELECT * FROM people WHERE id IN ( 1, 2, 3 )
View
6 examples/using-fluent-syntax.php
@@ -54,7 +54,7 @@
// 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 @@
// 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 @@
// 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
View
6 examples/using-logger.php
@@ -23,11 +23,11 @@
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 '<p>', get_class($e), ': ', $e->getMessage(), '</p>';
View
2  examples/using-profiler.php
@@ -19,7 +19,7 @@
// 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
Please sign in to comment.
Something went wrong with that request. Please try again.