mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 13:17:58 +02:00
used PHP 5.4 syntax
This commit is contained in:
@@ -12,7 +12,7 @@ matrix:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
|
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
|
||||||
- php code-checker/src/code-checker.php
|
- php temp/code-checker/src/code-checker.php --short-arrays
|
||||||
|
|
||||||
after_failure:
|
after_failure:
|
||||||
# Print *.actual content
|
# Print *.actual content
|
||||||
@@ -21,7 +21,7 @@ after_failure:
|
|||||||
before_script:
|
before_script:
|
||||||
# Install Nette Tester & Code Checker
|
# Install Nette Tester & Code Checker
|
||||||
- travis_retry composer install --no-interaction
|
- travis_retry composer install --no-interaction
|
||||||
- travis_retry composer create-project nette/code-checker code-checker ~2.5 --no-interaction
|
- travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction
|
||||||
|
|
||||||
# Create databases.ini
|
# Create databases.ini
|
||||||
- cp ./tests/databases.sample.ini ./tests/databases.ini
|
- cp ./tests/databases.sample.ini ./tests/databases.ini
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
trigger_error('Dibi was moved to /src/loader.php', E_USER_WARNING);
|
trigger_error('Dibi was moved to /src/loader.php', E_USER_WARNING);
|
||||||
require dirname(__FILE__) . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
@@ -10,10 +10,10 @@ require __DIR__ . '/../src/loader.php';
|
|||||||
// connects to SQlite using dibi class
|
// connects to SQlite using dibi class
|
||||||
echo '<p>Connecting to Sqlite: ';
|
echo '<p>Connecting to Sqlite: ';
|
||||||
try {
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
@@ -24,10 +24,10 @@ echo "</p>\n";
|
|||||||
// connects to SQlite using DibiConnection object
|
// connects to SQlite using DibiConnection object
|
||||||
echo '<p>Connecting to Sqlite: ';
|
echo '<p>Connecting to Sqlite: ';
|
||||||
try {
|
try {
|
||||||
$connection = new DibiConnection(array(
|
$connection = new DibiConnection([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
@@ -49,17 +49,17 @@ echo "</p>\n";
|
|||||||
// connects to MySQLi using array
|
// connects to MySQLi using array
|
||||||
echo '<p>Connecting to MySQLi: ';
|
echo '<p>Connecting to MySQLi: ';
|
||||||
try {
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'mysqli',
|
'driver' => 'mysqli',
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'username' => 'root',
|
'username' => 'root',
|
||||||
'password' => 'xxx',
|
'password' => 'xxx',
|
||||||
'database' => 'dibi',
|
'database' => 'dibi',
|
||||||
'options' => array(
|
'options' => [
|
||||||
MYSQLI_OPT_CONNECT_TIMEOUT => 30,
|
MYSQLI_OPT_CONNECT_TIMEOUT => 30,
|
||||||
),
|
],
|
||||||
'flags' => MYSQLI_CLIENT_COMPRESS,
|
'flags' => MYSQLI_CLIENT_COMPRESS,
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
@@ -70,12 +70,12 @@ echo "</p>\n";
|
|||||||
// connects to ODBC
|
// connects to ODBC
|
||||||
echo '<p>Connecting to ODBC: ';
|
echo '<p>Connecting to ODBC: ';
|
||||||
try {
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'odbc',
|
'driver' => 'odbc',
|
||||||
'username' => 'root',
|
'username' => 'root',
|
||||||
'password' => '***',
|
'password' => '***',
|
||||||
'dsn' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq='.__DIR__.'/data/sample.mdb',
|
'dsn' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq='.__DIR__.'/data/sample.mdb',
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
@@ -86,11 +86,11 @@ echo "</p>\n";
|
|||||||
// connects to PostgreSql
|
// connects to PostgreSql
|
||||||
echo '<p>Connecting to PostgreSql: ';
|
echo '<p>Connecting to PostgreSql: ';
|
||||||
try {
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'postgre',
|
'driver' => 'postgre',
|
||||||
'string' => 'host=localhost port=5432 dbname=mary',
|
'string' => 'host=localhost port=5432 dbname=mary',
|
||||||
'persistent' => TRUE,
|
'persistent' => TRUE,
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
@@ -101,10 +101,10 @@ echo "</p>\n";
|
|||||||
// connects to PDO
|
// connects to PDO
|
||||||
echo '<p>Connecting to Sqlite via PDO: ';
|
echo '<p>Connecting to Sqlite via PDO: ';
|
||||||
try {
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'pdo',
|
'driver' => 'pdo',
|
||||||
'dsn' => 'sqlite::memory:',
|
'dsn' => 'sqlite::memory:',
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
@@ -115,12 +115,12 @@ echo "</p>\n";
|
|||||||
// connects to MS SQL
|
// connects to MS SQL
|
||||||
echo '<p>Connecting to MS SQL: ';
|
echo '<p>Connecting to MS SQL: ';
|
||||||
try {
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'mssql',
|
'driver' => 'mssql',
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'username' => 'root',
|
'username' => 'root',
|
||||||
'password' => 'xxx',
|
'password' => 'xxx',
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
@@ -131,13 +131,13 @@ echo "</p>\n";
|
|||||||
// connects to MS SQL 2005
|
// connects to MS SQL 2005
|
||||||
echo '<p>Connecting to MS SQL 2005: ';
|
echo '<p>Connecting to MS SQL 2005: ';
|
||||||
try {
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'mssql2005',
|
'driver' => 'mssql2005',
|
||||||
'host' => '(local)',
|
'host' => '(local)',
|
||||||
'username' => 'Administrator',
|
'username' => 'Administrator',
|
||||||
'password' => 'xxx',
|
'password' => 'xxx',
|
||||||
'database' => 'main',
|
'database' => 'main',
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
@@ -148,12 +148,12 @@ echo "</p>\n";
|
|||||||
// connects to Oracle
|
// connects to Oracle
|
||||||
echo '<p>Connecting to Oracle: ';
|
echo '<p>Connecting to Oracle: ';
|
||||||
try {
|
try {
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'oracle',
|
'driver' => 'oracle',
|
||||||
'username' => 'root',
|
'username' => 'root',
|
||||||
'password' => 'xxx',
|
'password' => 'xxx',
|
||||||
'database' => 'db',
|
'database' => 'db',
|
||||||
));
|
]);
|
||||||
echo 'OK';
|
echo 'OK';
|
||||||
} catch (DibiException $e) {
|
} catch (DibiException $e) {
|
||||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||||
|
@@ -7,10 +7,10 @@
|
|||||||
require __DIR__ . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// retrieve database reflection
|
// retrieve database reflection
|
||||||
|
@@ -7,10 +7,10 @@
|
|||||||
require __DIR__ . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
$res = dibi::query('
|
$res = dibi::query('
|
||||||
|
@@ -11,10 +11,10 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
|
|||||||
Tracy\Debugger::enable();
|
Tracy\Debugger::enable();
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -7,10 +7,10 @@
|
|||||||
require __DIR__ . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
$count = dibi::loadFile('compress.zlib://data/sample.dump.sql.gz');
|
$count = dibi::loadFile('compress.zlib://data/sample.dump.sql.gz');
|
||||||
|
@@ -7,10 +7,10 @@
|
|||||||
require __DIR__ . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// some variables
|
// some variables
|
||||||
@@ -55,7 +55,7 @@ dibi::test('
|
|||||||
|
|
||||||
|
|
||||||
// IF()
|
// IF()
|
||||||
dibi::test('UPDATE products SET', array(
|
dibi::test('UPDATE products SET', [
|
||||||
'price' => array('IF(price_fixed, price, ?)', 123),
|
'price' => ['IF(price_fixed, price, ?)', 123],
|
||||||
));
|
]);
|
||||||
// -> SELECT * FROM customers WHERE LIMIT 10
|
// -> SELECT * FROM customers WHERE LIMIT 10
|
||||||
|
@@ -9,10 +9,10 @@ require __DIR__ . '/../src/loader.php';
|
|||||||
date_default_timezone_set('Europe/Prague');
|
date_default_timezone_set('Europe/Prague');
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// SELECT
|
// SELECT
|
||||||
@@ -30,37 +30,37 @@ 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', [
|
||||||
'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)
|
||||||
|
|
||||||
|
|
||||||
// multiple INSERT command
|
// multiple INSERT command
|
||||||
$array = array(
|
$array = [
|
||||||
'title' => 'Super Product',
|
'title' => 'Super Product',
|
||||||
'price' => 12,
|
'price' => 12,
|
||||||
'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', [
|
||||||
'color' => 'blue',
|
'color' => 'blue',
|
||||||
'order' => 12,
|
'order' => 12,
|
||||||
), '
|
], '
|
||||||
WHERE id=?', 123);
|
WHERE id=?', 123);
|
||||||
// -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123
|
// -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123
|
||||||
|
|
||||||
|
|
||||||
// modifier applied to array
|
// modifier applied to array
|
||||||
$array = array(1, 2, 3);
|
$array = [1, 2, 3];
|
||||||
dibi::test('
|
dibi::test('
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM people
|
FROM people
|
||||||
@@ -70,10 +70,10 @@ dibi::test('
|
|||||||
|
|
||||||
|
|
||||||
// modifier %by for ORDER BY
|
// modifier %by for ORDER BY
|
||||||
$order = array(
|
$order = [
|
||||||
'field1' => 'asc',
|
'field1' => 'asc',
|
||||||
'field2' => 'desc',
|
'field2' => 'desc',
|
||||||
);
|
];
|
||||||
dibi::test('
|
dibi::test('
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM people
|
FROM people
|
||||||
|
@@ -13,10 +13,10 @@ Tracy\Debugger::enable();
|
|||||||
date_default_timezone_set('Europe/Prague');
|
date_default_timezone_set('Europe/Prague');
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// using manual hints
|
// using manual hints
|
||||||
|
@@ -15,13 +15,13 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
|
|||||||
Tracy\Debugger::enable();
|
Tracy\Debugger::enable();
|
||||||
|
|
||||||
|
|
||||||
$connection = dibi::connect(array(
|
$connection = dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
'profiler' => array(
|
'profiler' => [
|
||||||
'run' => TRUE,
|
'run' => TRUE,
|
||||||
),
|
],
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// add panel to debug bar
|
// add panel to debug bar
|
||||||
|
@@ -17,13 +17,13 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
|
|||||||
Tracy\Debugger::enable();
|
Tracy\Debugger::enable();
|
||||||
|
|
||||||
|
|
||||||
$connection = dibi::connect(array(
|
$connection = dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
'profiler' => array(
|
'profiler' => [
|
||||||
'run' => TRUE,
|
'run' => TRUE,
|
||||||
),
|
],
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// add panel to debug bar
|
// add panel to debug bar
|
||||||
|
@@ -10,20 +10,20 @@ date_default_timezone_set('Europe/Prague');
|
|||||||
|
|
||||||
|
|
||||||
// CHANGE TO REAL PARAMETERS!
|
// CHANGE TO REAL PARAMETERS!
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
'formatDate' => "'Y-m-d'",
|
'formatDate' => "'Y-m-d'",
|
||||||
'formatDateTime' => "'Y-m-d H-i-s'",
|
'formatDateTime' => "'Y-m-d H-i-s'",
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// generate and dump SQL
|
// generate and dump SQL
|
||||||
dibi::test('
|
dibi::test('
|
||||||
INSERT INTO [mytable]', array(
|
INSERT INTO [mytable]', [
|
||||||
'id' => 123,
|
'id' => 123,
|
||||||
'date' => new DateTime('12.3.2007'),
|
'date' => new DateTime('12.3.2007'),
|
||||||
'stamp' => new DateTime('23.1.2007 10:23'),
|
'stamp' => new DateTime('23.1.2007 10:23'),
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
// -> INSERT INTO [mytable] ([id], [date], [stamp]) VALUES (123, '2007-03-12', '2007-01-23 10-23-00')
|
// -> INSERT INTO [mytable] ([id], [date], [stamp]) VALUES (123, '2007-03-12', '2007-01-23 10-23-00')
|
||||||
|
@@ -11,10 +11,10 @@ if (@!include __DIR__ . '/../vendor/autoload.php') {
|
|||||||
Tracy\Debugger::enable();
|
Tracy\Debugger::enable();
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// using the "prototype" to add custom method to class DibiResult
|
// using the "prototype" to add custom method to class DibiResult
|
||||||
|
@@ -9,18 +9,18 @@ require __DIR__ . '/../src/loader.php';
|
|||||||
date_default_timezone_set('Europe/Prague');
|
date_default_timezone_set('Europe/Prague');
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
$id = 10;
|
$id = 10;
|
||||||
$record = array(
|
$record = [
|
||||||
'title' => 'Super product',
|
'title' => 'Super product',
|
||||||
'price' => 318,
|
'price' => 318,
|
||||||
'active' => TRUE,
|
'active' => TRUE,
|
||||||
);
|
];
|
||||||
|
|
||||||
// SELECT ...
|
// SELECT ...
|
||||||
dibi::select('product_id')->as('id')
|
dibi::select('product_id')->as('id')
|
||||||
|
@@ -7,10 +7,10 @@
|
|||||||
require __DIR__ . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// no limit
|
// no limit
|
||||||
|
@@ -9,15 +9,15 @@ require __DIR__ . '/../src/loader.php';
|
|||||||
date_default_timezone_set('Europe/Prague');
|
date_default_timezone_set('Europe/Prague');
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
// enable query logging to this file
|
// enable query logging to this file
|
||||||
'profiler' => array(
|
'profiler' => [
|
||||||
'run' => TRUE,
|
'run' => TRUE,
|
||||||
'file' => 'data/log.sql',
|
'file' => 'data/log.sql',
|
||||||
),
|
],
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@@ -9,13 +9,13 @@
|
|||||||
require __DIR__ . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
'profiler' => array(
|
'profiler' => [
|
||||||
'run' => TRUE,
|
'run' => TRUE,
|
||||||
),
|
],
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// execute some queries...
|
// execute some queries...
|
||||||
|
@@ -7,10 +7,10 @@
|
|||||||
require __DIR__ . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
// create new substitution :blog: ==> wp_
|
// create new substitution :blog: ==> wp_
|
||||||
|
@@ -7,10 +7,10 @@
|
|||||||
require __DIR__ . '/../src/loader.php';
|
require __DIR__ . '/../src/loader.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'sqlite3',
|
'driver' => 'sqlite3',
|
||||||
'database' => 'data/sample.s3db',
|
'database' => 'data/sample.s3db',
|
||||||
));
|
]);
|
||||||
|
|
||||||
|
|
||||||
echo "<h2>Before</h2>\n";
|
echo "<h2>Before</h2>\n";
|
||||||
@@ -19,9 +19,9 @@ dibi::query('SELECT * FROM [products]')->dump();
|
|||||||
|
|
||||||
|
|
||||||
dibi::begin();
|
dibi::begin();
|
||||||
dibi::query('INSERT INTO [products]', array(
|
dibi::query('INSERT INTO [products]', [
|
||||||
'title' => 'Test product',
|
'title' => 'Test product',
|
||||||
));
|
]);
|
||||||
|
|
||||||
echo "<h2>After INSERT</h2>\n";
|
echo "<h2>After INSERT</h2>\n";
|
||||||
dibi::query('SELECT * FROM [products]')->dump();
|
dibi::query('SELECT * FROM [products]')->dump();
|
||||||
|
20
readme.md
20
readme.md
@@ -30,12 +30,12 @@ Connect to database:
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
// connect to database (static way)
|
// connect to database (static way)
|
||||||
dibi::connect(array(
|
dibi::connect([
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'host' => 'localhost',
|
'host' => 'localhost',
|
||||||
'username' => 'root',
|
'username' => 'root',
|
||||||
'password' => '***',
|
'password' => '***',
|
||||||
));
|
]);
|
||||||
|
|
||||||
// or object way; in all other examples use $connection-> instead of dibi::
|
// or object way; in all other examples use $connection-> instead of dibi::
|
||||||
$connection = new DibiConnection($options);
|
$connection = new DibiConnection($options);
|
||||||
@@ -46,19 +46,19 @@ SELECT, INSERT, UPDATE
|
|||||||
```php
|
```php
|
||||||
dibi::query('SELECT * FROM users WHERE id = ?', $id);
|
dibi::query('SELECT * FROM users WHERE id = ?', $id);
|
||||||
|
|
||||||
$arr = array(
|
$arr = [
|
||||||
'name' => 'John',
|
'name' => 'John',
|
||||||
'is_admin' => TRUE,
|
'is_admin' => TRUE,
|
||||||
);
|
];
|
||||||
dibi::query('INSERT INTO users', $arr);
|
dibi::query('INSERT INTO users', $arr);
|
||||||
// INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1)
|
// INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1)
|
||||||
|
|
||||||
dibi::query('UPDATE users SET', $arr, 'WHERE `id`=?', $x);
|
dibi::query('UPDATE users SET', $arr, 'WHERE `id`=?', $x);
|
||||||
// UPDATE users SET `name`='John', `is_admin`=1 WHERE `id` = 123
|
// UPDATE users SET `name`='John', `is_admin`=1 WHERE `id` = 123
|
||||||
|
|
||||||
dibi::query('UPDATE users SET', array(
|
dibi::query('UPDATE users SET', [
|
||||||
'title' => array('SHA1(?)', 'tajneheslo'),
|
'title' => array('SHA1(?)', 'tajneheslo'),
|
||||||
));
|
]);
|
||||||
// UPDATE users SET 'title' = SHA1('tajneheslo')
|
// UPDATE users SET 'title' = SHA1('tajneheslo')
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -81,10 +81,10 @@ foreach ($result as $n => $row) {
|
|||||||
Modifiers for arrays:
|
Modifiers for arrays:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
dibi::query('SELECT * FROM users WHERE %and', array(
|
dibi::query('SELECT * FROM users WHERE %and', [
|
||||||
array('number > ?', 10),
|
array('number > ?', 10),
|
||||||
array('number < ?', 100),
|
array('number < ?', 100),
|
||||||
));
|
]);
|
||||||
// SELECT * FROM users WHERE (number > 10) AND (number < 100)
|
// SELECT * FROM users WHERE (number > 10) AND (number < 100)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -116,9 +116,9 @@ dibi::query("SELECT * FROM table WHERE name LIKE %like~", $query);
|
|||||||
DateTime:
|
DateTime:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
dibi::query('UPDATE users SET', array(
|
dibi::query('UPDATE users SET', [
|
||||||
'time' => new DateTime,
|
'time' => new DateTime,
|
||||||
));
|
]);
|
||||||
// UPDATE users SET ('2008-01-01 01:08:10')
|
// UPDATE users SET ('2008-01-01 01:08:10')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -34,16 +34,16 @@ class DibiNette21Extension extends Nette\DI\CompilerExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
$connection = $container->addDefinition($this->prefix('connection'))
|
$connection = $container->addDefinition($this->prefix('connection'))
|
||||||
->setClass('DibiConnection', array($config))
|
->setClass('DibiConnection', [$config])
|
||||||
->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE);
|
->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE);
|
||||||
|
|
||||||
if ($useProfiler) {
|
if ($useProfiler) {
|
||||||
$panel = $container->addDefinition($this->prefix('panel'))
|
$panel = $container->addDefinition($this->prefix('panel'))
|
||||||
->setClass('DibiNettePanel')
|
->setClass('DibiNettePanel')
|
||||||
->addSetup('Nette\Diagnostics\Debugger::getBar()->addPanel(?)', array('@self'))
|
->addSetup('Nette\Diagnostics\Debugger::getBar()->addPanel(?)', ['@self'])
|
||||||
->addSetup('Nette\Diagnostics\Debugger::getBlueScreen()->addPanel(?)', array('DibiNettePanel::renderException'));
|
->addSetup('Nette\Diagnostics\Debugger::getBlueScreen()->addPanel(?)', ['DibiNettePanel::renderException']);
|
||||||
|
|
||||||
$connection->addSetup('$service->onEvent[] = ?', array(array($panel, 'logEvent')));
|
$connection->addSetup('$service->onEvent[] = ?', [[$panel, 'logEvent']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,13 +39,13 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
$connection = $container->addDefinition($this->prefix('connection'))
|
$connection = $container->addDefinition($this->prefix('connection'))
|
||||||
->setClass('DibiConnection', array($config))
|
->setClass('DibiConnection', [$config])
|
||||||
->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE);
|
->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE);
|
||||||
|
|
||||||
if ($useProfiler) {
|
if ($useProfiler) {
|
||||||
$panel = $container->addDefinition($this->prefix('panel'))
|
$panel = $container->addDefinition($this->prefix('panel'))
|
||||||
->setClass('Dibi\Bridges\Tracy\Panel');
|
->setClass('Dibi\Bridges\Tracy\Panel');
|
||||||
$connection->addSetup(array($panel, 'register'), array($connection));
|
$connection->addSetup([$panel, 'register'], [$connection]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel
|
|||||||
public $filter;
|
public $filter;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $events = array();
|
private $events = [];
|
||||||
|
|
||||||
|
|
||||||
public function __construct($explain = TRUE, $filter = NULL)
|
public function __construct($explain = TRUE, $filter = NULL)
|
||||||
@@ -38,8 +38,8 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel
|
|||||||
public function register(DibiConnection $connection)
|
public function register(DibiConnection $connection)
|
||||||
{
|
{
|
||||||
Debugger::getBar()->addPanel($this);
|
Debugger::getBar()->addPanel($this);
|
||||||
Debugger::getBlueScreen()->addPanel(array(__CLASS__, 'renderException'));
|
Debugger::getBlueScreen()->addPanel([__CLASS__, 'renderException']);
|
||||||
$connection->onEvent[] = array($this, 'logEvent');
|
$connection->onEvent[] = [$this, 'logEvent'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,10 +63,10 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel
|
|||||||
public static function renderException($e)
|
public static function renderException($e)
|
||||||
{
|
{
|
||||||
if ($e instanceof DibiException && $e->getSql()) {
|
if ($e instanceof DibiException && $e->getSql()) {
|
||||||
return array(
|
return [
|
||||||
'tab' => 'SQL',
|
'tab' => 'SQL',
|
||||||
'panel' => dibi::dump($e->getSql(), TRUE),
|
'panel' => dibi::dump($e->getSql(), TRUE),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel
|
|||||||
$explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS()
|
$explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS()
|
||||||
if ($this->explain && $event->type === DibiEvent::SELECT) {
|
if ($this->explain && $event->type === DibiEvent::SELECT) {
|
||||||
try {
|
try {
|
||||||
$backup = array($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime);
|
$backup = [$event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime];
|
||||||
$event->connection->onEvent = NULL;
|
$event->connection->onEvent = NULL;
|
||||||
$cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
|
$cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
|
||||||
$explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE);
|
$explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE);
|
||||||
@@ -126,7 +126,7 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel
|
|||||||
if (!class_exists($helpers)) {
|
if (!class_exists($helpers)) {
|
||||||
$helpers = class_exists('NDebugHelpers') ? 'NDebugHelpers' : 'DebugHelpers';
|
$helpers = class_exists('NDebugHelpers') ? 'NDebugHelpers' : 'DebugHelpers';
|
||||||
}
|
}
|
||||||
$s .= call_user_func(array($helpers, 'editorLink'), $event->source[0], $event->source[1])->class('nette-DibiProfiler-source');
|
$s .= call_user_func([$helpers, 'editorLink'], $event->source[0], $event->source[1])->class('nette-DibiProfiler-source');
|
||||||
}
|
}
|
||||||
|
|
||||||
$s .= "</td><td>{$event->count}</td><td>{$h($event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'))}</td></tr>";
|
$s .= "</td><td>{$event->count}</td><td>{$h($event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'))}</td></tr>";
|
||||||
|
@@ -27,7 +27,7 @@ class Panel extends \DibiObject implements Tracy\IBarPanel
|
|||||||
public $filter;
|
public $filter;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $events = array();
|
private $events = [];
|
||||||
|
|
||||||
|
|
||||||
public function __construct($explain = TRUE, $filter = NULL)
|
public function __construct($explain = TRUE, $filter = NULL)
|
||||||
@@ -40,8 +40,8 @@ class Panel extends \DibiObject implements Tracy\IBarPanel
|
|||||||
public function register(\DibiConnection $connection)
|
public function register(\DibiConnection $connection)
|
||||||
{
|
{
|
||||||
Tracy\Debugger::getBar()->addPanel($this);
|
Tracy\Debugger::getBar()->addPanel($this);
|
||||||
Tracy\Debugger::getBlueScreen()->addPanel(array(__CLASS__, 'renderException'));
|
Tracy\Debugger::getBlueScreen()->addPanel([__CLASS__, 'renderException']);
|
||||||
$connection->onEvent[] = array($this, 'logEvent');
|
$connection->onEvent[] = [$this, 'logEvent'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,10 +65,10 @@ class Panel extends \DibiObject implements Tracy\IBarPanel
|
|||||||
public static function renderException($e)
|
public static function renderException($e)
|
||||||
{
|
{
|
||||||
if ($e instanceof \DibiException && $e->getSql()) {
|
if ($e instanceof \DibiException && $e->getSql()) {
|
||||||
return array(
|
return [
|
||||||
'tab' => 'SQL',
|
'tab' => 'SQL',
|
||||||
'panel' => dibi::dump($e->getSql(), TRUE),
|
'panel' => dibi::dump($e->getSql(), TRUE),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ class Panel extends \DibiObject implements Tracy\IBarPanel
|
|||||||
$explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS()
|
$explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS()
|
||||||
if ($this->explain && $event->type === \DibiEvent::SELECT) {
|
if ($this->explain && $event->type === \DibiEvent::SELECT) {
|
||||||
try {
|
try {
|
||||||
$backup = array($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime);
|
$backup = [$event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime];
|
||||||
$event->connection->onEvent = NULL;
|
$event->connection->onEvent = NULL;
|
||||||
$cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
|
$cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
|
||||||
$explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE);
|
$explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE);
|
||||||
|
@@ -55,7 +55,7 @@ class DibiConnection extends DibiObject
|
|||||||
parse_str($config, $config);
|
parse_str($config, $config);
|
||||||
|
|
||||||
} elseif ($config instanceof Traversable) {
|
} elseif ($config instanceof Traversable) {
|
||||||
$tmp = array();
|
$tmp = [];
|
||||||
foreach ($config as $key => $val) {
|
foreach ($config as $key => $val) {
|
||||||
$tmp[$key] = $val instanceof Traversable ? iterator_to_array($val) : $val;
|
$tmp[$key] = $val instanceof Traversable ? iterator_to_array($val) : $val;
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ class DibiConnection extends DibiObject
|
|||||||
$config['driver'] = dibi::$defaultDriver;
|
$config['driver'] = dibi::$defaultDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = $tmp = preg_replace(array('#\W#', '#sql#'), array('_', 'Sql'), ucfirst(strtolower($config['driver'])));
|
$class = $tmp = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($config['driver'])));
|
||||||
$class = "Dibi{$class}Driver";
|
$class = "Dibi{$class}Driver";
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
throw new DibiException("Unable to create instance of dibi driver '$class'.");
|
throw new DibiException("Unable to create instance of dibi driver '$class'.");
|
||||||
@@ -89,17 +89,17 @@ class DibiConnection extends DibiObject
|
|||||||
// profiler
|
// profiler
|
||||||
$profilerCfg = & $config['profiler'];
|
$profilerCfg = & $config['profiler'];
|
||||||
if (is_scalar($profilerCfg)) {
|
if (is_scalar($profilerCfg)) {
|
||||||
$profilerCfg = array('run' => (bool) $profilerCfg);
|
$profilerCfg = ['run' => (bool) $profilerCfg];
|
||||||
}
|
}
|
||||||
if (!empty($profilerCfg['run'])) {
|
if (!empty($profilerCfg['run'])) {
|
||||||
$filter = isset($profilerCfg['filter']) ? $profilerCfg['filter'] : DibiEvent::QUERY;
|
$filter = isset($profilerCfg['filter']) ? $profilerCfg['filter'] : DibiEvent::QUERY;
|
||||||
|
|
||||||
if (isset($profilerCfg['file'])) {
|
if (isset($profilerCfg['file'])) {
|
||||||
$this->onEvent[] = array(new DibiFileLogger($profilerCfg['file'], $filter), 'logEvent');
|
$this->onEvent[] = [new DibiFileLogger($profilerCfg['file'], $filter), 'logEvent'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DibiFirePhpLogger::isAvailable()) {
|
if (DibiFirePhpLogger::isAvailable()) {
|
||||||
$this->onEvent[] = array(new DibiFirePhpLogger($filter), 'logEvent');
|
$this->onEvent[] = [new DibiFirePhpLogger($filter), 'logEvent'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!interface_exists('Tracy\IBarPanel') && interface_exists('Nette\Diagnostics\IBarPanel') && class_exists('DibiNettePanel')) {
|
if (!interface_exists('Tracy\IBarPanel') && interface_exists('Nette\Diagnostics\IBarPanel') && class_exists('DibiNettePanel')) {
|
||||||
@@ -108,7 +108,7 @@ class DibiConnection extends DibiObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->substitutes = new DibiHashMap(create_function('$expr', 'return ":$expr:";'));
|
$this->substitutes = new DibiHashMap(function ($expr) { return ":$expr:"; });
|
||||||
if (!empty($config['substitutes'])) {
|
if (!empty($config['substitutes'])) {
|
||||||
foreach ($config['substitutes'] as $key => $value) {
|
foreach ($config['substitutes'] as $key => $value) {
|
||||||
$this->substitutes->$key = $value;
|
$this->substitutes->$key = $value;
|
||||||
@@ -542,16 +542,9 @@ class DibiConnection extends DibiObject
|
|||||||
*/
|
*/
|
||||||
public function substitute($value)
|
public function substitute($value)
|
||||||
{
|
{
|
||||||
return strpos($value, ':') === FALSE ? $value : preg_replace_callback('#:([^:\s]*):#', array($this, 'subCb'), $value);
|
return strpos($value, ':') === FALSE
|
||||||
}
|
? $value
|
||||||
|
: preg_replace_callback('#:([^:\s]*):#', function ($m) { $this->substitutes->{$m[1]}; }, $value);
|
||||||
|
|
||||||
/**
|
|
||||||
* Substitution callback.
|
|
||||||
*/
|
|
||||||
private function subCb($m)
|
|
||||||
{
|
|
||||||
return $this->substitutes->{$m[1]};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -29,13 +29,13 @@ class DibiDataSource extends DibiObject implements IDataSource
|
|||||||
private $totalCount;
|
private $totalCount;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $cols = array();
|
private $cols = [];
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $sorting = array();
|
private $sorting = [];
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $conds = array();
|
private $conds = [];
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $offset;
|
private $offset;
|
||||||
@@ -259,8 +259,8 @@ class DibiDataSource extends DibiObject implements IDataSource
|
|||||||
return $this->connection->translate('
|
return $this->connection->translate('
|
||||||
SELECT %n', (empty($this->cols) ? '*' : $this->cols), '
|
SELECT %n', (empty($this->cols) ? '*' : $this->cols), '
|
||||||
FROM %SQL', $this->sql, '
|
FROM %SQL', $this->sql, '
|
||||||
%ex', $this->conds ? array('WHERE %and', $this->conds) : NULL, '
|
%ex', $this->conds ? ['WHERE %and', $this->conds] : NULL, '
|
||||||
%ex', $this->sorting ? array('ORDER BY %by', $this->sorting) : NULL, '
|
%ex', $this->sorting ? ['ORDER BY %by', $this->sorting] : NULL, '
|
||||||
%ofs %lmt', $this->offset, $this->limit
|
%ofs %lmt', $this->offset, $this->limit
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@@ -65,13 +65,13 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// default values
|
// default values
|
||||||
$config += array(
|
$config += [
|
||||||
'username' => ini_get('ibase.default_password'),
|
'username' => ini_get('ibase.default_password'),
|
||||||
'password' => ini_get('ibase.default_user'),
|
'password' => ini_get('ibase.default_user'),
|
||||||
'database' => ini_get('ibase.default_db'),
|
'database' => ini_get('ibase.default_db'),
|
||||||
'charset' => ini_get('ibase.default_charset'),
|
'charset' => ini_get('ibase.default_charset'),
|
||||||
'buffers' => 0,
|
'buffers' => 0,
|
||||||
);
|
];
|
||||||
|
|
||||||
DibiDriverException::tryError();
|
DibiDriverException::tryError();
|
||||||
if (empty($config['persistent'])) {
|
if (empty($config['persistent'])) {
|
||||||
@@ -432,15 +432,15 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$count = ibase_num_fields($this->resultSet);
|
$count = ibase_num_fields($this->resultSet);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$row = (array) ibase_field_info($this->resultSet, $i);
|
$row = (array) ibase_field_info($this->resultSet, $i);
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
'fullname' => $row['name'],
|
'fullname' => $row['name'],
|
||||||
'table' => $row['relation'],
|
'table' => $row['relation'],
|
||||||
'nativetype' => $row['type'],
|
'nativetype' => $row['type'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -461,12 +461,12 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
FROM RDB\$RELATIONS
|
FROM RDB\$RELATIONS
|
||||||
WHERE RDB\$SYSTEM_FLAG = 0;"
|
WHERE RDB\$SYSTEM_FLAG = 0;"
|
||||||
);
|
);
|
||||||
$tables = array();
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$tables[] = array(
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => $row[1] === 'TRUE',
|
'view' => $row[1] === 'TRUE',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $tables;
|
return $tables;
|
||||||
}
|
}
|
||||||
@@ -510,10 +510,10 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
ORDER BY r.RDB\$FIELD_POSITION;"
|
ORDER BY r.RDB\$FIELD_POSITION;"
|
||||||
|
|
||||||
);
|
);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$key = $row['FIELD_NAME'];
|
$key = $row['FIELD_NAME'];
|
||||||
$columns[$key] = array(
|
$columns[$key] = [
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => trim($row['FIELD_TYPE']),
|
'nativetype' => trim($row['FIELD_TYPE']),
|
||||||
@@ -521,7 +521,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
'nullable' => $row['NULLABLE'] === 'TRUE',
|
'nullable' => $row['NULLABLE'] === 'TRUE',
|
||||||
'default' => $row['DEFAULT_VALUE'],
|
'default' => $row['DEFAULT_VALUE'],
|
||||||
'autoincrement' => FALSE,
|
'autoincrement' => FALSE,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -548,7 +548,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
WHERE UPPER(i.RDB\$RELATION_NAME) = '$table'
|
WHERE UPPER(i.RDB\$RELATION_NAME) = '$table'
|
||||||
ORDER BY s.RDB\$FIELD_POSITION"
|
ORDER BY s.RDB\$FIELD_POSITION"
|
||||||
);
|
);
|
||||||
$indexes = array();
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$key = $row['INDEX_NAME'];
|
$key = $row['INDEX_NAME'];
|
||||||
$indexes[$key]['name'] = $key;
|
$indexes[$key]['name'] = $key;
|
||||||
@@ -578,14 +578,14 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
AND r.RDB\$CONSTRAINT_TYPE = 'FOREIGN KEY'
|
AND r.RDB\$CONSTRAINT_TYPE = 'FOREIGN KEY'
|
||||||
ORDER BY s.RDB\$FIELD_POSITION"
|
ORDER BY s.RDB\$FIELD_POSITION"
|
||||||
);
|
);
|
||||||
$keys = array();
|
$keys = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$key = $row['INDEX_NAME'];
|
$key = $row['INDEX_NAME'];
|
||||||
$keys[$key] = array(
|
$keys[$key] = [
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'column' => $row['FIELD_NAME'],
|
'column' => $row['FIELD_NAME'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $keys;
|
return $keys;
|
||||||
}
|
}
|
||||||
@@ -605,7 +605,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
AND RDB\$UNIQUE_FLAG IS NULL
|
AND RDB\$UNIQUE_FLAG IS NULL
|
||||||
AND RDB\$FOREIGN_KEY IS NULL;"
|
AND RDB\$FOREIGN_KEY IS NULL;"
|
||||||
);
|
);
|
||||||
$indices = array();
|
$indices = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$indices[] = $row[0];
|
$indices[] = $row[0];
|
||||||
}
|
}
|
||||||
@@ -629,7 +629,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
OR RDB\$FOREIGN_KEY IS NOT NULL
|
OR RDB\$FOREIGN_KEY IS NOT NULL
|
||||||
);"
|
);"
|
||||||
);
|
);
|
||||||
$constraints = array();
|
$constraints = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$constraints[] = $row[0];
|
$constraints[] = $row[0];
|
||||||
}
|
}
|
||||||
@@ -672,15 +672,15 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
WHERE RDB\$SYSTEM_FLAG = 0"
|
WHERE RDB\$SYSTEM_FLAG = 0"
|
||||||
. ($table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table');")
|
. ($table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table');")
|
||||||
);
|
);
|
||||||
$triggers = array();
|
$triggers = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$triggers[$row['TRIGGER_NAME']] = array(
|
$triggers[$row['TRIGGER_NAME']] = [
|
||||||
'name' => $row['TRIGGER_NAME'],
|
'name' => $row['TRIGGER_NAME'],
|
||||||
'table' => $row['TABLE_NAME'],
|
'table' => $row['TABLE_NAME'],
|
||||||
'type' => trim($row['TRIGGER_TYPE']),
|
'type' => trim($row['TRIGGER_TYPE']),
|
||||||
'event' => trim($row['TRIGGER_EVENT']),
|
'event' => trim($row['TRIGGER_EVENT']),
|
||||||
'enabled' => trim($row['TRIGGER_ENABLED']) === 'TRUE',
|
'enabled' => trim($row['TRIGGER_ENABLED']) === 'TRUE',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $triggers;
|
return $triggers;
|
||||||
}
|
}
|
||||||
@@ -700,7 +700,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
$q .= $table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table')";
|
$q .= $table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table')";
|
||||||
|
|
||||||
$res = $this->query($q);
|
$res = $this->query($q);
|
||||||
$triggers = array();
|
$triggers = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$triggers[] = $row[0];
|
$triggers[] = $row[0];
|
||||||
}
|
}
|
||||||
@@ -747,7 +747,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
LEFT JOIN RDB\$FIELDS f ON f.RDB\$FIELD_NAME = p.RDB\$FIELD_SOURCE
|
LEFT JOIN RDB\$FIELDS f ON f.RDB\$FIELD_NAME = p.RDB\$FIELD_SOURCE
|
||||||
ORDER BY p.RDB\$PARAMETER_TYPE, p.RDB\$PARAMETER_NUMBER;"
|
ORDER BY p.RDB\$PARAMETER_TYPE, p.RDB\$PARAMETER_NUMBER;"
|
||||||
);
|
);
|
||||||
$procedures = array();
|
$procedures = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$key = $row['PROCEDURE_NAME'];
|
$key = $row['PROCEDURE_NAME'];
|
||||||
$io = trim($row['PARAMETER_TYPE']);
|
$io = trim($row['PARAMETER_TYPE']);
|
||||||
@@ -771,7 +771,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
SELECT TRIM(RDB\$PROCEDURE_NAME)
|
SELECT TRIM(RDB\$PROCEDURE_NAME)
|
||||||
FROM RDB\$PROCEDURES;"
|
FROM RDB\$PROCEDURES;"
|
||||||
);
|
);
|
||||||
$procedures = array();
|
$procedures = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$procedures[] = $row[0];
|
$procedures[] = $row[0];
|
||||||
}
|
}
|
||||||
@@ -790,7 +790,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
FROM RDB\$GENERATORS
|
FROM RDB\$GENERATORS
|
||||||
WHERE RDB\$SYSTEM_FLAG = 0;"
|
WHERE RDB\$SYSTEM_FLAG = 0;"
|
||||||
);
|
);
|
||||||
$generators = array();
|
$generators = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$generators[] = $row[0];
|
$generators[] = $row[0];
|
||||||
}
|
}
|
||||||
@@ -809,7 +809,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
|||||||
FROM RDB\$FUNCTIONS
|
FROM RDB\$FUNCTIONS
|
||||||
WHERE RDB\$SYSTEM_FLAG = 0;"
|
WHERE RDB\$SYSTEM_FLAG = 0;"
|
||||||
);
|
);
|
||||||
$functions = array();
|
$functions = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$functions[] = $row[0];
|
$functions[] = $row[0];
|
||||||
}
|
}
|
||||||
|
@@ -264,7 +264,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
|
|||||||
*/
|
*/
|
||||||
public function escapeLike($value, $pos)
|
public function escapeLike($value, $pos)
|
||||||
{
|
{
|
||||||
$value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]'));
|
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
|
||||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,13 +366,13 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
|
|||||||
*/
|
*/
|
||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$columns = array();
|
$columns = [];
|
||||||
foreach ((array) sqlsrv_field_metadata($this->resultSet) as $fieldMetadata) {
|
foreach ((array) sqlsrv_field_metadata($this->resultSet) as $fieldMetadata) {
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $fieldMetadata['Name'],
|
'name' => $fieldMetadata['Name'],
|
||||||
'fullname' => $fieldMetadata['Name'],
|
'fullname' => $fieldMetadata['Name'],
|
||||||
'nativetype' => $fieldMetadata['Type'],
|
'nativetype' => $fieldMetadata['Type'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
@@ -31,12 +31,12 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector
|
|||||||
public function getTables()
|
public function getTables()
|
||||||
{
|
{
|
||||||
$res = $this->driver->query('SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES');
|
$res = $this->driver->query('SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES');
|
||||||
$tables = array();
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$tables[] = array(
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $tables;
|
return $tables;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector
|
|||||||
WHERE t.name = {$this->driver->escapeText($table)}
|
WHERE t.name = {$this->driver->escapeText($table)}
|
||||||
");
|
");
|
||||||
|
|
||||||
$autoIncrements = array();
|
$autoIncrements = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$autoIncrements[$row['COLUMN_NAME']] = (bool) $row['AUTO_INCREMENT'];
|
$autoIncrements[$row['COLUMN_NAME']] = (bool) $row['AUTO_INCREMENT'];
|
||||||
}
|
}
|
||||||
@@ -76,9 +76,9 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector
|
|||||||
) As Z
|
) As Z
|
||||||
WHERE C.TABLE_NAME = {$this->driver->escapeText($table)}
|
WHERE C.TABLE_NAME = {$this->driver->escapeText($table)}
|
||||||
");
|
");
|
||||||
$columns = array();
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['COLUMN_NAME'],
|
'name' => $row['COLUMN_NAME'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => strtoupper($row['DATA_TYPE']),
|
'nativetype' => strtoupper($row['DATA_TYPE']),
|
||||||
@@ -88,7 +88,7 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector
|
|||||||
'default' => $row['COLUMN_DEFAULT'],
|
'default' => $row['COLUMN_DEFAULT'],
|
||||||
'autoincrement' => $autoIncrements[$row['COLUMN_NAME']],
|
'autoincrement' => $autoIncrements[$row['COLUMN_NAME']],
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -102,18 +102,18 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector
|
|||||||
public function getIndexes($table)
|
public function getIndexes($table)
|
||||||
{
|
{
|
||||||
$keyUsagesRes = $this->driver->query("SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = {$this->driver->escapeText($table)}");
|
$keyUsagesRes = $this->driver->query("SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = {$this->driver->escapeText($table)}");
|
||||||
$keyUsages = array();
|
$keyUsages = [];
|
||||||
while ($row = $keyUsagesRes->fetch(TRUE)) {
|
while ($row = $keyUsagesRes->fetch(TRUE)) {
|
||||||
$keyUsages[$row['CONSTRAINT_NAME']][(int) $row['ORDINAL_POSITION'] - 1] = $row['COLUMN_NAME'];
|
$keyUsages[$row['CONSTRAINT_NAME']][(int) $row['ORDINAL_POSITION'] - 1] = $row['COLUMN_NAME'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $this->driver->query("SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = {$this->driver->escapeText($table)}");
|
$res = $this->driver->query("SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = {$this->driver->escapeText($table)}");
|
||||||
$indexes = array();
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$indexes[$row['CONSTRAINT_NAME']]['name'] = $row['CONSTRAINT_NAME'];
|
$indexes[$row['CONSTRAINT_NAME']]['name'] = $row['CONSTRAINT_NAME'];
|
||||||
$indexes[$row['CONSTRAINT_NAME']]['unique'] = $row['CONSTRAINT_TYPE'] === 'UNIQUE';
|
$indexes[$row['CONSTRAINT_NAME']]['unique'] = $row['CONSTRAINT_TYPE'] === 'UNIQUE';
|
||||||
$indexes[$row['CONSTRAINT_NAME']]['primary'] = $row['CONSTRAINT_TYPE'] === 'PRIMARY KEY';
|
$indexes[$row['CONSTRAINT_NAME']]['primary'] = $row['CONSTRAINT_TYPE'] === 'PRIMARY KEY';
|
||||||
$indexes[$row['CONSTRAINT_NAME']]['columns'] = isset($keyUsages[$row['CONSTRAINT_NAME']]) ? $keyUsages[$row['CONSTRAINT_NAME']] : array();
|
$indexes[$row['CONSTRAINT_NAME']]['columns'] = isset($keyUsages[$row['CONSTRAINT_NAME']]) ? $keyUsages[$row['CONSTRAINT_NAME']] : [];
|
||||||
}
|
}
|
||||||
return array_values($indexes);
|
return array_values($indexes);
|
||||||
}
|
}
|
||||||
|
@@ -214,7 +214,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
|||||||
public function escapeIdentifier($value)
|
public function escapeIdentifier($value)
|
||||||
{
|
{
|
||||||
// @see https://msdn.microsoft.com/en-us/library/ms176027.aspx
|
// @see https://msdn.microsoft.com/en-us/library/ms176027.aspx
|
||||||
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']';
|
return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -250,7 +250,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
|||||||
*/
|
*/
|
||||||
public function escapeLike($value, $pos)
|
public function escapeLike($value, $pos)
|
||||||
{
|
{
|
||||||
$value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]'));
|
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
|
||||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,15 +353,15 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
|||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$count = mssql_num_fields($this->resultSet);
|
$count = mssql_num_fields($this->resultSet);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$row = (array) mssql_fetch_field($this->resultSet, $i);
|
$row = (array) mssql_fetch_field($this->resultSet, $i);
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
'fullname' => $row['column_source'] ? $row['column_source'] . '.' . $row['name'] : $row['name'],
|
'fullname' => $row['column_source'] ? $row['column_source'] . '.' . $row['name'] : $row['name'],
|
||||||
'table' => $row['column_source'],
|
'table' => $row['column_source'],
|
||||||
'nativetype' => $row['type'],
|
'nativetype' => $row['type'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
@@ -34,12 +34,12 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
|||||||
SELECT TABLE_NAME, TABLE_TYPE
|
SELECT TABLE_NAME, TABLE_TYPE
|
||||||
FROM INFORMATION_SCHEMA.TABLES
|
FROM INFORMATION_SCHEMA.TABLES
|
||||||
');
|
');
|
||||||
$tables = array();
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$tables[] = array(
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $tables;
|
return $tables;
|
||||||
}
|
}
|
||||||
@@ -90,19 +90,19 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
|||||||
WHERE TABLE_NAME = {$this->driver->escapeText($table)}
|
WHERE TABLE_NAME = {$this->driver->escapeText($table)}
|
||||||
ORDER BY TABLE_NAME, ORDINAL_POSITION
|
ORDER BY TABLE_NAME, ORDINAL_POSITION
|
||||||
");
|
");
|
||||||
$columns = array();
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$size = FALSE;
|
$size = FALSE;
|
||||||
$type = strtoupper($row['DATA_TYPE']);
|
$type = strtoupper($row['DATA_TYPE']);
|
||||||
|
|
||||||
$size_cols = array(
|
$size_cols = [
|
||||||
'DATETIME' => 'DATETIME_PRECISION',
|
'DATETIME' => 'DATETIME_PRECISION',
|
||||||
'DECIMAL' => 'NUMERIC_PRECISION',
|
'DECIMAL' => 'NUMERIC_PRECISION',
|
||||||
'CHAR' => 'CHARACTER_MAXIMUM_LENGTH',
|
'CHAR' => 'CHARACTER_MAXIMUM_LENGTH',
|
||||||
'NCHAR' => 'CHARACTER_OCTET_LENGTH',
|
'NCHAR' => 'CHARACTER_OCTET_LENGTH',
|
||||||
'NVARCHAR' => 'CHARACTER_OCTET_LENGTH',
|
'NVARCHAR' => 'CHARACTER_OCTET_LENGTH',
|
||||||
'VARCHAR' => 'CHARACTER_OCTET_LENGTH',
|
'VARCHAR' => 'CHARACTER_OCTET_LENGTH',
|
||||||
);
|
];
|
||||||
|
|
||||||
if (isset($size_cols[$type])) {
|
if (isset($size_cols[$type])) {
|
||||||
if ($size_cols[$type]) {
|
if ($size_cols[$type]) {
|
||||||
@@ -110,7 +110,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['COLUMN_NAME'],
|
'name' => $row['COLUMN_NAME'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => $type,
|
'nativetype' => $type,
|
||||||
@@ -120,7 +120,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
|||||||
'default' => $row['COLUMN_DEFAULT'],
|
'default' => $row['COLUMN_DEFAULT'],
|
||||||
'autoincrement' => FALSE,
|
'autoincrement' => FALSE,
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $columns;
|
return $columns;
|
||||||
@@ -150,16 +150,16 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
|||||||
t.name, ind.name, ind.index_id, ic.index_column_id
|
t.name, ind.name, ind.index_id, ic.index_column_id
|
||||||
");
|
");
|
||||||
|
|
||||||
$indexes = array();
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$index_name = $row['index_name'];
|
$index_name = $row['index_name'];
|
||||||
|
|
||||||
if (!isset($indexes[$index_name])) {
|
if (!isset($indexes[$index_name])) {
|
||||||
$indexes[$index_name] = array();
|
$indexes[$index_name] = [];
|
||||||
$indexes[$index_name]['name'] = $index_name;
|
$indexes[$index_name]['name'] = $index_name;
|
||||||
$indexes[$index_name]['unique'] = (bool) $row['is_unique'];
|
$indexes[$index_name]['unique'] = (bool) $row['is_unique'];
|
||||||
$indexes[$index_name]['primary'] = (bool) $row['is_primary_key'];
|
$indexes[$index_name]['primary'] = (bool) $row['is_primary_key'];
|
||||||
$indexes[$index_name]['columns'] = array();
|
$indexes[$index_name]['columns'] = [];
|
||||||
}
|
}
|
||||||
$indexes[$index_name]['columns'][] = $row['column_name'];
|
$indexes[$index_name]['columns'][] = $row['column_name'];
|
||||||
}
|
}
|
||||||
@@ -190,15 +190,15 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
|||||||
WHERE OBJECT_NAME(f.parent_object_id) = {$this->driver->escapeText($table)}
|
WHERE OBJECT_NAME(f.parent_object_id) = {$this->driver->escapeText($table)}
|
||||||
");
|
");
|
||||||
|
|
||||||
$keys = array();
|
$keys = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$key_name = $row['foreign_key'];
|
$key_name = $row['foreign_key'];
|
||||||
|
|
||||||
if (!isset($keys[$key_name])) {
|
if (!isset($keys[$key_name])) {
|
||||||
$keys[$key_name]['name'] = $row['foreign_key']; // foreign key name
|
$keys[$key_name]['name'] = $row['foreign_key']; // foreign key name
|
||||||
$keys[$key_name]['local'] = array($row['column_name']); // local columns
|
$keys[$key_name]['local'] = [$row['column_name']]; // local columns
|
||||||
$keys[$key_name]['table'] = $row['reference_table_name']; // referenced table
|
$keys[$key_name]['table'] = $row['reference_table_name']; // referenced table
|
||||||
$keys[$key_name]['foreign'] = array($row['reference_column_name']); // referenced columns
|
$keys[$key_name]['foreign'] = [$row['reference_column_name']]; // referenced columns
|
||||||
$keys[$key_name]['onDelete'] = FALSE;
|
$keys[$key_name]['onDelete'] = FALSE;
|
||||||
$keys[$key_name]['onUpdate'] = FALSE;
|
$keys[$key_name]['onUpdate'] = FALSE;
|
||||||
} else {
|
} else {
|
||||||
|
@@ -69,12 +69,12 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
|||||||
} else {
|
} else {
|
||||||
// default values
|
// default values
|
||||||
DibiConnection::alias($config, 'flags', 'options');
|
DibiConnection::alias($config, 'flags', 'options');
|
||||||
$config += array(
|
$config += [
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
'timezone' => date('P'),
|
'timezone' => date('P'),
|
||||||
'username' => ini_get('mysql.default_user'),
|
'username' => ini_get('mysql.default_user'),
|
||||||
'password' => ini_get('mysql.default_password'),
|
'password' => ini_get('mysql.default_password'),
|
||||||
);
|
];
|
||||||
if (!isset($config['host'])) {
|
if (!isset($config['host'])) {
|
||||||
$host = ini_get('mysql.default_host');
|
$host = ini_get('mysql.default_host');
|
||||||
if ($host) {
|
if ($host) {
|
||||||
@@ -168,7 +168,7 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
|||||||
*/
|
*/
|
||||||
public function getInfo()
|
public function getInfo()
|
||||||
{
|
{
|
||||||
$res = array();
|
$res = [];
|
||||||
preg_match_all('#(.+?): +(\d+) *#', mysql_info($this->connection), $matches, PREG_SET_ORDER);
|
preg_match_all('#(.+?): +(\d+) *#', mysql_info($this->connection), $matches, PREG_SET_ORDER);
|
||||||
if (preg_last_error()) {
|
if (preg_last_error()) {
|
||||||
throw new DibiPcreException;
|
throw new DibiPcreException;
|
||||||
@@ -443,16 +443,16 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
|||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$count = mysql_num_fields($this->resultSet);
|
$count = mysql_num_fields($this->resultSet);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$row = (array) mysql_fetch_field($this->resultSet, $i);
|
$row = (array) mysql_fetch_field($this->resultSet, $i);
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
'table' => $row['table'],
|
'table' => $row['table'],
|
||||||
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
||||||
'nativetype' => strtoupper($row['type']),
|
'nativetype' => strtoupper($row['type']),
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
@@ -36,12 +36,12 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
|||||||
WHERE TABLE_SCHEMA = DATABASE()
|
WHERE TABLE_SCHEMA = DATABASE()
|
||||||
");*/
|
");*/
|
||||||
$res = $this->driver->query('SHOW FULL TABLES');
|
$res = $this->driver->query('SHOW FULL TABLES');
|
||||||
$tables = array();
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
$tables[] = array(
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
'view' => isset($row[1]) && $row[1] === 'VIEW',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $tables;
|
return $tables;
|
||||||
}
|
}
|
||||||
@@ -61,10 +61,10 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
|||||||
WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE()
|
WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE()
|
||||||
");*/
|
");*/
|
||||||
$res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escapeIdentifier($table)}");
|
$res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escapeIdentifier($table)}");
|
||||||
$columns = array();
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$type = explode('(', $row['Type']);
|
$type = explode('(', $row['Type']);
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['Field'],
|
'name' => $row['Field'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => strtoupper($type[0]),
|
'nativetype' => strtoupper($type[0]),
|
||||||
@@ -74,7 +74,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
|||||||
'default' => $row['Default'],
|
'default' => $row['Default'],
|
||||||
'autoincrement' => $row['Extra'] === 'auto_increment',
|
'autoincrement' => $row['Extra'] === 'auto_increment',
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
|||||||
AND REFERENCED_COLUMN_NAME IS NULL
|
AND REFERENCED_COLUMN_NAME IS NULL
|
||||||
");*/
|
");*/
|
||||||
$res = $this->driver->query("SHOW INDEX FROM {$this->driver->escapeIdentifier($table)}");
|
$res = $this->driver->query("SHOW INDEX FROM {$this->driver->escapeIdentifier($table)}");
|
||||||
$indexes = array();
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$indexes[$row['Key_name']]['name'] = $row['Key_name'];
|
$indexes[$row['Key_name']]['name'] = $row['Key_name'];
|
||||||
$indexes[$row['Key_name']]['unique'] = !$row['Non_unique'];
|
$indexes[$row['Key_name']]['unique'] = !$row['Non_unique'];
|
||||||
@@ -132,7 +132,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
|||||||
GROUP BY rc.CONSTRAINT_NAME
|
GROUP BY rc.CONSTRAINT_NAME
|
||||||
");
|
");
|
||||||
|
|
||||||
$foreignKeys = array();
|
$foreignKeys = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$keyName = $row['CONSTRAINT_NAME'];
|
$keyName = $row['CONSTRAINT_NAME'];
|
||||||
|
|
||||||
|
@@ -70,14 +70,14 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// default values
|
// default values
|
||||||
$config += array(
|
$config += [
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
'timezone' => date('P'),
|
'timezone' => date('P'),
|
||||||
'username' => ini_get('mysqli.default_user'),
|
'username' => ini_get('mysqli.default_user'),
|
||||||
'password' => ini_get('mysqli.default_pw'),
|
'password' => ini_get('mysqli.default_pw'),
|
||||||
'socket' => (string) ini_get('mysqli.default_socket'),
|
'socket' => (string) ini_get('mysqli.default_socket'),
|
||||||
'port' => NULL,
|
'port' => NULL,
|
||||||
);
|
];
|
||||||
if (!isset($config['host'])) {
|
if (!isset($config['host'])) {
|
||||||
$host = ini_get('mysqli.default_host');
|
$host = ini_get('mysqli.default_host');
|
||||||
if ($host) {
|
if ($host) {
|
||||||
@@ -163,7 +163,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
|||||||
*/
|
*/
|
||||||
public function getInfo()
|
public function getInfo()
|
||||||
{
|
{
|
||||||
$res = array();
|
$res = [];
|
||||||
preg_match_all('#(.+?): +(\d+) *#', mysqli_info($this->connection), $matches, PREG_SET_ORDER);
|
preg_match_all('#(.+?): +(\d+) *#', mysqli_info($this->connection), $matches, PREG_SET_ORDER);
|
||||||
if (preg_last_error()) {
|
if (preg_last_error()) {
|
||||||
throw new DibiPcreException;
|
throw new DibiPcreException;
|
||||||
@@ -432,8 +432,8 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
|||||||
static $types;
|
static $types;
|
||||||
if ($types === NULL) {
|
if ($types === NULL) {
|
||||||
$consts = get_defined_constants(TRUE);
|
$consts = get_defined_constants(TRUE);
|
||||||
$types = array();
|
$types = [];
|
||||||
foreach (isset($consts['mysqli']) ? $consts['mysqli'] : array() as $key => $value) {
|
foreach (isset($consts['mysqli']) ? $consts['mysqli'] : [] as $key => $value) {
|
||||||
if (strncmp($key, 'MYSQLI_TYPE_', 12) === 0) {
|
if (strncmp($key, 'MYSQLI_TYPE_', 12) === 0) {
|
||||||
$types[$value] = substr($key, 12);
|
$types[$value] = substr($key, 12);
|
||||||
}
|
}
|
||||||
@@ -442,16 +442,16 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
|||||||
}
|
}
|
||||||
|
|
||||||
$count = mysqli_num_fields($this->resultSet);
|
$count = mysqli_num_fields($this->resultSet);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$row = (array) mysqli_fetch_field_direct($this->resultSet, $i);
|
$row = (array) mysqli_fetch_field_direct($this->resultSet, $i);
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
'table' => $row['orgtable'],
|
'table' => $row['orgtable'],
|
||||||
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
||||||
'nativetype' => isset($types[$row['type']]) ? $types[$row['type']] : $row['type'],
|
'nativetype' => isset($types[$row['type']]) ? $types[$row['type']] : $row['type'],
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
@@ -59,11 +59,11 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
|||||||
$this->connection = $config['resource'];
|
$this->connection = $config['resource'];
|
||||||
} else {
|
} else {
|
||||||
// default values
|
// default values
|
||||||
$config += array(
|
$config += [
|
||||||
'username' => ini_get('odbc.default_user'),
|
'username' => ini_get('odbc.default_user'),
|
||||||
'password' => ini_get('odbc.default_pw'),
|
'password' => ini_get('odbc.default_pw'),
|
||||||
'dsn' => ini_get('odbc.default_db'),
|
'dsn' => ini_get('odbc.default_db'),
|
||||||
);
|
];
|
||||||
|
|
||||||
if (empty($config['persistent'])) {
|
if (empty($config['persistent'])) {
|
||||||
$this->connection = @odbc_connect($config['dsn'], $config['username'], $config['password']); // intentionally @
|
$this->connection = @odbc_connect($config['dsn'], $config['username'], $config['password']); // intentionally @
|
||||||
@@ -238,7 +238,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
|||||||
|
|
||||||
public function escapeIdentifier($value)
|
public function escapeIdentifier($value)
|
||||||
{
|
{
|
||||||
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']';
|
return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
|||||||
*/
|
*/
|
||||||
public function escapeLike($value, $pos)
|
public function escapeLike($value, $pos)
|
||||||
{
|
{
|
||||||
$value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]'));
|
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
|
||||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
$count = odbc_num_fields($set);
|
$count = odbc_num_fields($set);
|
||||||
$cols = array();
|
$cols = [];
|
||||||
for ($i = 1; $i <= $count; $i++) {
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
$cols[] = odbc_result($set, $i);
|
$cols[] = odbc_result($set, $i);
|
||||||
}
|
}
|
||||||
@@ -392,14 +392,14 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
|||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$count = odbc_num_fields($this->resultSet);
|
$count = odbc_num_fields($this->resultSet);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
for ($i = 1; $i <= $count; $i++) {
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => odbc_field_name($this->resultSet, $i),
|
'name' => odbc_field_name($this->resultSet, $i),
|
||||||
'table' => NULL,
|
'table' => NULL,
|
||||||
'fullname' => odbc_field_name($this->resultSet, $i),
|
'fullname' => odbc_field_name($this->resultSet, $i),
|
||||||
'nativetype' => odbc_field_type($this->resultSet, $i),
|
'nativetype' => odbc_field_type($this->resultSet, $i),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -426,13 +426,13 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
|||||||
public function getTables()
|
public function getTables()
|
||||||
{
|
{
|
||||||
$res = odbc_tables($this->connection);
|
$res = odbc_tables($this->connection);
|
||||||
$tables = array();
|
$tables = [];
|
||||||
while ($row = odbc_fetch_array($res)) {
|
while ($row = odbc_fetch_array($res)) {
|
||||||
if ($row['TABLE_TYPE'] === 'TABLE' || $row['TABLE_TYPE'] === 'VIEW') {
|
if ($row['TABLE_TYPE'] === 'TABLE' || $row['TABLE_TYPE'] === 'VIEW') {
|
||||||
$tables[] = array(
|
$tables[] = [
|
||||||
'name' => $row['TABLE_NAME'],
|
'name' => $row['TABLE_NAME'],
|
||||||
'view' => $row['TABLE_TYPE'] === 'VIEW',
|
'view' => $row['TABLE_TYPE'] === 'VIEW',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
odbc_free_result($res);
|
odbc_free_result($res);
|
||||||
@@ -448,17 +448,17 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
|||||||
public function getColumns($table)
|
public function getColumns($table)
|
||||||
{
|
{
|
||||||
$res = odbc_columns($this->connection);
|
$res = odbc_columns($this->connection);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
while ($row = odbc_fetch_array($res)) {
|
while ($row = odbc_fetch_array($res)) {
|
||||||
if ($row['TABLE_NAME'] === $table) {
|
if ($row['TABLE_NAME'] === $table) {
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['COLUMN_NAME'],
|
'name' => $row['COLUMN_NAME'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => $row['TYPE_NAME'],
|
'nativetype' => $row['TYPE_NAME'],
|
||||||
'size' => $row['COLUMN_SIZE'],
|
'size' => $row['COLUMN_SIZE'],
|
||||||
'nullable' => (bool) $row['NULLABLE'],
|
'nullable' => (bool) $row['NULLABLE'],
|
||||||
'default' => $row['COLUMN_DEF'],
|
'default' => $row['COLUMN_DEF'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
odbc_free_result($res);
|
odbc_free_result($res);
|
||||||
|
@@ -378,15 +378,15 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
|||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$count = oci_num_fields($this->resultSet);
|
$count = oci_num_fields($this->resultSet);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
for ($i = 1; $i <= $count; $i++) {
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
$type = oci_field_type($this->resultSet, $i);
|
$type = oci_field_type($this->resultSet, $i);
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => oci_field_name($this->resultSet, $i),
|
'name' => oci_field_name($this->resultSet, $i),
|
||||||
'table' => NULL,
|
'table' => NULL,
|
||||||
'fullname' => oci_field_name($this->resultSet, $i),
|
'fullname' => oci_field_name($this->resultSet, $i),
|
||||||
'nativetype' => $type === 'NUMBER' && oci_field_scale($this->resultSet, $i) === 0 ? 'INTEGER' : $type,
|
'nativetype' => $type === 'NUMBER' && oci_field_scale($this->resultSet, $i) === 0 ? 'INTEGER' : $type,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -413,13 +413,13 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
|||||||
public function getTables()
|
public function getTables()
|
||||||
{
|
{
|
||||||
$res = $this->query('SELECT * FROM cat');
|
$res = $this->query('SELECT * FROM cat');
|
||||||
$tables = array();
|
$tables = [];
|
||||||
while ($row = $res->fetch(FALSE)) {
|
while ($row = $res->fetch(FALSE)) {
|
||||||
if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
|
if ($row[1] === 'TABLE' || $row[1] === 'VIEW') {
|
||||||
$tables[] = array(
|
$tables[] = [
|
||||||
'name' => $row[0],
|
'name' => $row[0],
|
||||||
'view' => $row[1] === 'VIEW',
|
'view' => $row[1] === 'VIEW',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $tables;
|
return $tables;
|
||||||
|
@@ -101,7 +101,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
|||||||
{
|
{
|
||||||
// must detect if SQL returns result set or num of affected rows
|
// must detect if SQL returns result set or num of affected rows
|
||||||
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
||||||
static $list = array('UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1);
|
static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1];
|
||||||
$this->affectedRows = FALSE;
|
$this->affectedRows = FALSE;
|
||||||
|
|
||||||
if (isset($list[$cmd])) {
|
if (isset($list[$cmd])) {
|
||||||
@@ -275,7 +275,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
|||||||
|
|
||||||
case 'odbc':
|
case 'odbc':
|
||||||
case 'mssql':
|
case 'mssql':
|
||||||
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']';
|
return '[' . str_replace(['[', ']'], ['[[', ']]'], $value) . ']';
|
||||||
|
|
||||||
case 'dblib':
|
case 'dblib':
|
||||||
case 'sqlsrv':
|
case 'sqlsrv':
|
||||||
@@ -336,7 +336,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
|||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
$bs = substr($this->connection->quote('\\', PDO::PARAM_STR), 1, -1); // standard_conforming_strings = on/off
|
$bs = substr($this->connection->quote('\\', PDO::PARAM_STR), 1, -1); // standard_conforming_strings = on/off
|
||||||
$value = substr($this->connection->quote($value, PDO::PARAM_STR), 1, -1);
|
$value = substr($this->connection->quote($value, PDO::PARAM_STR), 1, -1);
|
||||||
$value = strtr($value, array('%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\'));
|
$value = strtr($value, ['%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\']);
|
||||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||||
|
|
||||||
case 'sqlite':
|
case 'sqlite':
|
||||||
@@ -347,7 +347,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
|||||||
case 'mssql':
|
case 'mssql':
|
||||||
case 'dblib':
|
case 'dblib':
|
||||||
case 'sqlsrv':
|
case 'sqlsrv':
|
||||||
$value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]'));
|
$value = strtr($value, ["'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]']);
|
||||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -491,24 +491,24 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
|||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$count = $this->resultSet->columnCount();
|
$count = $this->resultSet->columnCount();
|
||||||
$columns = array();
|
$columns = [];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$row = @$this->resultSet->getColumnMeta($i); // intentionally @
|
$row = @$this->resultSet->getColumnMeta($i); // intentionally @
|
||||||
if ($row === FALSE) {
|
if ($row === FALSE) {
|
||||||
throw new DibiNotSupportedException('Driver does not support meta data.');
|
throw new DibiNotSupportedException('Driver does not support meta data.');
|
||||||
}
|
}
|
||||||
$row = $row + array(
|
$row = $row + [
|
||||||
'table' => NULL,
|
'table' => NULL,
|
||||||
'native_type' => 'VAR_STRING',
|
'native_type' => 'VAR_STRING',
|
||||||
);
|
];
|
||||||
|
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
'table' => $row['table'],
|
'table' => $row['table'],
|
||||||
'nativetype' => $row['native_type'],
|
'nativetype' => $row['native_type'],
|
||||||
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
@@ -57,16 +57,16 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
$this->connection = $config['resource'];
|
$this->connection = $config['resource'];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$config += array(
|
$config += [
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
);
|
];
|
||||||
if (isset($config['string'])) {
|
if (isset($config['string'])) {
|
||||||
$string = $config['string'];
|
$string = $config['string'];
|
||||||
} else {
|
} else {
|
||||||
$string = '';
|
$string = '';
|
||||||
DibiConnection::alias($config, 'user', 'username');
|
DibiConnection::alias($config, 'user', 'username');
|
||||||
DibiConnection::alias($config, 'dbname', 'database');
|
DibiConnection::alias($config, 'dbname', 'database');
|
||||||
foreach (array('host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service') as $key) {
|
foreach (['host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service'] as $key) {
|
||||||
if (isset($config[$key])) {
|
if (isset($config[$key])) {
|
||||||
$string .= $key . '=' . $config[$key] . ' ';
|
$string .= $key . '=' . $config[$key] . ' ';
|
||||||
}
|
}
|
||||||
@@ -219,7 +219,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
*/
|
*/
|
||||||
public function inTransaction()
|
public function inTransaction()
|
||||||
{
|
{
|
||||||
return !in_array(pg_transaction_status($this->connection), array(PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE), TRUE);
|
return !in_array(pg_transaction_status($this->connection), [PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE], TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -323,7 +323,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
{
|
{
|
||||||
$bs = pg_escape_string($this->connection, '\\'); // standard_conforming_strings = on/off
|
$bs = pg_escape_string($this->connection, '\\'); // standard_conforming_strings = on/off
|
||||||
$value = pg_escape_string($this->connection, $value);
|
$value = pg_escape_string($this->connection, $value);
|
||||||
$value = strtr($value, array('%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\'));
|
$value = strtr($value, ['%' => $bs . '%', '_' => $bs . '_', '\\' => '\\\\']);
|
||||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,13 +425,13 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$count = pg_num_fields($this->resultSet);
|
$count = pg_num_fields($this->resultSet);
|
||||||
$columns = array();
|
$columns = [];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$row = array(
|
$row = [
|
||||||
'name' => pg_field_name($this->resultSet, $i),
|
'name' => pg_field_name($this->resultSet, $i),
|
||||||
'table' => pg_field_table($this->resultSet, $i),
|
'table' => pg_field_table($this->resultSet, $i),
|
||||||
'nativetype' => pg_field_type($this->resultSet, $i),
|
'nativetype' => pg_field_type($this->resultSet, $i),
|
||||||
);
|
];
|
||||||
$row['fullname'] = $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'];
|
$row['fullname'] = $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'];
|
||||||
$columns[] = $row;
|
$columns[] = $row;
|
||||||
}
|
}
|
||||||
@@ -489,7 +489,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
|
|
||||||
$res = $this->query($query);
|
$res = $this->query($query);
|
||||||
$tables = pg_fetch_all($res->resultSet);
|
$tables = pg_fetch_all($res->resultSet);
|
||||||
return $tables ? $tables : array();
|
return $tables ? $tables : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -542,10 +542,10 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
$columns = array();
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$size = (int) max($row['character_maximum_length'], $row['numeric_precision']);
|
$size = (int) max($row['character_maximum_length'], $row['numeric_precision']);
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $row['column_name'],
|
'name' => $row['column_name'],
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'nativetype' => strtoupper($row['udt_name']),
|
'nativetype' => strtoupper($row['udt_name']),
|
||||||
@@ -554,7 +554,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
'default' => $row['column_default'],
|
'default' => $row['column_default'],
|
||||||
'autoincrement' => (int) $row['ordinal_position'] === $primary && substr($row['column_default'], 0, 7) === 'nextval',
|
'autoincrement' => (int) $row['ordinal_position'] === $primary && substr($row['column_default'], 0, 7) === 'nextval',
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -582,7 +582,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
ORDER BY ordinal_position
|
ORDER BY ordinal_position
|
||||||
");
|
");
|
||||||
|
|
||||||
$columns = array();
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$columns[$row['ordinal_position']] = $row['column_name'];
|
$columns[$row['ordinal_position']] = $row['column_name'];
|
||||||
}
|
}
|
||||||
@@ -595,7 +595,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
WHERE pg_class.oid = $_table::regclass
|
WHERE pg_class.oid = $_table::regclass
|
||||||
");
|
");
|
||||||
|
|
||||||
$indexes = array();
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$indexes[$row['relname']]['name'] = $row['relname'];
|
$indexes[$row['relname']]['name'] = $row['relname'];
|
||||||
$indexes[$row['relname']]['unique'] = $row['indisunique'] === 't';
|
$indexes[$row['relname']]['unique'] = $row['indisunique'] === 't';
|
||||||
@@ -656,17 +656,17 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
c.conrelid = $_table::regclass
|
c.conrelid = $_table::regclass
|
||||||
");
|
");
|
||||||
|
|
||||||
$fKeys = $references = array();
|
$fKeys = $references = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
if (!isset($fKeys[$row['name']])) {
|
if (!isset($fKeys[$row['name']])) {
|
||||||
$fKeys[$row['name']] = array(
|
$fKeys[$row['name']] = [
|
||||||
'name' => $row['name'],
|
'name' => $row['name'],
|
||||||
'table' => $row['table'],
|
'table' => $row['table'],
|
||||||
'local' => array(),
|
'local' => [],
|
||||||
'foreign' => array(),
|
'foreign' => [],
|
||||||
'onUpdate' => $row['onUpdate'],
|
'onUpdate' => $row['onUpdate'],
|
||||||
'onDelete' => $row['onDelete'],
|
'onDelete' => $row['onDelete'],
|
||||||
);
|
];
|
||||||
|
|
||||||
$l = explode(',', trim($row['conkey'], '{}'));
|
$l = explode(',', trim($row['conkey'], '{}'));
|
||||||
$f = explode(',', trim($row['confkey'], '{}'));
|
$f = explode(',', trim($row['confkey'], '{}'));
|
||||||
|
@@ -332,12 +332,12 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
$row = $this->resultSet->fetchArray($assoc ? SQLITE3_ASSOC : SQLITE3_NUM);
|
$row = $this->resultSet->fetchArray($assoc ? SQLITE3_ASSOC : SQLITE3_NUM);
|
||||||
$charset = $this->charset === NULL ? NULL : $this->charset . '//TRANSLIT';
|
$charset = $this->charset === NULL ? NULL : $this->charset . '//TRANSLIT';
|
||||||
if ($row && ($assoc || $charset)) {
|
if ($row && ($assoc || $charset)) {
|
||||||
$tmp = array();
|
$tmp = [];
|
||||||
foreach ($row as $k => $v) {
|
foreach ($row as $k => $v) {
|
||||||
if ($charset !== NULL && is_string($v)) {
|
if ($charset !== NULL && is_string($v)) {
|
||||||
$v = iconv($this->dbcharset, $charset, $v);
|
$v = iconv($this->dbcharset, $charset, $v);
|
||||||
}
|
}
|
||||||
$tmp[str_replace(array('[', ']'), '', $k)] = $v;
|
$tmp[str_replace(['[', ']'], '', $k)] = $v;
|
||||||
}
|
}
|
||||||
return $tmp;
|
return $tmp;
|
||||||
}
|
}
|
||||||
@@ -375,15 +375,15 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
|
|||||||
public function getResultColumns()
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
$count = $this->resultSet->numColumns();
|
$count = $this->resultSet->numColumns();
|
||||||
$columns = array();
|
$columns = [];
|
||||||
static $types = array(SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null');
|
static $types = [SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null'];
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $this->resultSet->columnName($i),
|
'name' => $this->resultSet->columnName($i),
|
||||||
'table' => NULL,
|
'table' => NULL,
|
||||||
'fullname' => $this->resultSet->columnName($i),
|
'fullname' => $this->resultSet->columnName($i),
|
||||||
'nativetype' => $types[$this->resultSet->columnType($i)],
|
'nativetype' => $types[$this->resultSet->columnType($i)],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
|
|||||||
SELECT name, type = 'view' as view FROM sqlite_temp_master WHERE type IN ('table', 'view')
|
SELECT name, type = 'view' as view FROM sqlite_temp_master WHERE type IN ('table', 'view')
|
||||||
ORDER BY name
|
ORDER BY name
|
||||||
");
|
");
|
||||||
$tables = array();
|
$tables = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$tables[] = $row;
|
$tables[] = $row;
|
||||||
}
|
}
|
||||||
@@ -58,11 +58,11 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
|
|||||||
")->fetch(TRUE);
|
")->fetch(TRUE);
|
||||||
|
|
||||||
$res = $this->driver->query("PRAGMA table_info({$this->driver->escapeIdentifier($table)})");
|
$res = $this->driver->query("PRAGMA table_info({$this->driver->escapeIdentifier($table)})");
|
||||||
$columns = array();
|
$columns = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$column = $row['name'];
|
$column = $row['name'];
|
||||||
$type = explode('(', $row['type']);
|
$type = explode('(', $row['type']);
|
||||||
$columns[] = array(
|
$columns[] = [
|
||||||
'name' => $column,
|
'name' => $column,
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'fullname' => "$table.$column",
|
'fullname' => "$table.$column",
|
||||||
@@ -72,7 +72,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
|
|||||||
'default' => $row['dflt_value'],
|
'default' => $row['dflt_value'],
|
||||||
'autoincrement' => $row['pk'] && $type[0] === 'INTEGER',
|
'autoincrement' => $row['pk'] && $type[0] === 'INTEGER',
|
||||||
'vendor' => $row,
|
'vendor' => $row,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
|
|||||||
public function getIndexes($table)
|
public function getIndexes($table)
|
||||||
{
|
{
|
||||||
$res = $this->driver->query("PRAGMA index_list({$this->driver->escapeIdentifier($table)})");
|
$res = $this->driver->query("PRAGMA index_list({$this->driver->escapeIdentifier($table)})");
|
||||||
$indexes = array();
|
$indexes = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$indexes[$row['name']]['name'] = $row['name'];
|
$indexes[$row['name']]['name'] = $row['name'];
|
||||||
$indexes[$row['name']]['unique'] = (bool) $row['unique'];
|
$indexes[$row['name']]['unique'] = (bool) $row['unique'];
|
||||||
@@ -114,12 +114,12 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
|
|||||||
if (!$indexes) { // @see http://www.sqlite.org/lang_createtable.html#rowid
|
if (!$indexes) { // @see http://www.sqlite.org/lang_createtable.html#rowid
|
||||||
foreach ($columns as $column) {
|
foreach ($columns as $column) {
|
||||||
if ($column['vendor']['pk']) {
|
if ($column['vendor']['pk']) {
|
||||||
$indexes[] = array(
|
$indexes[] = [
|
||||||
'name' => 'ROWID',
|
'name' => 'ROWID',
|
||||||
'unique' => TRUE,
|
'unique' => TRUE,
|
||||||
'primary' => TRUE,
|
'primary' => TRUE,
|
||||||
'columns' => array($column['name']),
|
'columns' => [$column['name']],
|
||||||
);
|
];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
|
|||||||
public function getForeignKeys($table)
|
public function getForeignKeys($table)
|
||||||
{
|
{
|
||||||
$res = $this->driver->query("PRAGMA foreign_key_list({$this->driver->escapeIdentifier($table)})");
|
$res = $this->driver->query("PRAGMA foreign_key_list({$this->driver->escapeIdentifier($table)})");
|
||||||
$keys = array();
|
$keys = [];
|
||||||
while ($row = $res->fetch(TRUE)) {
|
while ($row = $res->fetch(TRUE)) {
|
||||||
$keys[$row['id']]['name'] = $row['id']; // foreign key name
|
$keys[$row['id']]['name'] = $row['id']; // foreign key name
|
||||||
$keys[$row['id']]['local'][$row['seq']] = $row['from']; // local columns
|
$keys[$row['id']]['local'][$row['seq']] = $row['from']; // local columns
|
||||||
|
@@ -56,10 +56,10 @@ class DibiEvent
|
|||||||
$this->time = -microtime(TRUE);
|
$this->time = -microtime(TRUE);
|
||||||
|
|
||||||
if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {
|
if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {
|
||||||
static $types = array(
|
static $types = [
|
||||||
'SELECT' => self::SELECT, 'UPDATE' => self::UPDATE,
|
'SELECT' => self::SELECT, 'UPDATE' => self::UPDATE,
|
||||||
'INSERT' => self::INSERT, 'DELETE' => self::DELETE,
|
'INSERT' => self::INSERT, 'DELETE' => self::DELETE,
|
||||||
);
|
];
|
||||||
$this->type = $types[strtoupper($matches[1])];
|
$this->type = $types[strtoupper($matches[1])];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ class DibiEvent
|
|||||||
$dibiDir = dirname($rc->getFileName()) . DIRECTORY_SEPARATOR;
|
$dibiDir = dirname($rc->getFileName()) . DIRECTORY_SEPARATOR;
|
||||||
foreach (debug_backtrace(FALSE) as $row) {
|
foreach (debug_backtrace(FALSE) as $row) {
|
||||||
if (isset($row['file']) && is_file($row['file']) && strpos($row['file'], $dibiDir) !== 0) {
|
if (isset($row['file']) && is_file($row['file']) && strpos($row['file'], $dibiDir) !== 0) {
|
||||||
$this->source = array($row['file'], (int) $row['line']);
|
$this->source = [$row['file'], (int) $row['line']];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,16 +28,16 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
const REMOVE = FALSE;
|
const REMOVE = FALSE;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public static $masks = array(
|
public static $masks = [
|
||||||
'SELECT' => array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
|
'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
|
||||||
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET'),
|
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET'],
|
||||||
'UPDATE' => array('UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'),
|
'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
|
||||||
'INSERT' => array('INSERT', 'INTO', 'VALUES', 'SELECT'),
|
'INSERT' => ['INSERT', 'INTO', 'VALUES', 'SELECT'],
|
||||||
'DELETE' => array('DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'),
|
'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],
|
||||||
);
|
];
|
||||||
|
|
||||||
/** @var array default modifiers for arrays */
|
/** @var array default modifiers for arrays */
|
||||||
public static $modifiers = array(
|
public static $modifiers = [
|
||||||
'SELECT' => '%n',
|
'SELECT' => '%n',
|
||||||
'FROM' => '%n',
|
'FROM' => '%n',
|
||||||
'IN' => '%in',
|
'IN' => '%in',
|
||||||
@@ -47,10 +47,10 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
'HAVING' => '%and',
|
'HAVING' => '%and',
|
||||||
'ORDER BY' => '%by',
|
'ORDER BY' => '%by',
|
||||||
'GROUP BY' => '%by',
|
'GROUP BY' => '%by',
|
||||||
);
|
];
|
||||||
|
|
||||||
/** @var array clauses separators */
|
/** @var array clauses separators */
|
||||||
public static $separators = array(
|
public static $separators = [
|
||||||
'SELECT' => ',',
|
'SELECT' => ',',
|
||||||
'FROM' => ',',
|
'FROM' => ',',
|
||||||
'WHERE' => 'AND',
|
'WHERE' => 'AND',
|
||||||
@@ -62,30 +62,30 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
'SET' => ',',
|
'SET' => ',',
|
||||||
'VALUES' => ',',
|
'VALUES' => ',',
|
||||||
'INTO' => FALSE,
|
'INTO' => FALSE,
|
||||||
);
|
];
|
||||||
|
|
||||||
/** @var array clauses */
|
/** @var array clauses */
|
||||||
public static $clauseSwitches = array(
|
public static $clauseSwitches = [
|
||||||
'JOIN' => 'FROM',
|
'JOIN' => 'FROM',
|
||||||
'INNER JOIN' => 'FROM',
|
'INNER JOIN' => 'FROM',
|
||||||
'LEFT JOIN' => 'FROM',
|
'LEFT JOIN' => 'FROM',
|
||||||
'RIGHT JOIN' => 'FROM',
|
'RIGHT JOIN' => 'FROM',
|
||||||
);
|
];
|
||||||
|
|
||||||
/** @var DibiConnection */
|
/** @var DibiConnection */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $setups = array();
|
private $setups = [];
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $command;
|
private $command;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $clauses = array();
|
private $clauses = [];
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $flags = array();
|
private $flags = [];
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $cursor;
|
private $cursor;
|
||||||
@@ -102,7 +102,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
|
|
||||||
if (self::$normalizer === NULL) {
|
if (self::$normalizer === NULL) {
|
||||||
self::$normalizer = new DibiHashMap(array(__CLASS__, '_formatClause'));
|
self::$normalizer = new DibiHashMap([__CLASS__, '_formatClause']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
$this->clauses = array_fill_keys(self::$masks[$clause], NULL);
|
$this->clauses = array_fill_keys(self::$masks[$clause], NULL);
|
||||||
}
|
}
|
||||||
$this->cursor = & $this->clauses[$clause];
|
$this->cursor = & $this->clauses[$clause];
|
||||||
$this->cursor = array();
|
$this->cursor = [];
|
||||||
$this->command = $clause;
|
$this->command = $clause;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
$this->cursor = & $this->clauses[$clause];
|
$this->cursor = & $this->clauses[$clause];
|
||||||
|
|
||||||
// TODO: really delete?
|
// TODO: really delete?
|
||||||
if ($args === array(self::REMOVE)) {
|
if ($args === [self::REMOVE]) {
|
||||||
$this->cursor = NULL;
|
$this->cursor = NULL;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
if (isset(self::$separators[$clause])) {
|
if (isset(self::$separators[$clause])) {
|
||||||
$sep = self::$separators[$clause];
|
$sep = self::$separators[$clause];
|
||||||
if ($sep === FALSE) { // means: replace
|
if ($sep === FALSE) { // means: replace
|
||||||
$this->cursor = array();
|
$this->cursor = [];
|
||||||
|
|
||||||
} elseif (!empty($this->cursor)) {
|
} elseif (!empty($this->cursor)) {
|
||||||
$this->cursor[] = $sep;
|
$this->cursor[] = $sep;
|
||||||
@@ -154,7 +154,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// append to currect flow
|
// append to currect flow
|
||||||
if ($args === array(self::REMOVE)) {
|
if ($args === [self::REMOVE]) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->cursor === NULL) {
|
if ($this->cursor === NULL) {
|
||||||
$this->cursor = array();
|
$this->cursor = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// special types or argument
|
// special types or argument
|
||||||
@@ -173,14 +173,14 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
|
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
|
||||||
$args = array('%n', $arg);
|
$args = ['%n', $arg];
|
||||||
|
|
||||||
} elseif (is_array($arg) || ($arg instanceof Traversable && !$arg instanceof self)) { // any array
|
} elseif (is_array($arg) || ($arg instanceof Traversable && !$arg instanceof self)) { // any array
|
||||||
if (isset(self::$modifiers[$clause])) {
|
if (isset(self::$modifiers[$clause])) {
|
||||||
$args = array(self::$modifiers[$clause], $arg);
|
$args = [self::$modifiers[$clause], $arg];
|
||||||
|
|
||||||
} elseif (is_string(key($arg))) { // associative array
|
} elseif (is_string(key($arg))) { // associative array
|
||||||
$args = array('%a', $arg);
|
$args = ['%a', $arg];
|
||||||
}
|
}
|
||||||
} // case $arg === FALSE is handled above
|
} // case $arg === FALSE is handled above
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
{
|
{
|
||||||
$this->cursor = & $this->clauses[self::$normalizer->$clause];
|
$this->cursor = & $this->clauses[self::$normalizer->$clause];
|
||||||
if ($this->cursor === NULL) {
|
if ($this->cursor === NULL) {
|
||||||
$this->cursor = array();
|
$this->cursor = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -316,7 +316,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
public function fetch()
|
public function fetch()
|
||||||
{
|
{
|
||||||
if ($this->command === 'SELECT') {
|
if ($this->command === 'SELECT') {
|
||||||
return $this->query($this->_export(NULL, array('%lmt', 1)))->fetch();
|
return $this->query($this->_export(NULL, ['%lmt', 1]))->fetch();
|
||||||
} else {
|
} else {
|
||||||
return $this->query($this->_export())->fetch();
|
return $this->query($this->_export())->fetch();
|
||||||
}
|
}
|
||||||
@@ -330,7 +330,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
public function fetchSingle()
|
public function fetchSingle()
|
||||||
{
|
{
|
||||||
if ($this->command === 'SELECT') {
|
if ($this->command === 'SELECT') {
|
||||||
return $this->query($this->_export(NULL, array('%lmt', 1)))->fetchSingle();
|
return $this->query($this->_export(NULL, ['%lmt', 1]))->fetchSingle();
|
||||||
} else {
|
} else {
|
||||||
return $this->query($this->_export())->fetchSingle();
|
return $this->query($this->_export())->fetchSingle();
|
||||||
}
|
}
|
||||||
@@ -345,7 +345,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function fetchAll($offset = NULL, $limit = NULL)
|
public function fetchAll($offset = NULL, $limit = NULL)
|
||||||
{
|
{
|
||||||
return $this->query($this->_export(NULL, array('%ofs %lmt', $offset, $limit)))->fetchAll();
|
return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function getIterator($offset = NULL, $limit = NULL)
|
public function getIterator($offset = NULL, $limit = NULL)
|
||||||
{
|
{
|
||||||
return $this->query($this->_export(NULL, array('%ofs %lmt', $offset, $limit)))->getIterator();
|
return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->getIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -400,9 +400,9 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function count()
|
public function count()
|
||||||
{
|
{
|
||||||
return (int) $this->query(array(
|
return (int) $this->query([
|
||||||
'SELECT COUNT(*) FROM (%ex', $this->_export(), ') AS [data]',
|
'SELECT COUNT(*) FROM (%ex', $this->_export(), ') AS [data]',
|
||||||
))->fetchSingle();
|
])->fetchSingle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -413,7 +413,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
{
|
{
|
||||||
$res = $this->connection->query($args);
|
$res = $this->connection->query($args);
|
||||||
foreach ($this->setups as $setup) {
|
foreach ($this->setups as $setup) {
|
||||||
call_user_func_array(array($res, array_shift($setup)), $setup);
|
call_user_func_array([$res, array_shift($setup)], $setup);
|
||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
@@ -450,7 +450,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
* @param string clause name
|
* @param string clause name
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function _export($clause = NULL, $args = array())
|
protected function _export($clause = NULL, $args = [])
|
||||||
{
|
{
|
||||||
if ($clause === NULL) {
|
if ($clause === NULL) {
|
||||||
$data = $this->clauses;
|
$data = $this->clauses;
|
||||||
@@ -458,9 +458,9 @@ class DibiFluent extends DibiObject implements IDataSource
|
|||||||
} else {
|
} else {
|
||||||
$clause = self::$normalizer->$clause;
|
$clause = self::$normalizer->$clause;
|
||||||
if (array_key_exists($clause, $this->clauses)) {
|
if (array_key_exists($clause, $this->clauses)) {
|
||||||
$data = array($clause => $this->clauses[$clause]);
|
$data = [$clause => $this->clauses[$clause]];
|
||||||
} else {
|
} else {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,14 +15,14 @@ class DibiHelpers
|
|||||||
/** @internal */
|
/** @internal */
|
||||||
public static function escape($driver, $value, $type)
|
public static function escape($driver, $value, $type)
|
||||||
{
|
{
|
||||||
static $types = array(
|
static $types = [
|
||||||
dibi::TEXT => 'text',
|
dibi::TEXT => 'text',
|
||||||
dibi::BINARY => 'binary',
|
dibi::BINARY => 'binary',
|
||||||
dibi::BOOL => 'bool',
|
dibi::BOOL => 'bool',
|
||||||
dibi::DATE => 'date',
|
dibi::DATE => 'date',
|
||||||
dibi::DATETIME => 'datetime',
|
dibi::DATETIME => 'datetime',
|
||||||
dibi::IDENTIFIER => 'identifier',
|
dibi::IDENTIFIER => 'identifier',
|
||||||
);
|
];
|
||||||
if (isset($types[$type])) {
|
if (isset($types[$type])) {
|
||||||
return $driver->{'escape' . $types[$type]}($value);
|
return $driver->{'escape' . $types[$type]}($value);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -32,7 +32,7 @@ class DibiFirePhpLogger extends DibiObject
|
|||||||
public $numOfQueries = 0;
|
public $numOfQueries = 0;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private static $fireTable = array(array('Time', 'SQL Statement', 'Rows', 'Connection'));
|
private static $fireTable = [['Time', 'SQL Statement', 'Rows', 'Connection']];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,20 +67,20 @@ class DibiFirePhpLogger extends DibiObject
|
|||||||
}
|
}
|
||||||
$this->totalTime += $event->time;
|
$this->totalTime += $event->time;
|
||||||
$this->numOfQueries++;
|
$this->numOfQueries++;
|
||||||
self::$fireTable[] = array(
|
self::$fireTable[] = [
|
||||||
sprintf('%0.3f', $event->time * 1000),
|
sprintf('%0.3f', $event->time * 1000),
|
||||||
strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql,
|
strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql,
|
||||||
$event->result instanceof Exception ? 'ERROR' : (string) $event->count,
|
$event->result instanceof Exception ? 'ERROR' : (string) $event->count,
|
||||||
$event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'),
|
$event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'),
|
||||||
);
|
];
|
||||||
|
|
||||||
$payload = json_encode(array(
|
$payload = json_encode([
|
||||||
array(
|
[
|
||||||
'Type' => 'TABLE',
|
'Type' => 'TABLE',
|
||||||
'Label' => 'dibi profiler (' . $this->numOfQueries . ' SQL queries took ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms)',
|
'Label' => 'dibi profiler (' . $this->numOfQueries . ' SQL queries took ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms)',
|
||||||
),
|
],
|
||||||
self::$fireTable,
|
self::$fireTable,
|
||||||
));
|
]);
|
||||||
foreach (str_split($payload, self::$streamChunkSize) as $num => $s) {
|
foreach (str_split($payload, self::$streamChunkSize) as $num => $s) {
|
||||||
$num++;
|
$num++;
|
||||||
header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index
|
header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index
|
||||||
|
@@ -48,7 +48,7 @@
|
|||||||
*/
|
*/
|
||||||
abstract class DibiObject
|
abstract class DibiObject
|
||||||
{
|
{
|
||||||
/** @var array (method => array(type => callback)) */
|
/** @var array [method => [type => callback]] */
|
||||||
private static $extMethods;
|
private static $extMethods;
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ abstract class DibiObject
|
|||||||
if (is_array($list) || $list instanceof Traversable) {
|
if (is_array($list) || $list instanceof Traversable) {
|
||||||
foreach ($list as $handler) {
|
foreach ($list as $handler) {
|
||||||
/**/if (is_object($handler)) {
|
/**/if (is_object($handler)) {
|
||||||
call_user_func_array(array($handler, '__invoke'), $args);
|
call_user_func_array([$handler, '__invoke'], $args);
|
||||||
|
|
||||||
} else /**/{
|
} else /**/{
|
||||||
call_user_func_array($handler, $args);
|
call_user_func_array($handler, $args);
|
||||||
|
@@ -76,7 +76,7 @@ class DibiColumnInfo extends DibiObject
|
|||||||
if (empty($this->info['table']) || !$this->reflector) {
|
if (empty($this->info['table']) || !$this->reflector) {
|
||||||
throw new DibiException("Table is unknown or not available.");
|
throw new DibiException("Table is unknown or not available.");
|
||||||
}
|
}
|
||||||
return new DibiTableInfo($this->reflector, array('name' => $this->info['table']));
|
return new DibiTableInfo($this->reflector, ['name' => $this->info['table']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ class DibiColumnInfo extends DibiObject
|
|||||||
*/
|
*/
|
||||||
public static function detectType($type)
|
public static function detectType($type)
|
||||||
{
|
{
|
||||||
static $patterns = array(
|
static $patterns = [
|
||||||
'^_' => dibi::TEXT, // PostgreSQL arrays
|
'^_' => dibi::TEXT, // PostgreSQL arrays
|
||||||
'BYTEA|BLOB|BIN' => dibi::BINARY,
|
'BYTEA|BLOB|BIN' => dibi::BINARY,
|
||||||
'TEXT|CHAR|POINT|INTERVAL' => dibi::TEXT,
|
'TEXT|CHAR|POINT|INTERVAL' => dibi::TEXT,
|
||||||
@@ -180,7 +180,7 @@ class DibiColumnInfo extends DibiObject
|
|||||||
'TIME' => dibi::DATETIME, // DATETIME, TIMESTAMP
|
'TIME' => dibi::DATETIME, // DATETIME, TIMESTAMP
|
||||||
'DATE' => dibi::DATE,
|
'DATE' => dibi::DATE,
|
||||||
'BOOL' => dibi::BOOL,
|
'BOOL' => dibi::BOOL,
|
||||||
);
|
];
|
||||||
|
|
||||||
foreach ($patterns as $s => $val) {
|
foreach ($patterns as $s => $val) {
|
||||||
if (preg_match("#$s#i", $type)) {
|
if (preg_match("#$s#i", $type)) {
|
||||||
@@ -197,7 +197,7 @@ class DibiColumnInfo extends DibiObject
|
|||||||
public static function getTypeCache()
|
public static function getTypeCache()
|
||||||
{
|
{
|
||||||
if (self::$types === NULL) {
|
if (self::$types === NULL) {
|
||||||
self::$types = new DibiHashMap(array(__CLASS__, 'detectType'));
|
self::$types = new DibiHashMap([__CLASS__, 'detectType']);
|
||||||
}
|
}
|
||||||
return self::$types;
|
return self::$types;
|
||||||
}
|
}
|
||||||
|
@@ -59,7 +59,7 @@ class DibiDatabaseInfo extends DibiObject
|
|||||||
public function getTableNames()
|
public function getTableNames()
|
||||||
{
|
{
|
||||||
$this->init();
|
$this->init();
|
||||||
$res = array();
|
$res = [];
|
||||||
foreach ($this->tables as $table) {
|
foreach ($this->tables as $table) {
|
||||||
$res[] = $table->getName();
|
$res[] = $table->getName();
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ class DibiDatabaseInfo extends DibiObject
|
|||||||
protected function init()
|
protected function init()
|
||||||
{
|
{
|
||||||
if ($this->tables === NULL) {
|
if ($this->tables === NULL) {
|
||||||
$this->tables = array();
|
$this->tables = [];
|
||||||
foreach ($this->reflector->getTables() as $info) {
|
foreach ($this->reflector->getTables() as $info) {
|
||||||
$this->tables[strtolower($info['name'])] = new DibiTableInfo($this->reflector, $info);
|
$this->tables[strtolower($info['name'])] = new DibiTableInfo($this->reflector, $info);
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ class DibiForeignKeyInfo extends DibiObject
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
/** @var array of array(local, foreign, onDelete, onUpdate) */
|
/** @var array of [local, foreign, onDelete, onUpdate] */
|
||||||
private $references;
|
private $references;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -49,7 +49,7 @@ class DibiResultInfo extends DibiObject
|
|||||||
public function getColumnNames($fullNames = FALSE)
|
public function getColumnNames($fullNames = FALSE)
|
||||||
{
|
{
|
||||||
$this->initColumns();
|
$this->initColumns();
|
||||||
$res = array();
|
$res = [];
|
||||||
foreach ($this->columns as $column) {
|
foreach ($this->columns as $column) {
|
||||||
$res[] = $fullNames ? $column->getFullName() : $column->getName();
|
$res[] = $fullNames ? $column->getFullName() : $column->getName();
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ class DibiResultInfo extends DibiObject
|
|||||||
protected function initColumns()
|
protected function initColumns()
|
||||||
{
|
{
|
||||||
if ($this->columns === NULL) {
|
if ($this->columns === NULL) {
|
||||||
$this->columns = array();
|
$this->columns = [];
|
||||||
$reflector = $this->driver instanceof IDibiReflector ? $this->driver : NULL;
|
$reflector = $this->driver instanceof IDibiReflector ? $this->driver : NULL;
|
||||||
foreach ($this->driver->getResultColumns() as $info) {
|
foreach ($this->driver->getResultColumns() as $info) {
|
||||||
$this->columns[] = $this->names[$info['name']] = new DibiColumnInfo($reflector, $info);
|
$this->columns[] = $this->names[$info['name']] = new DibiColumnInfo($reflector, $info);
|
||||||
|
@@ -85,7 +85,7 @@ class DibiTableInfo extends DibiObject
|
|||||||
public function getColumnNames()
|
public function getColumnNames()
|
||||||
{
|
{
|
||||||
$this->initColumns();
|
$this->initColumns();
|
||||||
$res = array();
|
$res = [];
|
||||||
foreach ($this->columns as $column) {
|
foreach ($this->columns as $column) {
|
||||||
$res[] = $column->getName();
|
$res[] = $column->getName();
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ class DibiTableInfo extends DibiObject
|
|||||||
protected function initColumns()
|
protected function initColumns()
|
||||||
{
|
{
|
||||||
if ($this->columns === NULL) {
|
if ($this->columns === NULL) {
|
||||||
$this->columns = array();
|
$this->columns = [];
|
||||||
foreach ($this->reflector->getColumns($this->name) as $info) {
|
foreach ($this->reflector->getColumns($this->name) as $info) {
|
||||||
$this->columns[strtolower($info['name'])] = new DibiColumnInfo($this->reflector, $info);
|
$this->columns[strtolower($info['name'])] = new DibiColumnInfo($this->reflector, $info);
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ class DibiTableInfo extends DibiObject
|
|||||||
{
|
{
|
||||||
if ($this->indexes === NULL) {
|
if ($this->indexes === NULL) {
|
||||||
$this->initColumns();
|
$this->initColumns();
|
||||||
$this->indexes = array();
|
$this->indexes = [];
|
||||||
foreach ($this->reflector->getIndexes($this->name) as $info) {
|
foreach ($this->reflector->getIndexes($this->name) as $info) {
|
||||||
foreach ($info['columns'] as $key => $name) {
|
foreach ($info['columns'] as $key => $name) {
|
||||||
$info['columns'][$key] = $this->columns[strtolower($name)];
|
$info['columns'][$key] = $this->columns[strtolower($name)];
|
||||||
|
@@ -32,7 +32,7 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
private $driver;
|
private $driver;
|
||||||
|
|
||||||
/** @var array Translate table */
|
/** @var array Translate table */
|
||||||
private $types = array();
|
private $types = [];
|
||||||
|
|
||||||
/** @var DibiResultInfo */
|
/** @var DibiResultInfo */
|
||||||
private $meta;
|
private $meta;
|
||||||
@@ -47,7 +47,7 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
private $rowFactory;
|
private $rowFactory;
|
||||||
|
|
||||||
/** @var array format */
|
/** @var array format */
|
||||||
private $formats = array();
|
private $formats = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,10 +229,10 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
$this->seek((int) $offset);
|
$this->seek((int) $offset);
|
||||||
$row = $this->fetch();
|
$row = $this->fetch();
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
return array(); // empty result set
|
return []; // empty result set
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array();
|
$data = [];
|
||||||
do {
|
do {
|
||||||
if ($limit === 0) {
|
if ($limit === 0) {
|
||||||
break;
|
break;
|
||||||
@@ -265,7 +265,7 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
$this->seek(0);
|
$this->seek(0);
|
||||||
$row = $this->fetch();
|
$row = $this->fetch();
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
return array(); // empty result set
|
return []; // empty result set
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = NULL;
|
$data = NULL;
|
||||||
@@ -333,7 +333,7 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
$this->seek(0);
|
$this->seek(0);
|
||||||
$row = $this->fetch();
|
$row = $this->fetch();
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
return array(); // empty result set
|
return []; // empty result set
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = NULL;
|
$data = NULL;
|
||||||
@@ -410,10 +410,10 @@ class DibiResult extends DibiObject implements IDataSource
|
|||||||
$this->seek(0);
|
$this->seek(0);
|
||||||
$row = $this->fetch();
|
$row = $this->fetch();
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
return array(); // empty result set
|
return []; // empty result set
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array();
|
$data = [];
|
||||||
|
|
||||||
if ($value === NULL) {
|
if ($value === NULL) {
|
||||||
if ($key !== NULL) {
|
if ($key !== NULL) {
|
||||||
|
@@ -50,7 +50,7 @@ final class DibiTranslator extends DibiObject
|
|||||||
public function __construct(DibiConnection $connection)
|
public function __construct(DibiConnection $connection)
|
||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->identifiers = new DibiHashMap(array($this, 'delimite'));
|
$this->identifiers = new DibiHashMap([$this, 'delimite']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ final class DibiTranslator extends DibiObject
|
|||||||
$comment = FALSE;
|
$comment = FALSE;
|
||||||
|
|
||||||
// iterate
|
// iterate
|
||||||
$sql = array();
|
$sql = [];
|
||||||
while ($cursor < count($this->args)) {
|
while ($cursor < count($this->args)) {
|
||||||
$arg = $this->args[$cursor];
|
$arg = $this->args[$cursor];
|
||||||
$cursor++;
|
$cursor++;
|
||||||
@@ -116,7 +116,7 @@ final class DibiTranslator extends DibiObject
|
|||||||
)/xs',
|
)/xs',
|
||||||
*/ // note: this can change $this->args & $this->cursor & ...
|
*/ // note: this can change $this->args & $this->cursor & ...
|
||||||
. preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z~][a-zA-Z0-9~]{0,5})|(\?))/s',
|
. preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z~][a-zA-Z0-9~]{0,5})|(\?))/s',
|
||||||
array($this, 'cb'),
|
[$this, 'cb'],
|
||||||
substr($arg, $toSkip)
|
substr($arg, $toSkip)
|
||||||
);
|
);
|
||||||
if (preg_last_error()) {
|
if (preg_last_error()) {
|
||||||
@@ -199,7 +199,7 @@ final class DibiTranslator extends DibiObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$vx = $kx = array();
|
$vx = $kx = [];
|
||||||
switch ($modifier) {
|
switch ($modifier) {
|
||||||
case 'and':
|
case 'and':
|
||||||
case 'or': // key=val AND key IS NULL AND ...
|
case 'or': // key=val AND key IS NULL AND ...
|
||||||
@@ -401,7 +401,7 @@ final class DibiTranslator extends DibiObject
|
|||||||
$value = substr($value, 0, $toSkip)
|
$value = substr($value, 0, $toSkip)
|
||||||
. preg_replace_callback(
|
. preg_replace_callback(
|
||||||
'/(?=[`[\'":])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?))/s',
|
'/(?=[`[\'":])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?))/s',
|
||||||
array($this, 'cb'),
|
[$this, 'cb'],
|
||||||
substr($value, $toSkip)
|
substr($value, $toSkip)
|
||||||
);
|
);
|
||||||
if (preg_last_error()) {
|
if (preg_last_error()) {
|
||||||
|
@@ -46,13 +46,13 @@ class dibi
|
|||||||
DESC = 'DESC';
|
DESC = 'DESC';
|
||||||
|
|
||||||
/** @var DibiConnection[] Connection registry storage for DibiConnection objects */
|
/** @var DibiConnection[] Connection registry storage for DibiConnection objects */
|
||||||
private static $registry = array();
|
private static $registry = [];
|
||||||
|
|
||||||
/** @var DibiConnection Current connection */
|
/** @var DibiConnection Current connection */
|
||||||
private static $connection;
|
private static $connection;
|
||||||
|
|
||||||
/** @var array @see addHandler */
|
/** @var array @see addHandler */
|
||||||
private static $handlers = array();
|
private static $handlers = [];
|
||||||
|
|
||||||
/** @var string Last SQL command @see dibi::query() */
|
/** @var string Last SQL command @see dibi::query() */
|
||||||
public static $sql;
|
public static $sql;
|
||||||
@@ -89,7 +89,7 @@ class dibi
|
|||||||
* @return DibiConnection
|
* @return DibiConnection
|
||||||
* @throws DibiException
|
* @throws DibiException
|
||||||
*/
|
*/
|
||||||
public static function connect($config = array(), $name = 0)
|
public static function connect($config = [], $name = 0)
|
||||||
{
|
{
|
||||||
return self::$connection = self::$registry[$name] = new DibiConnection($config, $name);
|
return self::$connection = self::$registry[$name] = new DibiConnection($config, $name);
|
||||||
}
|
}
|
||||||
@@ -376,7 +376,7 @@ class dibi
|
|||||||
//if ($name = 'select', 'update', ...') {
|
//if ($name = 'select', 'update', ...') {
|
||||||
// return self::command()->$name($args);
|
// return self::command()->$name($args);
|
||||||
//}
|
//}
|
||||||
return call_user_func_array(array(self::getConnection(), $name), $args);
|
return call_user_func_array([self::getConnection(), $name], $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -399,7 +399,7 @@ class dibi
|
|||||||
public static function select($args)
|
public static function select($args)
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
return call_user_func_array(array(self::getConnection(), 'select'), $args);
|
return call_user_func_array([self::getConnection(), 'select'], $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -485,13 +485,39 @@ class dibi
|
|||||||
$highlighter = "#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is";
|
$highlighter = "#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is";
|
||||||
if (PHP_SAPI === 'cli') {
|
if (PHP_SAPI === 'cli') {
|
||||||
if (substr(getenv('TERM'), 0, 5) === 'xterm') {
|
if (substr(getenv('TERM'), 0, 5) === 'xterm') {
|
||||||
$sql = preg_replace_callback($highlighter, array('dibi', 'cliHighlightCallback'), $sql);
|
$sql = preg_replace_callback($highlighter, function ($m) {
|
||||||
|
if (!empty($m[1])) { // comment
|
||||||
|
return "\033[1;30m" . $m[1] . "\033[0m";
|
||||||
|
|
||||||
|
} elseif (!empty($m[2])) { // error
|
||||||
|
return "\033[1;31m" . $m[2] . "\033[0m";
|
||||||
|
|
||||||
|
} elseif (!empty($m[3])) { // most important keywords
|
||||||
|
return "\033[1;34m" . $m[3] . "\033[0m";
|
||||||
|
|
||||||
|
} elseif (!empty($m[4])) { // other keywords
|
||||||
|
return "\033[1;32m" . $m[4] . "\033[0m";
|
||||||
|
}
|
||||||
|
}, $sql);
|
||||||
}
|
}
|
||||||
echo trim($sql) . "\n\n";
|
echo trim($sql) . "\n\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$sql = htmlSpecialChars($sql);
|
$sql = htmlSpecialChars($sql);
|
||||||
$sql = preg_replace_callback($highlighter, array('dibi', 'highlightCallback'), $sql);
|
$sql = preg_replace_callback($highlighter, function ($m) {
|
||||||
|
if (!empty($m[1])) { // comment
|
||||||
|
return '<em style="color:gray">' . $m[1] . '</em>';
|
||||||
|
|
||||||
|
} elseif (!empty($m[2])) { // error
|
||||||
|
return '<strong style="color:red">' . $m[2] . '</strong>';
|
||||||
|
|
||||||
|
} elseif (!empty($m[3])) { // most important keywords
|
||||||
|
return '<strong style="color:blue">' . $m[3] . '</strong>';
|
||||||
|
|
||||||
|
} elseif (!empty($m[4])) { // other keywords
|
||||||
|
return '<strong style="color:green">' . $m[4] . '</strong>';
|
||||||
|
}
|
||||||
|
}, $sql);
|
||||||
echo '<pre class="dump">', trim($sql), "</pre>\n\n";
|
echo '<pre class="dump">', trim($sql), "</pre>\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -503,38 +529,4 @@ class dibi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static function highlightCallback($matches)
|
|
||||||
{
|
|
||||||
if (!empty($matches[1])) { // comment
|
|
||||||
return '<em style="color:gray">' . $matches[1] . '</em>';
|
|
||||||
|
|
||||||
} elseif (!empty($matches[2])) { // error
|
|
||||||
return '<strong style="color:red">' . $matches[2] . '</strong>';
|
|
||||||
|
|
||||||
} elseif (!empty($matches[3])) { // most important keywords
|
|
||||||
return '<strong style="color:blue">' . $matches[3] . '</strong>';
|
|
||||||
|
|
||||||
} elseif (!empty($matches[4])) { // other keywords
|
|
||||||
return '<strong style="color:green">' . $matches[4] . '</strong>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static function cliHighlightCallback($matches)
|
|
||||||
{
|
|
||||||
if (!empty($matches[1])) { // comment
|
|
||||||
return "\033[1;30m" . $matches[1] . "\033[0m";
|
|
||||||
|
|
||||||
} elseif (!empty($matches[2])) { // error
|
|
||||||
return "\033[1;31m" . $matches[2] . "\033[0m";
|
|
||||||
|
|
||||||
} elseif (!empty($matches[3])) { // most important keywords
|
|
||||||
return "\033[1;34m" . $matches[3] . "\033[0m";
|
|
||||||
|
|
||||||
} elseif (!empty($matches[4])) { // other keywords
|
|
||||||
return "\033[1;32m" . $matches[4] . "\033[0m";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -71,7 +71,7 @@ class DibiDriverException extends DibiException
|
|||||||
*/
|
*/
|
||||||
public static function tryError()
|
public static function tryError()
|
||||||
{
|
{
|
||||||
set_error_handler(array(__CLASS__, '_errorHandler'), E_ALL);
|
set_error_handler([__CLASS__, '_errorHandler'], E_ALL);
|
||||||
self::$errorMsg = NULL;
|
self::$errorMsg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,13 +118,13 @@ class DibiPcreException extends Exception
|
|||||||
{
|
{
|
||||||
public function __construct($message = '%msg.')
|
public function __construct($message = '%msg.')
|
||||||
{
|
{
|
||||||
static $messages = array(
|
static $messages = [
|
||||||
PREG_INTERNAL_ERROR => 'Internal error',
|
PREG_INTERNAL_ERROR => 'Internal error',
|
||||||
PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted',
|
PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted',
|
||||||
PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted',
|
PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted',
|
||||||
PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data',
|
PREG_BAD_UTF8_ERROR => 'Malformed UTF-8 data',
|
||||||
5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR
|
5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR
|
||||||
);
|
];
|
||||||
$code = preg_last_error();
|
$code = preg_last_error();
|
||||||
parent::__construct(str_replace('%msg', isset($messages[$code]) ? $messages[$code] : 'Unknown error', $message), $code);
|
parent::__construct(str_replace('%msg', isset($messages[$code]) ? $messages[$code] : 'Unknown error', $message), $code);
|
||||||
}
|
}
|
||||||
|
@@ -12,9 +12,9 @@ $conn = new DibiConnection($config);
|
|||||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||||
|
|
||||||
|
|
||||||
$conn->query('INSERT INTO products', array(
|
$conn->query('INSERT INTO products', [
|
||||||
'title' => 'Test product',
|
'title' => 'Test product',
|
||||||
));
|
]);
|
||||||
Assert::same(1, $conn->getAffectedRows());
|
Assert::same(1, $conn->getAffectedRows());
|
||||||
|
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ test(function () use ($config) {
|
|||||||
|
|
||||||
|
|
||||||
test(function () use ($config) { // lazy
|
test(function () use ($config) { // lazy
|
||||||
$conn = new DibiConnection($config + array('lazy' => TRUE));
|
$conn = new DibiConnection($config + ['lazy' => TRUE]);
|
||||||
Assert::false($conn->isConnected());
|
Assert::false($conn->isConnected());
|
||||||
|
|
||||||
$conn->query('SELECT 1');
|
$conn->query('SELECT 1');
|
||||||
|
@@ -29,43 +29,43 @@ Assert::same('Chair', $res->fetchSingle());
|
|||||||
|
|
||||||
// fetch complete result set
|
// fetch complete result set
|
||||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
new DibiRow(array('product_id' => num(1), 'title' => 'Chair')),
|
new DibiRow(['product_id' => num(1), 'title' => 'Chair']),
|
||||||
new DibiRow(array('product_id' => num(2), 'title' => 'Table')),
|
new DibiRow(['product_id' => num(2), 'title' => 'Table']),
|
||||||
new DibiRow(array('product_id' => num(3), 'title' => 'Computer')),
|
new DibiRow(['product_id' => num(3), 'title' => 'Computer']),
|
||||||
), $res->fetchAll());
|
], $res->fetchAll());
|
||||||
|
|
||||||
|
|
||||||
// fetch complete result set like pairs key => value
|
// fetch complete result set like pairs key => value
|
||||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||||
Assert::same(
|
Assert::same(
|
||||||
array(1 => 'Chair', 'Table', 'Computer'),
|
[1 => 'Chair', 'Table', 'Computer'],
|
||||||
$res->fetchPairs('product_id', 'title')
|
$res->fetchPairs('product_id', 'title')
|
||||||
);
|
);
|
||||||
|
|
||||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||||
Assert::same(
|
Assert::same(
|
||||||
array(1 => 'Chair', 'Table', 'Computer'),
|
[1 => 'Chair', 'Table', 'Computer'],
|
||||||
$res->fetchPairs()
|
$res->fetchPairs()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// fetch row by row
|
// fetch row by row
|
||||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
new DibiRow(array('product_id' => num(1), 'title' => 'Chair')),
|
new DibiRow(['product_id' => num(1), 'title' => 'Chair']),
|
||||||
new DibiRow(array('product_id' => num(2), 'title' => 'Table')),
|
new DibiRow(['product_id' => num(2), 'title' => 'Table']),
|
||||||
new DibiRow(array('product_id' => num(3), 'title' => 'Computer')),
|
new DibiRow(['product_id' => num(3), 'title' => 'Computer']),
|
||||||
), iterator_to_array($res));
|
], iterator_to_array($res));
|
||||||
|
|
||||||
|
|
||||||
// fetch complete result set like association array
|
// fetch complete result set like association array
|
||||||
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
$res = $conn->query('SELECT * FROM [products] ORDER BY product_id');
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Chair' => new DibiRow(array('product_id' => num(1), 'title' => 'Chair')),
|
'Chair' => new DibiRow(['product_id' => num(1), 'title' => 'Chair']),
|
||||||
'Table' => new DibiRow(array('product_id' => num(2), 'title' => 'Table')),
|
'Table' => new DibiRow(['product_id' => num(2), 'title' => 'Table']),
|
||||||
'Computer' => new DibiRow(array('product_id' => num(3), 'title' => 'Computer')),
|
'Computer' => new DibiRow(['product_id' => num(3), 'title' => 'Computer']),
|
||||||
), $res->fetchAssoc('title'));
|
], $res->fetchAssoc('title'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -88,242 +88,242 @@ function query($conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => array(
|
'Arnold Rimmer' => [
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
'Dave Lister' => array(
|
'Dave Lister' => [
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
'Kristine Kochanski' => array(
|
'Kristine Kochanski' => [
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
), query($conn)->fetchAssoc('name,title'));
|
], query($conn)->fetchAssoc('name,title'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => array(
|
'Arnold Rimmer' => [
|
||||||
array(
|
[
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
'Dave Lister' => array(
|
'Dave Lister' => [
|
||||||
array(
|
[
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
'Kristine Kochanski' => array(
|
'Kristine Kochanski' => [
|
||||||
array(
|
[
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
), query($conn)->fetchAssoc('name,#,title'));
|
], query($conn)->fetchAssoc('name,#,title'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => array(
|
'Arnold Rimmer' => [
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Arnold Rimmer',
|
'name' => 'Arnold Rimmer',
|
||||||
'amount' => num(7.0),
|
'amount' => num(7.0),
|
||||||
),
|
],
|
||||||
'Dave Lister' => array(
|
'Dave Lister' => [
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Dave Lister',
|
'name' => 'Dave Lister',
|
||||||
'amount' => num(3.0),
|
'amount' => num(3.0),
|
||||||
),
|
],
|
||||||
'Kristine Kochanski' => array(
|
'Kristine Kochanski' => [
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Kristine Kochanski',
|
'name' => 'Kristine Kochanski',
|
||||||
'amount' => num(5.0),
|
'amount' => num(5.0),
|
||||||
),
|
],
|
||||||
), query($conn)->fetchAssoc('name,=,title'));
|
], query($conn)->fetchAssoc('name,=,title'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => new DibiRow(array(
|
'Arnold Rimmer' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Arnold Rimmer',
|
'name' => 'Arnold Rimmer',
|
||||||
'amount' => num(7.0),
|
'amount' => num(7.0),
|
||||||
)),
|
]),
|
||||||
'Dave Lister' => new DibiRow(array(
|
'Dave Lister' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Dave Lister',
|
'name' => 'Dave Lister',
|
||||||
'amount' => num(3.0),
|
'amount' => num(3.0),
|
||||||
)),
|
]),
|
||||||
'Kristine Kochanski' => new DibiRow(array(
|
'Kristine Kochanski' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Kristine Kochanski',
|
'name' => 'Kristine Kochanski',
|
||||||
'amount' => num(5.0),
|
'amount' => num(5.0),
|
||||||
)),
|
]),
|
||||||
), query($conn)->fetchAssoc('name,@,title'));
|
], query($conn)->fetchAssoc('name,@,title'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
new DibiRow(array(
|
new DibiRow([
|
||||||
'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
new DibiRow(array(
|
new DibiRow([
|
||||||
'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
new DibiRow(array(
|
new DibiRow([
|
||||||
'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
), query($conn)->fetchAssoc('@,='));
|
], query($conn)->fetchAssoc('@,='));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => array(
|
'Arnold Rimmer' => [
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Arnold Rimmer',
|
'name' => 'Arnold Rimmer',
|
||||||
'amount' => num(7.0),
|
'amount' => num(7.0),
|
||||||
),
|
],
|
||||||
'Dave Lister' => array(
|
'Dave Lister' => [
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Dave Lister',
|
'name' => 'Dave Lister',
|
||||||
'amount' => num(3.0),
|
'amount' => num(3.0),
|
||||||
),
|
],
|
||||||
'Kristine Kochanski' => array(
|
'Kristine Kochanski' => [
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Kristine Kochanski',
|
'name' => 'Kristine Kochanski',
|
||||||
'amount' => num(5.0),
|
'amount' => num(5.0),
|
||||||
),
|
],
|
||||||
), query($conn)->fetchAssoc('name,=,title,@'));
|
], query($conn)->fetchAssoc('name,=,title,@'));
|
||||||
|
|
||||||
|
|
||||||
// old syntax
|
// old syntax
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => array(
|
'Arnold Rimmer' => [
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
'Dave Lister' => array(
|
'Dave Lister' => [
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
'Kristine Kochanski' => array(
|
'Kristine Kochanski' => [
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
), query($conn)->fetchAssoc('name|title'));
|
], query($conn)->fetchAssoc('name|title'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => array(
|
'Arnold Rimmer' => [
|
||||||
array(
|
[
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
'Dave Lister' => array(
|
'Dave Lister' => [
|
||||||
array(
|
[
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
'Kristine Kochanski' => array(
|
'Kristine Kochanski' => [
|
||||||
array(
|
[
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
), query($conn)->fetchAssoc('name[]title'));
|
], query($conn)->fetchAssoc('name[]title'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => new DibiRow(array(
|
'Arnold Rimmer' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Arnold Rimmer',
|
'name' => 'Arnold Rimmer',
|
||||||
'amount' => num(7.0),
|
'amount' => num(7.0),
|
||||||
)),
|
]),
|
||||||
'Dave Lister' => new DibiRow(array(
|
'Dave Lister' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Dave Lister',
|
'name' => 'Dave Lister',
|
||||||
'amount' => num(3.0),
|
'amount' => num(3.0),
|
||||||
)),
|
]),
|
||||||
'Kristine Kochanski' => new DibiRow(array(
|
'Kristine Kochanski' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Kristine Kochanski',
|
'name' => 'Kristine Kochanski',
|
||||||
'amount' => num(5.0),
|
'amount' => num(5.0),
|
||||||
)),
|
]),
|
||||||
), query($conn)->fetchAssoc('name->title'));
|
], query($conn)->fetchAssoc('name->title'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => new DibiRow(array(
|
'Arnold Rimmer' => new DibiRow([
|
||||||
'title' => array('Chair' => 'Arnold Rimmer', 'Computer' => 'Arnold Rimmer'),
|
'title' => ['Chair' => 'Arnold Rimmer', 'Computer' => 'Arnold Rimmer'],
|
||||||
'name' => 'Arnold Rimmer',
|
'name' => 'Arnold Rimmer',
|
||||||
'amount' => num(7.0),
|
'amount' => num(7.0),
|
||||||
)),
|
]),
|
||||||
'Dave Lister' => new DibiRow(array(
|
'Dave Lister' => new DibiRow([
|
||||||
'title' => array('Table' => 'Dave Lister'),
|
'title' => ['Table' => 'Dave Lister'],
|
||||||
'name' => 'Dave Lister',
|
'name' => 'Dave Lister',
|
||||||
'amount' => num(3.0),
|
'amount' => num(3.0),
|
||||||
)),
|
]),
|
||||||
'Kristine Kochanski' => new DibiRow(array(
|
'Kristine Kochanski' => new DibiRow([
|
||||||
'title' => array('Computer' => 'Kristine Kochanski'),
|
'title' => ['Computer' => 'Kristine Kochanski'],
|
||||||
'name' => 'Kristine Kochanski',
|
'name' => 'Kristine Kochanski',
|
||||||
'amount' => num(5.0),
|
'amount' => num(5.0),
|
||||||
)),
|
]),
|
||||||
), query($conn)->fetchAssoc('name->title=name'));
|
], query($conn)->fetchAssoc('name->title=name'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
), query($conn)->fetchAssoc('[]'));
|
], query($conn)->fetchAssoc('[]'));
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => new DibiRow(array(
|
'Arnold Rimmer' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Arnold Rimmer',
|
'name' => 'Arnold Rimmer',
|
||||||
'amount' => num(7.0),
|
'amount' => num(7.0),
|
||||||
)),
|
]),
|
||||||
'Dave Lister' => new DibiRow(array(
|
'Dave Lister' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Dave Lister',
|
'name' => 'Dave Lister',
|
||||||
'amount' => num(3.0),
|
'amount' => num(3.0),
|
||||||
)),
|
]),
|
||||||
'Kristine Kochanski' => new DibiRow(array(
|
'Kristine Kochanski' => new DibiRow([
|
||||||
'title' => array(
|
'title' => [
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
'name' => 'Kristine Kochanski',
|
'name' => 'Kristine Kochanski',
|
||||||
'amount' => num(5.0),
|
'amount' => num(5.0),
|
||||||
)),
|
]),
|
||||||
), query($conn)->fetchAssoc('name->title->'));
|
], query($conn)->fetchAssoc('name->title->'));
|
||||||
|
@@ -30,9 +30,9 @@ Assert::exception(function () use ($conn) {
|
|||||||
|
|
||||||
$conn->begin();
|
$conn->begin();
|
||||||
Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||||
$conn->query('INSERT INTO [products]', array(
|
$conn->query('INSERT INTO [products]', [
|
||||||
'title' => 'Test product',
|
'title' => 'Test product',
|
||||||
));
|
]);
|
||||||
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||||
$conn->rollback();
|
$conn->rollback();
|
||||||
Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||||
@@ -41,8 +41,8 @@ Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSing
|
|||||||
|
|
||||||
|
|
||||||
$conn->begin();
|
$conn->begin();
|
||||||
$conn->query('INSERT INTO [products]', array(
|
$conn->query('INSERT INTO [products]', [
|
||||||
'title' => 'Test product',
|
'title' => 'Test product',
|
||||||
));
|
]);
|
||||||
$conn->commit();
|
$conn->commit();
|
||||||
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||||
|
@@ -54,9 +54,9 @@ FROM (SELECT * FROM products) t
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$ds->select(array('product_id'));
|
$ds->select(['product_id']);
|
||||||
$ds->orderBy(array('product_id' => dibi::ASC));
|
$ds->orderBy(['product_id' => dibi::ASC]);
|
||||||
$ds->where(array('product_id = 1'));
|
$ds->where(['product_id = 1']);
|
||||||
Assert::match(
|
Assert::match(
|
||||||
reformat("
|
reformat("
|
||||||
SELECT [product_id]
|
SELECT [product_id]
|
||||||
@@ -79,11 +79,11 @@ FROM (SELECT * FROM products) t
|
|||||||
Assert::same(1, $ds->toDataSource()->count());
|
Assert::same(1, $ds->toDataSource()->count());
|
||||||
|
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
new DibiRow(array(
|
new DibiRow([
|
||||||
'product_id' => 1,
|
'product_id' => 1,
|
||||||
)),
|
]),
|
||||||
), iterator_to_array($ds));
|
], iterator_to_array($ds));
|
||||||
|
|
||||||
Assert::match(
|
Assert::match(
|
||||||
reformat("
|
reformat("
|
||||||
@@ -117,32 +117,32 @@ FROM (SELECT [title] FROM [products]) t'),
|
|||||||
(string) $ds
|
(string) $ds
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert::equal(new DibiRow(array(
|
Assert::equal(new DibiRow([
|
||||||
'product_id' => 1,
|
'product_id' => 1,
|
||||||
'title' => 'Chair',
|
'title' => 'Chair',
|
||||||
)), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetch());
|
]), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetch());
|
||||||
|
|
||||||
Assert::same(1, $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchSingle());
|
Assert::same(1, $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchSingle());
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
array(1 => 'Chair', 'Table', 'Computer'),
|
[1 => 'Chair', 'Table', 'Computer'],
|
||||||
$conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchPairs()
|
$conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchPairs()
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
1 => new DibiRow(array(
|
1 => new DibiRow([
|
||||||
'product_id' => 1,
|
'product_id' => 1,
|
||||||
'title' => 'Chair',
|
'title' => 'Chair',
|
||||||
)),
|
]),
|
||||||
new DibiRow(array(
|
new DibiRow([
|
||||||
'product_id' => 2,
|
'product_id' => 2,
|
||||||
'title' => 'Table',
|
'title' => 'Table',
|
||||||
)),
|
]),
|
||||||
new DibiRow(array(
|
new DibiRow([
|
||||||
'product_id' => 3,
|
'product_id' => 3,
|
||||||
'title' => 'Computer',
|
'title' => 'Computer',
|
||||||
)),
|
]),
|
||||||
), $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchAssoc('product_id'));
|
], $conn->dataSource('SELECT * FROM products ORDER BY product_id')->fetchAssoc('product_id'));
|
||||||
|
|
||||||
|
|
||||||
$ds = new DibiDataSource('products', $conn);
|
$ds = new DibiDataSource('products', $conn);
|
||||||
|
@@ -29,31 +29,31 @@ Assert::equal('Chair', $res->fetchSingle());
|
|||||||
|
|
||||||
// fetch complete result set
|
// fetch complete result set
|
||||||
$res = $conn->select('*')->from('products')->orderBy('product_id');
|
$res = $conn->select('*')->from('products')->orderBy('product_id');
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
new DibiRow(array('product_id' => num(1), 'title' => 'Chair')),
|
new DibiRow(['product_id' => num(1), 'title' => 'Chair']),
|
||||||
new DibiRow(array('product_id' => num(2), 'title' => 'Table')),
|
new DibiRow(['product_id' => num(2), 'title' => 'Table']),
|
||||||
new DibiRow(array('product_id' => num(3), 'title' => 'Computer')),
|
new DibiRow(['product_id' => num(3), 'title' => 'Computer']),
|
||||||
), $res->fetchAll());
|
], $res->fetchAll());
|
||||||
|
|
||||||
|
|
||||||
// more complex association array
|
// more complex association array
|
||||||
if ($config['system'] !== 'odbc') {
|
if ($config['system'] !== 'odbc') {
|
||||||
$res = $conn->select(array('products.title' => 'title', 'customers.name' => 'name'))->select('orders.amount')->as('amount')
|
$res = $conn->select(['products.title' => 'title', 'customers.name' => 'name'])->select('orders.amount')->as('amount')
|
||||||
->from('products')
|
->from('products')
|
||||||
->innerJoin('orders')->using('(product_id)')
|
->innerJoin('orders')->using('(product_id)')
|
||||||
->innerJoin('customers')->using('([customer_id])')
|
->innerJoin('customers')->using('([customer_id])')
|
||||||
->orderBy('order_id');
|
->orderBy('order_id');
|
||||||
|
|
||||||
Assert::equal(array(
|
Assert::equal([
|
||||||
'Arnold Rimmer' => array(
|
'Arnold Rimmer' => [
|
||||||
'Chair' => new DibiRow(array('title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0))),
|
'Chair' => new DibiRow(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
||||||
),
|
],
|
||||||
'Dave Lister' => array(
|
'Dave Lister' => [
|
||||||
'Table' => new DibiRow(array('title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0))),
|
'Table' => new DibiRow(['title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
||||||
),
|
],
|
||||||
'Kristine Kochanski' => array(
|
'Kristine Kochanski' => [
|
||||||
'Computer' => new DibiRow(array('title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0))),
|
'Computer' => new DibiRow(['title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
||||||
),
|
],
|
||||||
), $res->fetchAssoc('name,title'));
|
], $res->fetchAssoc('name,title'));
|
||||||
}
|
}
|
||||||
|
@@ -8,11 +8,11 @@ require __DIR__ . '/bootstrap.php';
|
|||||||
$conn = new DibiConnection($config);
|
$conn = new DibiConnection($config);
|
||||||
|
|
||||||
|
|
||||||
$arr = array(
|
$arr = [
|
||||||
'title' => 'Super Product',
|
'title' => 'Super Product',
|
||||||
'price' => 12,
|
'price' => 12,
|
||||||
'brand' => NULL,
|
'brand' => NULL,
|
||||||
);
|
];
|
||||||
|
|
||||||
$fluent = $conn->insert('table', $arr)
|
$fluent = $conn->insert('table', $arr)
|
||||||
->setFlag('IGNORE')->setFlag('DELAYED');
|
->setFlag('IGNORE')->setFlag('DELAYED');
|
||||||
|
@@ -14,7 +14,7 @@ $min = 5;
|
|||||||
$fluent = $conn->select('*')
|
$fluent = $conn->select('*')
|
||||||
->select('a')
|
->select('a')
|
||||||
->select('b')->as('bAlias')
|
->select('b')->as('bAlias')
|
||||||
->select(array('c', 'd', 'e'))
|
->select(['c', 'd', 'e'])
|
||||||
->select('%n', 'd');
|
->select('%n', 'd');
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
@@ -58,10 +58,10 @@ Assert::same(
|
|||||||
$fluent->where('col > %i', $max)
|
$fluent->where('col > %i', $max)
|
||||||
->or('col < %i', $min)
|
->or('col < %i', $min)
|
||||||
->where('active = 1')
|
->where('active = 1')
|
||||||
->where('col')->in(array(1, 2, 3))
|
->where('col')->in([1, 2, 3])
|
||||||
->orderBy('val')->asc()
|
->orderBy('val')->asc()
|
||||||
->orderBy('[val2] DESC')
|
->orderBy('[val2] DESC')
|
||||||
->orderBy(array('val3' => -1));
|
->orderBy(['val3' => -1]);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [anotherTable] AS [anotherAlias] INNER JOIN [table3] ON table.col = table3.col WHERE col > 10 OR col < 5 AND active = 1 AND [col] IN (1, 2, 3) ORDER BY [val] ASC , [val2] DESC , [val3] DESC'),
|
reformat('SELECT * , [a] , [b] AS [bAlias] , [c], [d], [e] , [d] FROM [anotherTable] AS [anotherAlias] INNER JOIN [table3] ON table.col = table3.col WHERE col > 10 OR col < 5 AND active = 1 AND [col] IN (1, 2, 3) ORDER BY [val] ASC , [val2] DESC , [val3] DESC'),
|
||||||
@@ -104,11 +104,11 @@ Assert::same(
|
|||||||
|
|
||||||
|
|
||||||
$fluent = $conn->select('*')
|
$fluent = $conn->select('*')
|
||||||
->select(array('x' => 'xAlias'))
|
->select(['x' => 'xAlias'])
|
||||||
->from('products')
|
->from('products')
|
||||||
->innerJoin('orders')->using('(product_id)')
|
->innerJoin('orders')->using('(product_id)')
|
||||||
->innerJoin('customers')->using('([customer_id])')
|
->innerJoin('customers')->using('([customer_id])')
|
||||||
->innerJoin('items')->using('(%n)', array('customer_id', 'order_id'));
|
->innerJoin('items')->using('(%n)', ['customer_id', 'order_id']);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * , [x] AS [xAlias] FROM [products] INNER JOIN [orders] USING (product_id) INNER JOIN [customers] USING ([customer_id]) INNER JOIN [items] USING ([customer_id], [order_id])'),
|
reformat('SELECT * , [x] AS [xAlias] FROM [products] INNER JOIN [orders] USING (product_id) INNER JOIN [customers] USING ([customer_id]) INNER JOIN [items] USING ([customer_id], [order_id])'),
|
||||||
@@ -129,9 +129,9 @@ Assert::same(
|
|||||||
|
|
||||||
|
|
||||||
$fluent = $conn->select('*')
|
$fluent = $conn->select('*')
|
||||||
->from(array('me' => 't'))
|
->from(['me' => 't'])
|
||||||
->where('col > %i', $max)
|
->where('col > %i', $max)
|
||||||
->where(array('x' => 'a', 'b', 'c'));
|
->where(['x' => 'a', 'b', 'c']);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * FROM [me] AS [t] WHERE col > 10 AND ([x] = \'a\') AND (b) AND (c)'),
|
reformat('SELECT * FROM [me] AS [t] WHERE col > 10 AND ([x] = \'a\') AND (b) AND (c)'),
|
||||||
|
@@ -8,11 +8,11 @@ require __DIR__ . '/bootstrap.php';
|
|||||||
$conn = new DibiConnection($config);
|
$conn = new DibiConnection($config);
|
||||||
|
|
||||||
|
|
||||||
$arr = array(
|
$arr = [
|
||||||
'title' => 'Super Product',
|
'title' => 'Super Product',
|
||||||
'price' => 12,
|
'price' => 12,
|
||||||
'brand' => NULL,
|
'brand' => NULL,
|
||||||
);
|
];
|
||||||
|
|
||||||
$fluent = $conn->update('table', $arr)
|
$fluent = $conn->update('table', $arr)
|
||||||
->setFlag('IGNORE')->setFlag('DELAYED');
|
->setFlag('IGNORE')->setFlag('DELAYED');
|
||||||
@@ -22,7 +22,7 @@ Assert::same(
|
|||||||
(string) $fluent
|
(string) $fluent
|
||||||
);
|
);
|
||||||
|
|
||||||
$fluent->set(array('another' => 123));
|
$fluent->set(['another' => 123]);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('UPDATE IGNORE DELAYED [table] SET [title]=\'Super Product\', [price]=12, [brand]=NULL , [another]=123'),
|
reformat('UPDATE IGNORE DELAYED [table] SET [title]=\'Super Product\', [price]=12, [brand]=NULL , [another]=123'),
|
||||||
|
@@ -24,14 +24,14 @@ $info = $conn->query('
|
|||||||
|
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
array('product_id', 'order_id', 'name', 'xxx'),
|
['product_id', 'order_id', 'name', 'xxx'],
|
||||||
$info->getColumnNames()
|
$info->getColumnNames()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if ($config['driver'] !== 'sqlite3' && $config['driver'] !== 'pdo') {
|
if ($config['driver'] !== 'sqlite3' && $config['driver'] !== 'pdo') {
|
||||||
Assert::same(
|
Assert::same(
|
||||||
array('products.product_id', 'orders.order_id', 'customers.name', 'xxx'),
|
['products.product_id', 'orders.order_id', 'customers.name', 'xxx'],
|
||||||
$info->getColumnNames(TRUE)
|
$info->getColumnNames(TRUE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ $res = $conn->query('SELECT * FROM [customers]');
|
|||||||
// auto-converts this column to integer
|
// auto-converts this column to integer
|
||||||
$res->setType('customer_id', Dibi::DATETIME, 'H:i j.n.Y');
|
$res->setType('customer_id', Dibi::DATETIME, 'H:i j.n.Y');
|
||||||
|
|
||||||
Assert::equal(new DibiRow(array(
|
Assert::equal(new DibiRow([
|
||||||
'customer_id' => new DibiDateTime('1970-01-01 01:00:01'),
|
'customer_id' => new DibiDateTime('1970-01-01 01:00:01'),
|
||||||
'name' => 'Dave Lister',
|
'name' => 'Dave Lister',
|
||||||
)), $res->fetch());
|
]), $res->fetch());
|
||||||
|
@@ -35,8 +35,8 @@ Assert::false(isset($row['missing']));
|
|||||||
|
|
||||||
|
|
||||||
// to array
|
// to array
|
||||||
Assert::same(array('product_id' => 1, 'title' => 'Chair'), iterator_to_array($row));
|
Assert::same(['product_id' => 1, 'title' => 'Chair'], iterator_to_array($row));
|
||||||
Assert::same(array('product_id' => 1, 'title' => 'Chair'), $row->toArray());
|
Assert::same(['product_id' => 1, 'title' => 'Chair'], $row->toArray());
|
||||||
|
|
||||||
// counting
|
// counting
|
||||||
Assert::same(2, count($row));
|
Assert::same(2, count($row));
|
||||||
|
@@ -8,24 +8,24 @@ use Tester\Assert;
|
|||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
$conn = new DibiConnection($config + array('formatDateTime' => "'Y-m-d H:i:s'", 'formatDate' => "'Y-m-d'"));
|
$conn = new DibiConnection($config + ['formatDateTime' => "'Y-m-d H:i:s'", 'formatDate' => "'Y-m-d'"]);
|
||||||
|
|
||||||
|
|
||||||
// dibi detects INSERT or REPLACE command & booleans
|
// dibi detects INSERT or REPLACE command & booleans
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat("REPLACE INTO [products] ([title], [price]) VALUES ('Drticka', 318)"),
|
reformat("REPLACE INTO [products] ([title], [price]) VALUES ('Drticka', 318)"),
|
||||||
$conn->translate('REPLACE INTO [products]', array(
|
$conn->translate('REPLACE INTO [products]', [
|
||||||
'title' => 'Drticka',
|
'title' => 'Drticka',
|
||||||
'price' => 318,
|
'price' => 318,
|
||||||
)));
|
]));
|
||||||
|
|
||||||
|
|
||||||
// multiple INSERT command
|
// multiple INSERT command
|
||||||
$array = array(
|
$array = [
|
||||||
'title' => 'Super Product',
|
'title' => 'Super Product',
|
||||||
'price' => 12,
|
'price' => 12,
|
||||||
'brand' => NULL,
|
'brand' => NULL,
|
||||||
);
|
];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('INSERT INTO [products] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL)'),
|
reformat('INSERT INTO [products] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL)'),
|
||||||
$conn->translate('INSERT INTO [products]', $array, $array, $array)
|
$conn->translate('INSERT INTO [products]', $array, $array, $array)
|
||||||
@@ -33,11 +33,11 @@ Assert::same(
|
|||||||
|
|
||||||
|
|
||||||
// multiple INSERT command II
|
// multiple INSERT command II
|
||||||
$array = array(
|
$array = [
|
||||||
array('pole' => 'hodnota1', 'bit' => 1),
|
['pole' => 'hodnota1', 'bit' => 1],
|
||||||
array('pole' => 'hodnota2', 'bit' => 1),
|
['pole' => 'hodnota2', 'bit' => 1],
|
||||||
array('pole' => 'hodnota3', 'bit' => 1),
|
['pole' => 'hodnota3', 'bit' => 1],
|
||||||
);
|
];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('INSERT INTO [products] ([pole], [bit]) VALUES (\'hodnota1\', 1) , (\'hodnota2\', 1) , (\'hodnota3\', 1)'),
|
reformat('INSERT INTO [products] ([pole], [bit]) VALUES (\'hodnota1\', 1) , (\'hodnota2\', 1) , (\'hodnota3\', 1)'),
|
||||||
$conn->translate('INSERT INTO [products] %ex', $array)
|
$conn->translate('INSERT INTO [products] %ex', $array)
|
||||||
@@ -47,14 +47,14 @@ Assert::same(
|
|||||||
// dibi detects UPDATE command
|
// dibi detects UPDATE command
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat("UPDATE [colors] SET [color]='blue', [order]=12 WHERE [id]=123"),
|
reformat("UPDATE [colors] SET [color]='blue', [order]=12 WHERE [id]=123"),
|
||||||
$conn->translate('UPDATE [colors] SET', array(
|
$conn->translate('UPDATE [colors] SET', [
|
||||||
'color' => 'blue',
|
'color' => 'blue',
|
||||||
'order' => 12,
|
'order' => 12,
|
||||||
), 'WHERE [id]=%i', 123));
|
], 'WHERE [id]=%i', 123));
|
||||||
|
|
||||||
|
|
||||||
// IN array
|
// IN array
|
||||||
$array = array(1, 2, 3);
|
$array = [1, 2, 3];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * FROM [people] WHERE [id] IN ( 1, 2, 3 )'),
|
reformat('SELECT * FROM [people] WHERE [id] IN ( 1, 2, 3 )'),
|
||||||
$conn->translate('SELECT * FROM [people] WHERE [id] IN (', $array, ')')
|
$conn->translate('SELECT * FROM [people] WHERE [id] IN (', $array, ')')
|
||||||
@@ -75,7 +75,7 @@ Assert::same(
|
|||||||
|
|
||||||
// invalid input
|
// invalid input
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->translate('SELECT %s', (object) array(123), ', %m', 123);
|
$conn->translate('SELECT %s', (object) [123], ', %m', 123);
|
||||||
}, 'DibiException', 'SQL translate error');
|
}, 'DibiException', 'SQL translate error');
|
||||||
Assert::same('SELECT **Unexpected type object** , **Unknown or invalid modifier %m**', $e->getSql());
|
Assert::same('SELECT **Unexpected type object** , **Unknown or invalid modifier %m**', $e->getSql());
|
||||||
|
|
||||||
@@ -86,16 +86,16 @@ Assert::same(
|
|||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('TEST ([cond] > 2) OR ([cond2] = \'3\') OR (cond3 < RAND())'),
|
reformat('TEST ([cond] > 2) OR ([cond2] = \'3\') OR (cond3 < RAND())'),
|
||||||
$conn->translate('TEST %or', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'))
|
$conn->translate('TEST %or', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'])
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('TEST ([cond] > 2) AND ([cond2] = \'3\') AND (cond3 < RAND())'),
|
reformat('TEST ([cond] > 2) AND ([cond2] = \'3\') AND (cond3 < RAND())'),
|
||||||
$conn->translate('TEST %and', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'))
|
$conn->translate('TEST %and', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'])
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
$where = array();
|
$where = [];
|
||||||
$where[] = '[age] > 20';
|
$where[] = '[age] > 20';
|
||||||
$where[] = '[email] IS NOT NULL';
|
$where[] = '[email] IS NOT NULL';
|
||||||
Assert::same(
|
Assert::same(
|
||||||
@@ -104,17 +104,17 @@ Assert::same(
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$where = array();
|
$where = [];
|
||||||
$where['age'] = NULL;
|
$where['age'] = NULL;
|
||||||
$where['email'] = 'ahoj';
|
$where['email'] = 'ahoj';
|
||||||
$where['id%l'] = array(10, 20, 30);
|
$where['id%l'] = [10, 20, 30];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * FROM [table] WHERE ([age] IS NULL) AND ([email] = \'ahoj\') AND ([id] IN (10, 20, 30))'),
|
reformat('SELECT * FROM [table] WHERE ([age] IS NULL) AND ([email] = \'ahoj\') AND ([id] IN (10, 20, 30))'),
|
||||||
$conn->translate('SELECT * FROM [table] WHERE %and', $where)
|
$conn->translate('SELECT * FROM [table] WHERE %and', $where)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$where = array();
|
$where = [];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * FROM [table] WHERE 1=1'),
|
reformat('SELECT * FROM [table] WHERE 1=1'),
|
||||||
$conn->translate('SELECT * FROM [table] WHERE %and', $where)
|
$conn->translate('SELECT * FROM [table] WHERE %and', $where)
|
||||||
@@ -122,14 +122,14 @@ Assert::same(
|
|||||||
|
|
||||||
|
|
||||||
// ORDER BY array
|
// ORDER BY array
|
||||||
$order = array(
|
$order = [
|
||||||
'field1' => 'asc',
|
'field1' => 'asc',
|
||||||
'field2' => 'desc',
|
'field2' => 'desc',
|
||||||
'field3' => 1,
|
'field3' => 1,
|
||||||
'field4' => -1,
|
'field4' => -1,
|
||||||
'field5' => TRUE,
|
'field5' => TRUE,
|
||||||
'field6' => FALSE,
|
'field6' => FALSE,
|
||||||
);
|
];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC'),
|
reformat('SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC'),
|
||||||
$conn->translate('SELECT * FROM [people] ORDER BY %by', $order)
|
$conn->translate('SELECT * FROM [people] ORDER BY %by', $order)
|
||||||
@@ -138,10 +138,10 @@ Assert::same(
|
|||||||
|
|
||||||
// with limit = 2
|
// with limit = 2
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat(array(
|
reformat([
|
||||||
'odbc' => 'SELECT TOP 2 * FROM (SELECT * FROM [products] ) t',
|
'odbc' => 'SELECT TOP 2 * FROM (SELECT * FROM [products] ) t',
|
||||||
'SELECT * FROM [products] LIMIT 2',
|
'SELECT * FROM [products] LIMIT 2',
|
||||||
)),
|
]),
|
||||||
$conn->translate('SELECT * FROM [products] %lmt', 2)
|
$conn->translate('SELECT * FROM [products] %lmt', 2)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -158,11 +158,11 @@ if ($config['system'] === 'odbc') {
|
|||||||
|
|
||||||
// with offset = 50
|
// with offset = 50
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat(array(
|
reformat([
|
||||||
'mysql' => 'SELECT * FROM `products` LIMIT 18446744073709551615 OFFSET 50',
|
'mysql' => 'SELECT * FROM `products` LIMIT 18446744073709551615 OFFSET 50',
|
||||||
'pgsql' => 'SELECT * FROM "products" OFFSET 50',
|
'pgsql' => 'SELECT * FROM "products" OFFSET 50',
|
||||||
'SELECT * FROM [products] LIMIT -1 OFFSET 50',
|
'SELECT * FROM [products] LIMIT -1 OFFSET 50',
|
||||||
)),
|
]),
|
||||||
$conn->translate('SELECT * FROM [products] %ofs', 50)
|
$conn->translate('SELECT * FROM [products] %ofs', 50)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -171,11 +171,11 @@ if ($config['system'] === 'odbc') {
|
|||||||
|
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat(array(
|
reformat([
|
||||||
'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES (#09/26/1212 00:00:00#, #12/31/1969 22:13:20#, #09/26/1212#, #09/26/1212 00:00:00#, #12/31/1969#, #12/31/1969 22:13:20#, #09/26/1212 00:00:00#, #09/26/1212#, #09/26/1212 00:00:00#, NULL, NULL)',
|
'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES (#09/26/1212 00:00:00#, #12/31/1969 22:13:20#, #09/26/1212#, #09/26/1212 00:00:00#, #12/31/1969#, #12/31/1969 22:13:20#, #09/26/1212 00:00:00#, #09/26/1212#, #09/26/1212 00:00:00#, NULL, NULL)',
|
||||||
"INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES ('1212-09-26 00:00:00', '1969-12-31 22:13:20', '1212-09-26', '1212-09-26 00:00:00', '1969-12-31', '1969-12-31 22:13:20', '1212-09-26 00:00:00', '1212-09-26', '1212-09-26 00:00:00', NULL, NULL)",
|
"INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES ('1212-09-26 00:00:00', '1969-12-31 22:13:20', '1212-09-26', '1212-09-26 00:00:00', '1969-12-31', '1969-12-31 22:13:20', '1212-09-26 00:00:00', '1212-09-26', '1212-09-26 00:00:00', NULL, NULL)",
|
||||||
)),
|
]),
|
||||||
$conn->translate('INSERT INTO test', array(
|
$conn->translate('INSERT INTO test', [
|
||||||
'a2' => new DibiDateTime('1212-09-26'),
|
'a2' => new DibiDateTime('1212-09-26'),
|
||||||
'a4' => new DibiDateTime(-10000),
|
'a4' => new DibiDateTime(-10000),
|
||||||
'b1%d' => '1212-09-26',
|
'b1%d' => '1212-09-26',
|
||||||
@@ -187,17 +187,17 @@ Assert::same(
|
|||||||
'b7%t' => new DateTime('1212-09-26'),
|
'b7%t' => new DateTime('1212-09-26'),
|
||||||
'b8%d' => NULL,
|
'b8%d' => NULL,
|
||||||
'b9%t' => NULL,
|
'b9%t' => NULL,
|
||||||
)));
|
]));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// like
|
// like
|
||||||
$args = array(
|
$args = [
|
||||||
'SELECT * FROM products WHERE (title LIKE %like~ AND title LIKE %~like) OR title LIKE %~like~',
|
'SELECT * FROM products WHERE (title LIKE %like~ AND title LIKE %~like) OR title LIKE %~like~',
|
||||||
'C',
|
'C',
|
||||||
'r',
|
'r',
|
||||||
"a\n%_\\'\"",
|
"a\n%_\\'\"",
|
||||||
);
|
];
|
||||||
|
|
||||||
if ($config['system'] === 'pgsql') {
|
if ($config['system'] === 'pgsql') {
|
||||||
$conn->query('SET escape_string_warning = off'); // do not log warnings
|
$conn->query('SET escape_string_warning = off'); // do not log warnings
|
||||||
@@ -215,11 +215,11 @@ if ($config['system'] === 'pgsql') {
|
|||||||
);
|
);
|
||||||
} elseif ($config['driver'] !== 'sqlite') { // sqlite2
|
} elseif ($config['driver'] !== 'sqlite') { // sqlite2
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat(array(
|
reformat([
|
||||||
'sqlite' => "SELECT * FROM products WHERE (title LIKE 'C%' ESCAPE '\\' AND title LIKE '%r' ESCAPE '\\') OR title LIKE '%a\n\\%\\_\\\\''\"%' ESCAPE '\\'",
|
'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[%][_]\\''\"%'",
|
'odbc' => "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])
|
$conn->translate($args[0], $args[1], $args[2], $args[3])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -231,7 +231,7 @@ $e = Assert::exception(function () use ($conn) {
|
|||||||
Assert::same('SELECT **Alone quote**', $e->getSql());
|
Assert::same('SELECT **Alone quote**', $e->getSql());
|
||||||
|
|
||||||
Assert::match(
|
Assert::match(
|
||||||
reformat(array(
|
reformat([
|
||||||
'mysql' => "SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT
|
'mysql' => "SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT
|
||||||
CONCAT(last_name, ', ', first_name) AS full_name
|
CONCAT(last_name, ', ', first_name) AS full_name
|
||||||
GROUP BY `user`
|
GROUP BY `user`
|
||||||
@@ -248,7 +248,7 @@ INTO OUTFILE '/tmp/result''.txt'
|
|||||||
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
|
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
|
||||||
LINES TERMINATED BY '\\n'
|
LINES TERMINATED BY '\\n'
|
||||||
",
|
",
|
||||||
)),
|
]),
|
||||||
$conn->translate('%sql', 'SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT
|
$conn->translate('%sql', 'SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT
|
||||||
CONCAT(last_name, ", ", first_name) AS full_name
|
CONCAT(last_name, ", ", first_name) AS full_name
|
||||||
GROUP BY [user]
|
GROUP BY [user]
|
||||||
@@ -263,25 +263,25 @@ LINES TERMINATED BY '\\n'
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
$array1 = array(1, 2, 3);
|
$array1 = [1, 2, 3];
|
||||||
$array2 = array('one', 'two', 'three');
|
$array2 = ['one', 'two', 'three'];
|
||||||
$array3 = array(
|
$array3 = [
|
||||||
'col1' => 'one',
|
'col1' => 'one',
|
||||||
'col2' => 'two',
|
'col2' => 'two',
|
||||||
'col3' => 'three',
|
'col3' => 'three',
|
||||||
);
|
];
|
||||||
$array4 = array(
|
$array4 = [
|
||||||
'a' => 12,
|
'a' => 12,
|
||||||
'b' => NULL,
|
'b' => NULL,
|
||||||
'c' => new DibiDateTime('12.3.2007'),
|
'c' => new DibiDateTime('12.3.2007'),
|
||||||
'd' => 'any string',
|
'd' => 'any string',
|
||||||
);
|
];
|
||||||
|
|
||||||
$array5 = array('RAND()', '[col1] > [col2]');
|
$array5 = ['RAND()', '[col1] > [col2]'];
|
||||||
|
|
||||||
|
|
||||||
Assert::match(
|
Assert::match(
|
||||||
reformat(array(
|
reformat([
|
||||||
'mysql' => "SELECT *
|
'mysql' => "SELECT *
|
||||||
FROM `db`.`table`
|
FROM `db`.`table`
|
||||||
WHERE (`test`.`a` LIKE '1995-03-01'
|
WHERE (`test`.`a` LIKE '1995-03-01'
|
||||||
@@ -362,20 +362,20 @@ WHERE ([test].[a] LIKE '1995-03-01'
|
|||||||
OR [str_null]=NULL
|
OR [str_null]=NULL
|
||||||
OR [str_not_null]='hello'
|
OR [str_not_null]='hello'
|
||||||
LIMIT 10",
|
LIMIT 10",
|
||||||
)),
|
]),
|
||||||
|
|
||||||
$conn->translate('SELECT *
|
$conn->translate('SELECT *
|
||||||
FROM [db.table]
|
FROM [db.table]
|
||||||
WHERE ([test.a] LIKE %d', '1995-03-01', '
|
WHERE ([test.a] LIKE %d', '1995-03-01', '
|
||||||
OR [b1] IN (', $array1, ')
|
OR [b1] IN (', $array1, ')
|
||||||
OR [b2] IN (%s', $array1, ')
|
OR [b2] IN (%s', $array1, ')
|
||||||
OR [b3] IN (%s', array(), ')
|
OR [b3] IN (%s', [], ')
|
||||||
OR [b4] IN (', $array2, ')
|
OR [b4] IN (', $array2, ')
|
||||||
OR [b5] IN (%n', $array3, ')
|
OR [b5] IN (%n', $array3, ')
|
||||||
OR [b6] IN %l', $array3, '
|
OR [b6] IN %l', $array3, '
|
||||||
OR [b7] IN %in', array(), '
|
OR [b7] IN %in', [], '
|
||||||
OR [b8] IN (%sql', $array5, ')
|
OR [b8] IN (%sql', $array5, ')
|
||||||
OR [b9] IN (', array(), ")
|
OR [b9] IN (', [], ")
|
||||||
AND [c] = 'embedded '' string'
|
AND [c] = 'embedded '' string'
|
||||||
OR [d]=%i", 10.3, '
|
OR [d]=%i", 10.3, '
|
||||||
OR [e]=%i', NULL, '
|
OR [e]=%i', NULL, '
|
||||||
@@ -389,40 +389,40 @@ LIMIT 10')
|
|||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('TEST [cond] > 2 [cond2] = \'3\' cond3 < RAND() 123'),
|
reformat('TEST [cond] > 2 [cond2] = \'3\' cond3 < RAND() 123'),
|
||||||
$conn->translate('TEST %ex', array('[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'), 123)
|
$conn->translate('TEST %ex', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'], 123)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('TEST ([cond] > 2) OR ([cond2] > 3) OR ([cond3] = 10 + 1)'),
|
reformat('TEST ([cond] > 2) OR ([cond2] > 3) OR ([cond3] = 10 + 1)'),
|
||||||
$conn->translate('TEST %or', array('`cond` > 2', array('[cond2] > %i', '3'), 'cond3%sql' => array('10 + 1')))
|
$conn->translate('TEST %or', ['`cond` > 2', ['[cond2] > %i', '3'], 'cond3%sql' => ['10 + 1']])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('TEST ([cond] = 2) OR ([cond3] = RAND())'),
|
reformat('TEST ([cond] = 2) OR ([cond3] = RAND())'),
|
||||||
$conn->translate('TEST %or', array('cond' => 2, 'cond3%sql' => 'RAND()'))
|
$conn->translate('TEST %or', ['cond' => 2, 'cond3%sql' => 'RAND()'])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('TEST ([cond1] 3) OR ([cond2] RAND()) OR ([cond3] LIKE \'string\')'),
|
reformat('TEST ([cond1] 3) OR ([cond2] RAND()) OR ([cond3] LIKE \'string\')'),
|
||||||
$conn->translate('TEST %or', array('cond1%ex' => 3, 'cond2%ex' => 'RAND()', 'cond3%ex' => array('LIKE %s', 'string')))
|
$conn->translate('TEST %or', ['cond1%ex' => 3, 'cond2%ex' => 'RAND()', 'cond3%ex' => ['LIKE %s', 'string']])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat(array(
|
reformat([
|
||||||
'odbc' => 'SELECT TOP 10 * FROM (SELECT * FROM [test] WHERE [id] LIKE \'%d%t\' ) t',
|
'odbc' => 'SELECT TOP 10 * FROM (SELECT * FROM [test] WHERE [id] LIKE \'%d%t\' ) t',
|
||||||
'SELECT * FROM [test] WHERE [id] LIKE \'%d%t\' LIMIT 10',
|
'SELECT * FROM [test] WHERE [id] LIKE \'%d%t\' LIMIT 10',
|
||||||
)),
|
]),
|
||||||
$conn->translate("SELECT * FROM [test] WHERE %n LIKE '%d%t' %lmt", 'id', 10)
|
$conn->translate("SELECT * FROM [test] WHERE %n LIKE '%d%t' %lmt", 'id', 10)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$where = array(
|
$where = [
|
||||||
'tablename.column' => 1,
|
'tablename.column' => 1,
|
||||||
);
|
];
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * FROM [tablename] WHERE ([tablename].[column] = 1)'),
|
reformat('SELECT * FROM [tablename] WHERE ([tablename].[column] = 1)'),
|
||||||
$conn->translate('SELECT * FROM [tablename] WHERE %and', $where)
|
$conn->translate('SELECT * FROM [tablename] WHERE %and', $where)
|
||||||
@@ -447,39 +447,39 @@ Assert::same(
|
|||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('INSERT INTO [products] ([product_id], [title]) VALUES (1, SHA1(\'Test product\')) , (1, SHA1(\'Test product\'))'),
|
reformat('INSERT INTO [products] ([product_id], [title]) VALUES (1, SHA1(\'Test product\')) , (1, SHA1(\'Test product\'))'),
|
||||||
$conn->translate('INSERT INTO [products]', array(
|
$conn->translate('INSERT INTO [products]', [
|
||||||
'product_id' => 1,
|
'product_id' => 1,
|
||||||
'title' => array('SHA1(%s)', 'Test product'),
|
'title' => ['SHA1(%s)', 'Test product'],
|
||||||
), array(
|
], [
|
||||||
'product_id' => 1,
|
'product_id' => 1,
|
||||||
'title' => array('SHA1(%s)', 'Test product'),
|
'title' => ['SHA1(%s)', 'Test product'],
|
||||||
))
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('UPDATE [products] [product_id]=1, [title]=SHA1(\'Test product\')'),
|
reformat('UPDATE [products] [product_id]=1, [title]=SHA1(\'Test product\')'),
|
||||||
$conn->translate('UPDATE [products]', array(
|
$conn->translate('UPDATE [products]', [
|
||||||
'product_id' => 1,
|
'product_id' => 1,
|
||||||
'title' => array('SHA1(%s)', 'Test product'),
|
'title' => ['SHA1(%s)', 'Test product'],
|
||||||
))
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$array6 = array(
|
$array6 = [
|
||||||
'id' => array(1, 2, 3, 4),
|
'id' => [1, 2, 3, 4],
|
||||||
'text' => array('ahoj', 'jak', 'se', array('SUM(%i)', '5')),
|
'text' => ['ahoj', 'jak', 'se', ['SUM(%i)', '5']],
|
||||||
'num%i' => array('1', ''),
|
'num%i' => ['1', ''],
|
||||||
);
|
];
|
||||||
$conn->translate('INSERT INTO test %m', $array6);
|
$conn->translate('INSERT INTO test %m', $array6);
|
||||||
}, 'DibiException', 'SQL translate error');
|
}, 'DibiException', 'SQL translate error');
|
||||||
Assert::same('INSERT INTO test **Multi-insert array "num%i" is different.**', $e->getSql());
|
Assert::same('INSERT INTO test **Multi-insert array "num%i" is different.**', $e->getSql());
|
||||||
|
|
||||||
$array6 = array(
|
$array6 = [
|
||||||
'id' => array(1, 2, 3, 4),
|
'id' => [1, 2, 3, 4],
|
||||||
'text' => array('ahoj', 'jak', 'se', array('SUM(%i)', '5')),
|
'text' => ['ahoj', 'jak', 'se', ['SUM(%i)', '5']],
|
||||||
'num%i' => array('1', '', 10.3, 1),
|
'num%i' => ['1', '', 10.3, 1],
|
||||||
);
|
];
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('INSERT INTO test ([id], [text], [num]) VALUES (1, \'ahoj\', 1), (2, \'jak\', 0), (3, \'se\', 10), (4, SUM(5), 1)'),
|
reformat('INSERT INTO test ([id], [text], [num]) VALUES (1, \'ahoj\', 1), (2, \'jak\', 0), (3, \'se\', 10), (4, SUM(5), 1)'),
|
||||||
@@ -487,10 +487,10 @@ Assert::same(
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$by = array(
|
$by = [
|
||||||
array('funkce(nazev_pole) ASC'),
|
['funkce(nazev_pole) ASC'],
|
||||||
'jine_pole' => 'DESC',
|
'jine_pole' => 'DESC',
|
||||||
);
|
];
|
||||||
|
|
||||||
Assert::same(
|
Assert::same(
|
||||||
reformat('SELECT * FROM table ORDER BY funkce(nazev_pole) ASC, [jine_pole] DESC'),
|
reformat('SELECT * FROM table ORDER BY funkce(nazev_pole) ASC, [jine_pole] DESC'),
|
||||||
@@ -513,12 +513,12 @@ setLocale(LC_ALL, 'czech');
|
|||||||
Assert::same(
|
Assert::same(
|
||||||
reformat("UPDATE [colors] SET [color]='blue', [price]=-12.4, [spec]=-9E-005, [spec2]=1000, [spec3]=10000, [spec4]=10000 WHERE [price]=123.5"),
|
reformat("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', array(
|
$conn->translate('UPDATE [colors] SET', [
|
||||||
'color' => 'blue',
|
'color' => 'blue',
|
||||||
'price' => -12.4,
|
'price' => -12.4,
|
||||||
'spec%f' => '-9E-005',
|
'spec%f' => '-9E-005',
|
||||||
'spec2%f' => 1000.00,
|
'spec2%f' => 1000.00,
|
||||||
'spec3%i' => 10000,
|
'spec3%i' => 10000,
|
||||||
'spec4' => 10000,
|
'spec4' => 10000,
|
||||||
), 'WHERE [price]=%f', 123.5)
|
], 'WHERE [price]=%f', 123.5)
|
||||||
);
|
);
|
||||||
|
@@ -22,7 +22,7 @@ Assert::same(3, count($meta->getTables()));
|
|||||||
|
|
||||||
$names = $meta->getTableNames();
|
$names = $meta->getTableNames();
|
||||||
sort($names);
|
sort($names);
|
||||||
Assert::equal(array('customers', 'orders', 'products'), $names);
|
Assert::equal(['customers', 'orders', 'products'], $names);
|
||||||
|
|
||||||
Assert::false($meta->hasTable('xxxx'));
|
Assert::false($meta->hasTable('xxxx'));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user