1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-03 20:57:36 +02:00

DibiTranslator: fixed usage of modifier ?

This commit is contained in:
David Grudl
2012-01-03 05:14:44 +01:00
parent dbb72b769b
commit 74a139974c
8 changed files with 17 additions and 17 deletions

View File

@@ -102,7 +102,7 @@ final class DibiTranslator extends DibiObject
// simple string means SQL // simple string means SQL
if (is_string($arg)) { if (is_string($arg)) {
// speed-up - is regexp required? // speed-up - is regexp required?
$toSkip = strcspn($arg, '`[\'":%'); $toSkip = strcspn($arg, '`[\'":%?');
if (strlen($arg) === $toSkip) { // needn't be translated if (strlen($arg) === $toSkip) { // needn't be translated
$sql[] = $arg; $sql[] = $arg;

View File

@@ -28,4 +28,4 @@ dibi::connect(array(
// throws error because SQL is bad // 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 File

@@ -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]' );

View File

@@ -27,7 +27,7 @@ $name = $cond1 ? 'K%' : NULL;
dibi::test(' dibi::test('
SELECT * SELECT *
FROM customers 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%' // -> SELECT * FROM customers WHERE name LIKE 'K%'
@@ -39,8 +39,8 @@ dibi::test("
SELECT * SELECT *
FROM people FROM people
WHERE id > 0 WHERE id > 0
%if", ($foo > 0), "AND foo=%i", $foo, " %if", ($foo > 0), "AND foo=?", $foo, "
%else %if", ($bar > 0), "AND bar=%i", $bar, " %else %if", ($bar > 0), "AND bar=?", $bar, "
"); ");
// -> SELECT * FROM people WHERE id > 0 AND bar=2 // -> SELECT * FROM people WHERE id > 0 AND bar=2
@@ -51,7 +51,7 @@ dibi::test('
SELECT * SELECT *
FROM customers FROM customers
WHERE WHERE
%if', isset($name), 'name LIKE %s', $name, ' %if', isset($name), 'name LIKE ?', $name, '
%if', $cond2, 'AND admin=1 %end %if', $cond2, 'AND admin=1 %end
%else 1 LIMIT 10 %end' %else 1 LIMIT 10 %end'
); );

View File

@@ -23,7 +23,7 @@ $timestamp = mktime(0, 0, 0, 10, 13, 1997);
dibi::test(' dibi::test('
SELECT COUNT(*) as [count] SELECT COUNT(*) as [count]
FROM [comments] FROM [comments]
WHERE [ip] LIKE %s', $ipMask, ' WHERE [ip] LIKE ?', $ipMask, '
AND [date] > ', new DibiDateTime($timestamp) AND [date] > ', new DibiDateTime($timestamp)
); );
// -> SELECT COUNT(*) as [count] FROM [comments] WHERE [ip] LIKE '192.168.%' AND [date] > 876693600 // -> SELECT COUNT(*) as [count] FROM [comments] WHERE [ip] LIKE '192.168.%' AND [date] > 876693600
@@ -59,7 +59,7 @@ dibi::test("
'color' => 'blue', 'color' => 'blue',
'order' => 12, 'order' => 12,
), " ), "
WHERE id=%i", 123); WHERE id=?", 123);
// -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123 // -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123
@@ -69,7 +69,7 @@ $array = array(1, 2, 3);
dibi::test(" dibi::test("
SELECT * SELECT *
FROM people FROM people
WHERE id IN (%i)", $array WHERE id IN (?)", $array
); );
// -> SELECT * FROM people WHERE id IN ( 1, 2, 3 ) // -> SELECT * FROM people WHERE id IN ( 1, 2, 3 )

View File

@@ -54,7 +54,7 @@ dibi::insert('products', $record)
// UPDATE ... // UPDATE ...
dibi::update('products', $record) dibi::update('products', $record)
->where('product_id = %d', $id) ->where('product_id = ?', $id)
->test(); ->test();
// -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10 // -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10
@@ -62,7 +62,7 @@ dibi::update('products', $record)
// DELETE ... // DELETE ...
dibi::delete('products') dibi::delete('products')
->where('product_id = %d', $id) ->where('product_id = ?', $id)
->test(); ->test();
// -> DELETE FROM [products] WHERE product_id = 10 // -> DELETE FROM [products] WHERE product_id = 10
@@ -71,7 +71,7 @@ dibi::delete('products')
// custom commands // custom commands
dibi::command() dibi::command()
->update('products') ->update('products')
->where('product_id = %d', $id) ->where('product_id = ?', $id)
->set($record) ->set($record)
->test(); ->test();
// -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10 // -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10

View File

@@ -23,11 +23,11 @@ dibi::connect(array(
try { 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) { } catch (DibiException $e) {
echo '<p>', get_class($e), ': ', $e->getMessage(), '</p>'; echo '<p>', get_class($e), ': ', $e->getMessage(), '</p>';

View File

@@ -19,7 +19,7 @@ dibi::connect(array(
// execute some queries... // execute some queries...
for ($i=0; $i<20; $i++) { 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 // display output