1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-26 23:44:24 +02:00

coding style

This commit is contained in:
David Grudl
2020-10-28 16:38:16 +01:00
parent b27db4a9aa
commit 34a1665915
28 changed files with 216 additions and 154 deletions

View File

@@ -23,7 +23,9 @@ Assert::equal(1, $conn->getInsertId());
$conn->query(
'CREATE TRIGGER %n ON %n AFTER INSERT AS INSERT INTO %n DEFAULT VALUES',
'UpdAAB', 'aab', 'aaa'
'UpdAAB',
'aab',
'aaa'
);
$conn->query('INSERT INTO %n DEFAULT VALUES', 'aab');

View File

@@ -19,12 +19,17 @@ Assert::same(
SELECT *
FROM [customers]
/* WHERE ... LIKE ... */'),
$conn->translate('
$conn->translate(
'
SELECT *
FROM [customers]
%if', isset($name), 'WHERE [name] LIKE %s', 'xxx', '%end'
));
%if',
isset($name),
'WHERE [name] LIKE %s',
'xxx',
'%end'
)
);
// if & else & end (last end is optional)
@@ -32,11 +37,14 @@ Assert::same(
reformat('
SELECT *
FROM [customers] /* ... */'),
$conn->translate('
$conn->translate(
'
SELECT *
FROM %if', true, '[customers] %else [products]'
));
FROM %if',
true,
'[customers] %else [products]'
)
);
// if & else & (optional) end
@@ -48,14 +56,14 @@ WHERE [id] > 0
/* AND ...=...
*/ AND [bar]=1
'),
$conn->translate('
SELECT *
FROM [people]
WHERE [id] > 0
%if', false, 'AND [foo]=%i', 1, '
%else %if', true, 'AND [bar]=%i', 1, '
'));
')
);
// nested condition
@@ -76,24 +84,35 @@ WHERE
/* AND ...=1 */
/* 1 LIMIT 10 */",
]),
$conn->translate('
$conn->translate(
'
SELECT *
FROM [customers]
WHERE
%if', true, '[name] LIKE %s', 'xxx', '
%if', false, 'AND [admin]=1 %end
%if',
true,
'[name] LIKE %s',
'xxx',
'
%if',
false,
'AND [admin]=1 %end
%else 1 LIMIT 10 %end'
));
)
);
// limit & offset
Assert::same(
'SELECT * FROM foo /* (limit 3) (offset 5) */',
$conn->translate(
'SELECT * FROM foo',
'%if', false,
'%lmt', 3,
'%ofs', 5,
'%end'
));
'SELECT * FROM foo',
'%if',
false,
'%lmt',
3,
'%ofs',
5,
'%end'
)
);

View File

@@ -261,7 +261,7 @@ if ($config['system'] === 'postgre') {
'sqlite' => "SELECT * FROM products WHERE (title LIKE 'C%' ESCAPE '\\' AND title LIKE '%r' ESCAPE '\\') OR title LIKE '%a\n\\%\\_\\\\''\"%' ESCAPE '\\'",
'odbc' => "SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\n[%][_]\\''\"%'",
'sqlsrv' => "SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\n[%][_]\\''\"%'",
"SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\\n\\%\\_\\\\\\\\\'\"%'",
"SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\\n\\%\\_\\\\\\\\\\'\"%'",
]),
$conn->translate($args[0], $args[1], $args[2], $args[3])
);
@@ -279,7 +279,7 @@ Assert::match(
CONCAT(last_name, ', ', first_name) AS full_name
GROUP BY `user`
HAVING MAX(salary) > %i 123
INTO OUTFILE '/tmp/result\'.txt'
INTO OUTFILE '/tmp/result\\'.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\\"'
LINES TERMINATED BY '\\\\n'
",
@@ -344,7 +344,7 @@ WHERE (`test`.`a` LIKE '1995-03-01'
OR `b8` IN (RAND() `col1` > `col2` )
OR `b9` IN (RAND(), [col1] > [col2] )
OR `b10` IN ( )
AND `c` = 'embedded \' string'
AND `c` = 'embedded \\' string'
OR `d`=10
OR `e`=NULL
OR `true`= 1
@@ -437,7 +437,6 @@ WHERE ([test].[a] LIKE '1995-03-01'
OR [str_not_null]='hello'
LIMIT 10",
]),
$conn->translate('SELECT *
FROM [db.table]
WHERE ([test.a] LIKE %d', '1995-03-01', '
@@ -671,7 +670,6 @@ Assert::same(
'sqlsrv' => "UPDATE [colors] SET [color]=N'blue', [price]=-12.4, [spec]=-9E-005, [spec2]=1000, [spec3]=10000, [spec4]=10000 WHERE [price]=123.5",
"UPDATE [colors] SET [color]='blue', [price]=-12.4, [spec]=-9E-005, [spec2]=1000, [spec3]=10000, [spec4]=10000 WHERE [price]=123.5",
]),
$conn->translate('UPDATE [colors] SET', [
'color' => 'blue',
'price' => -12.4,