1
0
mirror of https://github.com/dg/dibi.git synced 2025-07-10 00:56:24 +02:00

examples: removed unnecessary delimiters []

This commit is contained in:
David Grudl
2010-08-03 17:12:34 +02:00
parent beee4ee4b7
commit 3f594756e0
6 changed files with 36 additions and 36 deletions

View File

@ -16,9 +16,9 @@ dibi::connect(array(
$res = dibi::query(' $res = dibi::query('
SELECT * FROM [products] SELECT * FROM products
INNER JOIN [orders] USING ([product_id]) INNER JOIN orders USING (product_id)
INNER JOIN [customers] USING ([customer_id]) INNER JOIN customers USING (customer_id)
'); ');

View File

@ -34,19 +34,19 @@ Debug::dump($row); // Chair
// fetch a single value // fetch a single value
echo "<h2>fetchSingle()</h2>\n"; echo "<h2>fetchSingle()</h2>\n";
$value = dibi::fetchSingle('SELECT [title] FROM [products]'); $value = dibi::fetchSingle('SELECT title FROM products');
Debug::dump($value); // Chair Debug::dump($value); // Chair
// fetch complete result set // fetch complete result set
echo "<h2>fetchAll()</h2>\n"; echo "<h2>fetchAll()</h2>\n";
$all = dibi::fetchAll('SELECT * FROM [products]'); $all = dibi::fetchAll('SELECT * FROM products');
Debug::dump($all); Debug::dump($all);
// fetch complete result set like association array // fetch complete result set like association array
echo "<h2>fetchAssoc('title')</h2>\n"; echo "<h2>fetchAssoc('title')</h2>\n";
$res = dibi::query('SELECT * FROM [products]'); $res = dibi::query('SELECT * FROM products');
$assoc = $res->fetchAssoc('title'); // key $assoc = $res->fetchAssoc('title'); // key
Debug::dump($assoc); Debug::dump($assoc);
@ -80,9 +80,9 @@ foreach ($res->getIterator(2, 1) as $n => $row) {
// more complex association array // more complex association array
$res = dibi::query(' $res = dibi::query('
SELECT * SELECT *
FROM [products] FROM products
INNER JOIN [orders] USING ([product_id]) INNER JOIN orders USING (product_id)
INNER JOIN [customers] USING ([customer_id]) INNER JOIN customers USING (customer_id)
'); ');
echo "<h2>fetchAssoc('customers.name|products.title')</h2>\n"; echo "<h2>fetchAssoc('customers.name|products.title')</h2>\n";

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 < %i', 38);

View File

@ -27,4 +27,4 @@ dibi::connect(array(
)); ));
Debug::barDump( dibi::fetchAll('SELECT * FROM [customers] WHERE [customer_id] < %i', 38), '[customers]' ); Debug::barDump( dibi::fetchAll('SELECT * FROM customers WHERE customer_id < %i', 38), '[customers]' );

View File

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

View File

@ -32,12 +32,12 @@ dibi::test('
// dibi detects INSERT or REPLACE command // dibi detects INSERT or REPLACE command
dibi::test(' dibi::test('
REPLACE INTO [products]', array( REPLACE INTO products', array(
'title' => 'Super product', 'title' => 'Super product',
'price' => 318, 'price' => 318,
'active' => TRUE, 'active' => TRUE,
)); ));
// -> REPLACE INTO [products] ([title], [price], [active]) VALUES ('Super product', 318, 1) // -> REPLACE INTO products ([title], [price], [active]) VALUES ('Super product', 318, 1)
@ -48,19 +48,19 @@ $array = array(
'brand' => NULL, 'brand' => NULL,
'created' => new DateTime, 'created' => new DateTime,
); );
dibi::test("INSERT INTO [products]", $array, $array, $array); dibi::test("INSERT INTO products", $array, $array, $array);
// -> INSERT INTO [products] ([title], [price], [brand], [created]) VALUES ('Super Product', ...) , (...) , (...) // -> INSERT INTO products ([title], [price], [brand], [created]) VALUES ('Super Product', ...) , (...) , (...)
// dibi detects UPDATE command // dibi detects UPDATE command
dibi::test(" dibi::test("
UPDATE [colors] SET", array( UPDATE colors SET", array(
'color' => 'blue', 'color' => 'blue',
'order' => 12, 'order' => 12,
), " ), "
WHERE [id]=%i", 123); WHERE id=%i", 123);
// -> UPDATE [colors] SET [color]='blue', [order]=12 WHERE [id]=123 // -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123
@ -68,10 +68,10 @@ dibi::test("
$array = array(1, 2, 3); $array = array(1, 2, 3);
dibi::test(" dibi::test("
SELECT * SELECT *
FROM [people] FROM people
WHERE [id] IN (", $array, ") WHERE id IN (%i)", $array
"); );
// -> SELECT * FROM [people] WHERE [id] IN ( 1, 2, 3 ) // -> SELECT * FROM people WHERE id IN ( 1, 2, 3 )
@ -82,10 +82,10 @@ $order = array(
); );
dibi::test(" dibi::test("
SELECT * SELECT *
FROM [people] FROM people
ORDER BY %by", $order, " ORDER BY %by", $order, "
"); ");
// -> SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC // -> SELECT * FROM people ORDER BY [field1] ASC, [field2] DESC