mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 20:57:36 +02:00
coding style: fixes in code
This commit is contained in:
@@ -143,7 +143,7 @@ class Panel implements Tracy\IBarPanel
|
|||||||
#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
|
#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
|
||||||
<h1>Queries: ' . count($this->events)
|
<h1>Queries: ' . count($this->events)
|
||||||
. ($totalTime === null ? '' : ', time: ' . number_format($totalTime * 1000, 1, '.', ' ') . ' ms') . ', '
|
. ($totalTime === null ? '' : ', time: ' . number_format($totalTime * 1000, 1, '.', ' ') . ' ms') . ', '
|
||||||
. htmlSpecialChars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')
|
. htmlspecialchars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')
|
||||||
. ($connection->getConfig('host') ? ' @ ' . $connection->getConfig('host') : '')) . '</h1>
|
. ($connection->getConfig('host') ? ' @ ' . $connection->getConfig('host') : '')) . '</h1>
|
||||||
<div class="tracy-inner tracy-DibiProfiler">
|
<div class="tracy-inner tracy-DibiProfiler">
|
||||||
<table>
|
<table>
|
||||||
|
@@ -48,7 +48,6 @@ class Connection
|
|||||||
* - run (bool) => enable profiler?
|
* - run (bool) => enable profiler?
|
||||||
* - file => file to log
|
* - file => file to log
|
||||||
* - substitutes (array) => map of driver specific substitutes (under development)
|
* - substitutes (array) => map of driver specific substitutes (under development)
|
||||||
|
|
||||||
* @param mixed connection parameters
|
* @param mixed connection parameters
|
||||||
* @param string connection name
|
* @param string connection name
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@@ -10,7 +10,6 @@ namespace Dibi;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of IDataSource for dibi.
|
* Default implementation of IDataSource for dibi.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class DataSource implements IDataSource
|
class DataSource implements IDataSource
|
||||||
{
|
{
|
||||||
|
@@ -33,7 +33,7 @@ class DateTime extends \DateTime
|
|||||||
|
|
||||||
public function modifyClone($modify = '')
|
public function modifyClone($modify = '')
|
||||||
{
|
{
|
||||||
$dolly = clone($this);
|
$dolly = clone $this;
|
||||||
return $modify ? $dolly->modify($modify) : $dolly;
|
return $modify ? $dolly->modify($modify) : $dolly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -713,9 +713,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getTriggers($table = null)
|
public function getTriggers($table = null)
|
||||||
{
|
{
|
||||||
$q = "SELECT TRIM(RDB\$TRIGGER_NAME)
|
$q = 'SELECT TRIM(RDB$TRIGGER_NAME)
|
||||||
FROM RDB\$TRIGGERS
|
FROM RDB$TRIGGERS
|
||||||
WHERE RDB\$SYSTEM_FLAG = 0";
|
WHERE RDB$SYSTEM_FLAG = 0';
|
||||||
$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);
|
||||||
@@ -786,9 +786,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getProcedures()
|
public function getProcedures()
|
||||||
{
|
{
|
||||||
$res = $this->query("
|
$res = $this->query('
|
||||||
SELECT TRIM(RDB\$PROCEDURE_NAME)
|
SELECT TRIM(RDB$PROCEDURE_NAME)
|
||||||
FROM RDB\$PROCEDURES;"
|
FROM RDB$PROCEDURES;'
|
||||||
);
|
);
|
||||||
$procedures = [];
|
$procedures = [];
|
||||||
while ($row = $res->fetch(false)) {
|
while ($row = $res->fetch(false)) {
|
||||||
@@ -804,10 +804,10 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getGenerators()
|
public function getGenerators()
|
||||||
{
|
{
|
||||||
$res = $this->query("
|
$res = $this->query('
|
||||||
SELECT TRIM(RDB\$GENERATOR_NAME)
|
SELECT TRIM(RDB$GENERATOR_NAME)
|
||||||
FROM RDB\$GENERATORS
|
FROM RDB$GENERATORS
|
||||||
WHERE RDB\$SYSTEM_FLAG = 0;"
|
WHERE RDB$SYSTEM_FLAG = 0;'
|
||||||
);
|
);
|
||||||
$generators = [];
|
$generators = [];
|
||||||
while ($row = $res->fetch(false)) {
|
while ($row = $res->fetch(false)) {
|
||||||
@@ -823,10 +823,10 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
$res = $this->query("
|
$res = $this->query('
|
||||||
SELECT TRIM(RDB\$FUNCTION_NAME)
|
SELECT TRIM(RDB$FUNCTION_NAME)
|
||||||
FROM RDB\$FUNCTIONS
|
FROM RDB$FUNCTIONS
|
||||||
WHERE RDB\$SYSTEM_FLAG = 0;"
|
WHERE RDB$SYSTEM_FLAG = 0;'
|
||||||
);
|
);
|
||||||
$functions = [];
|
$functions = [];
|
||||||
while ($row = $res->fetch(false)) {
|
while ($row = $res->fetch(false)) {
|
||||||
|
@@ -357,7 +357,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
/**
|
/**
|
||||||
* Moves cursor position without fetching row.
|
* Moves cursor position without fetching row.
|
||||||
* @param int the 0-based cursor pos to seek to
|
* @param int the 0-based cursor pos to seek to
|
||||||
* @return boolean true on success, false if unable to seek to specified record
|
* @return bool true on success, false if unable to seek to specified record
|
||||||
*/
|
*/
|
||||||
public function seek($row)
|
public function seek($row)
|
||||||
{
|
{
|
||||||
|
@@ -69,12 +69,12 @@ class MsSqlReflector implements Dibi\Reflector
|
|||||||
if (!is_array($row) || count($row) < 1) {
|
if (!is_array($row) || count($row) < 1) {
|
||||||
if ($fallback) {
|
if ($fallback) {
|
||||||
$row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escapeIdentifier($table)}")->fetch(false);
|
$row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escapeIdentifier($table)}")->fetch(false);
|
||||||
$count = intval($row[0]);
|
$count = (int) ($row[0]);
|
||||||
} else {
|
} else {
|
||||||
$count = false;
|
$count = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$count = intval($row[0]);
|
$count = (int) ($row[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
|
@@ -274,7 +274,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("#m/d/Y#");
|
return $value->format('#m/d/Y#');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -287,7 +287,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format("#m/d/Y H:i:s.u#");
|
return $value->format('#m/d/Y H:i:s.u#');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -41,7 +41,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
|
|||||||
private $autocommit = true;
|
private $autocommit = true;
|
||||||
|
|
||||||
/** @var string Date and datetime format */
|
/** @var string Date and datetime format */
|
||||||
private $fmtDate, $fmtDateTime;
|
private $fmtDate;
|
||||||
|
private $fmtDateTime;
|
||||||
|
|
||||||
/** @var int|false Number of affected rows */
|
/** @var int|false Number of affected rows */
|
||||||
private $affectedRows = false;
|
private $affectedRows = false;
|
||||||
|
@@ -348,7 +348,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
|
||||||
$value = new Dibi\DateTime($value);
|
$value = new Dibi\DateTime($value);
|
||||||
}
|
}
|
||||||
return $value->format($this->driverName === 'odbc' ? "#m/d/Y H:i:s.u#" : "'Y-m-d H:i:s.u'");
|
return $value->format($this->driverName === 'odbc' ? '#m/d/Y H:i:s.u#' : "'Y-m-d H:i:s.u'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -474,8 +474,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// intentionally break omitted
|
// break omitted
|
||||||
|
|
||||||
case 'odbc':
|
case 'odbc':
|
||||||
if ($offset) {
|
if ($offset) {
|
||||||
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
|
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
|
||||||
@@ -484,8 +483,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// intentionally break omitted
|
// break omitted
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Dibi\NotSupportedException('PDO or driver does not support applying limit or offset.');
|
throw new Dibi\NotSupportedException('PDO or driver does not support applying limit or offset.');
|
||||||
}
|
}
|
||||||
|
@@ -37,10 +37,12 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
|
|||||||
private $autoFree = true;
|
private $autoFree = true;
|
||||||
|
|
||||||
/** @var string Date and datetime format */
|
/** @var string Date and datetime format */
|
||||||
private $fmtDate, $fmtDateTime;
|
private $fmtDate;
|
||||||
|
private $fmtDateTime;
|
||||||
|
|
||||||
/** @var string character encoding */
|
/** @var string character encoding */
|
||||||
private $dbcharset, $charset;
|
private $dbcharset;
|
||||||
|
private $charset;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -105,7 +105,7 @@ class SqlsrvReflector implements Dibi\Reflector
|
|||||||
*/
|
*/
|
||||||
public function getIndexes($table)
|
public function getIndexes($table)
|
||||||
{
|
{
|
||||||
$keyUsagesRes = $this->driver->query(sprintf("EXEC [sys].[sp_helpindex] @objname = N%s", $this->driver->escapeText($table)));
|
$keyUsagesRes = $this->driver->query(sprintf('EXEC [sys].[sp_helpindex] @objname = N%s', $this->driver->escapeText($table)));
|
||||||
$keyUsages = [];
|
$keyUsages = [];
|
||||||
while ($row = $keyUsagesRes->fetch(true)) {
|
while ($row = $keyUsagesRes->fetch(true)) {
|
||||||
$keyUsages[$row['index_name']] = explode(',', $row['index_keys']);
|
$keyUsages[$row['index_name']] = explode(',', $row['index_keys']);
|
||||||
|
@@ -38,7 +38,7 @@ class Fluent implements IDataSource
|
|||||||
/** @var array */
|
/** @var array */
|
||||||
public static $masks = [
|
public static $masks = [
|
||||||
'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
|
'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
|
||||||
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET'],
|
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', ],
|
||||||
'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
|
'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
|
||||||
'INSERT' => ['INSERT', 'INTO', 'VALUES', 'SELECT'],
|
'INSERT' => ['INSERT', 'INTO', 'VALUES', 'SELECT'],
|
||||||
'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],
|
'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],
|
||||||
|
@@ -51,14 +51,14 @@ class Helpers
|
|||||||
if ($i === 0) {
|
if ($i === 0) {
|
||||||
echo "\n<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n";
|
echo "\n<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n";
|
||||||
foreach ($row as $col => $foo) {
|
foreach ($row as $col => $foo) {
|
||||||
echo "\t\t<th>" . htmlSpecialChars((string) $col) . "</th>\n";
|
echo "\t\t<th>" . htmlspecialchars((string) $col) . "</th>\n";
|
||||||
}
|
}
|
||||||
echo "\t</tr>\n</thead>\n<tbody>\n";
|
echo "\t</tr>\n</thead>\n<tbody>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "\t<tr>\n\t\t<th>", $i, "</th>\n";
|
echo "\t<tr>\n\t\t<th>", $i, "</th>\n";
|
||||||
foreach ($row as $col) {
|
foreach ($row as $col) {
|
||||||
echo "\t\t<td>", htmlSpecialChars((string) $col), "</td>\n";
|
echo "\t\t<td>", htmlspecialchars((string) $col), "</td>\n";
|
||||||
}
|
}
|
||||||
echo "\t</tr>\n";
|
echo "\t</tr>\n";
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ class Helpers
|
|||||||
echo trim($sql) . "\n\n";
|
echo trim($sql) . "\n\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$sql = htmlSpecialChars($sql);
|
$sql = htmlspecialchars($sql);
|
||||||
$sql = preg_replace_callback($highlighter, function ($m) {
|
$sql = preg_replace_callback($highlighter, function ($m) {
|
||||||
if (!empty($m[1])) { // comment
|
if (!empty($m[1])) { // comment
|
||||||
return '<em style="color:gray">' . $m[1] . '</em>';
|
return '<em style="color:gray">' . $m[1] . '</em>';
|
||||||
|
@@ -76,7 +76,7 @@ class Column
|
|||||||
public function getTable()
|
public function getTable()
|
||||||
{
|
{
|
||||||
if (empty($this->info['table']) || !$this->reflector) {
|
if (empty($this->info['table']) || !$this->reflector) {
|
||||||
throw new Dibi\Exception("Table is unknown or not available.");
|
throw new Dibi\Exception('Table is unknown or not available.');
|
||||||
}
|
}
|
||||||
return new Table($this->reflector, ['name' => $this->info['table']]);
|
return new Table($this->reflector, ['name' => $this->info['table']]);
|
||||||
}
|
}
|
||||||
|
@@ -340,14 +340,12 @@ final class Translator
|
|||||||
|
|
||||||
case 'in': // deprecated
|
case 'in': // deprecated
|
||||||
trigger_error('Modifier %in is deprecated, use %iN.', E_USER_DEPRECATED);
|
trigger_error('Modifier %in is deprecated, use %iN.', E_USER_DEPRECATED);
|
||||||
// intentionally break omitted
|
// break omitted
|
||||||
|
|
||||||
case 'iN': // signed int or null
|
case 'iN': // signed int or null
|
||||||
if ($value == '') {
|
if ($value == '') {
|
||||||
$value = null;
|
$value = null;
|
||||||
}
|
}
|
||||||
// intentionally break omitted
|
// break omitted
|
||||||
|
|
||||||
case 'i': // signed int
|
case 'i': // signed int
|
||||||
case 'u': // unsigned int, ignored
|
case 'u': // unsigned int, ignored
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
@@ -360,7 +358,7 @@ final class Translator
|
|||||||
} else {
|
} else {
|
||||||
return (string) (int) $value;
|
return (string) (int) $value;
|
||||||
}
|
}
|
||||||
|
// break omitted
|
||||||
case 'f': // float
|
case 'f': // float
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
@@ -369,7 +367,7 @@ final class Translator
|
|||||||
} else {
|
} else {
|
||||||
return rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
|
return rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
|
||||||
}
|
}
|
||||||
|
// break omitted
|
||||||
case 'd': // date
|
case 'd': // date
|
||||||
case 't': // datetime
|
case 't': // datetime
|
||||||
case 'dt': // datetime
|
case 'dt': // datetime
|
||||||
@@ -378,7 +376,7 @@ final class Translator
|
|||||||
} else {
|
} else {
|
||||||
return $modifier === 'd' ? $this->driver->escapeDate($value) : $this->driver->escapeDateTime($value);
|
return $modifier === 'd' ? $this->driver->escapeDate($value) : $this->driver->escapeDateTime($value);
|
||||||
}
|
}
|
||||||
|
// break omitted
|
||||||
case 'by':
|
case 'by':
|
||||||
case 'n': // composed identifier name
|
case 'n': // composed identifier name
|
||||||
return $this->identifiers->$value;
|
return $this->identifiers->$value;
|
||||||
|
@@ -49,12 +49,6 @@ class dibi
|
|||||||
FIELD_DATETIME = Type::DATETIME,
|
FIELD_DATETIME = Type::DATETIME,
|
||||||
FIELD_TIME = Type::TIME;
|
FIELD_TIME = Type::TIME;
|
||||||
|
|
||||||
/** @var Dibi\Connection[] Connection registry storage for DibiConnection objects */
|
|
||||||
private static $registry = [];
|
|
||||||
|
|
||||||
/** @var Dibi\Connection Current connection */
|
|
||||||
private static $connection;
|
|
||||||
|
|
||||||
/** @var string Last SQL command @see dibi::query() */
|
/** @var string Last SQL command @see dibi::query() */
|
||||||
public static $sql;
|
public static $sql;
|
||||||
|
|
||||||
@@ -70,6 +64,12 @@ class dibi
|
|||||||
/** @var string Default dibi driver */
|
/** @var string Default dibi driver */
|
||||||
public static $defaultDriver = 'mysqli';
|
public static $defaultDriver = 'mysqli';
|
||||||
|
|
||||||
|
/** @var Dibi\Connection[] Connection registry storage for DibiConnection objects */
|
||||||
|
private static $registry = [];
|
||||||
|
|
||||||
|
/** @var Dibi\Connection Current connection */
|
||||||
|
private static $connection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static class - cannot be instantiated.
|
* Static class - cannot be instantiated.
|
||||||
|
@@ -166,7 +166,7 @@ interface ResultDriver
|
|||||||
/**
|
/**
|
||||||
* Moves cursor position without fetching row.
|
* Moves cursor position without fetching row.
|
||||||
* @param int the 0-based cursor pos to seek to
|
* @param int the 0-based cursor pos to seek to
|
||||||
* @return boolean true on success, false if unable to seek to specified record
|
* @return bool true on success, false if unable to seek to specified record
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function seek($row);
|
function seek($row);
|
||||||
|
@@ -4,8 +4,8 @@
|
|||||||
* @dataProvider ../databases.ini
|
* @dataProvider ../databases.ini
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Tester\Assert;
|
|
||||||
use Dibi\Connection;
|
use Dibi\Connection;
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
@@ -4,8 +4,8 @@
|
|||||||
* @dataProvider ../databases.ini
|
* @dataProvider ../databases.ini
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Tester\Assert;
|
|
||||||
use Dibi\Row;
|
use Dibi\Row;
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
@@ -61,9 +61,9 @@ Assert::equal([
|
|||||||
|
|
||||||
|
|
||||||
// more complex association array
|
// more complex association array
|
||||||
function query($conn) {
|
function query($conn)
|
||||||
|
{
|
||||||
return $conn->query(in_array($conn->getConfig('system'), ['odbc', 'sqlsrv']) ? '
|
return $conn->query(in_array($conn->getConfig('system'), ['odbc', 'sqlsrv'], true) ? '
|
||||||
SELECT products.title, customers.name, orders.amount
|
SELECT products.title, customers.name, orders.amount
|
||||||
FROM ([products]
|
FROM ([products]
|
||||||
INNER JOIN [orders] ON [products.product_id] = [orders.product_id])
|
INNER JOIN [orders] ON [products.product_id] = [orders.product_id])
|
||||||
@@ -170,11 +170,11 @@ Assert::equal([
|
|||||||
Assert::equal([
|
Assert::equal([
|
||||||
new Row(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
new Row(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
|
||||||
new Row([
|
new Row([
|
||||||
'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
|
'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0), ]),
|
||||||
new Row([
|
new Row([
|
||||||
'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
|
'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0), ]),
|
||||||
new Row([
|
new Row([
|
||||||
'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
|
'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0), ]),
|
||||||
], query($conn)->fetchAssoc('@,='));
|
], query($conn)->fetchAssoc('@,='));
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Tester\Assert;
|
|
||||||
use Dibi\Row;
|
use Dibi\Row;
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Tester\Assert;
|
|
||||||
use Dibi\Fluent;
|
use Dibi\Fluent;
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
@@ -7,23 +7,29 @@ require __DIR__ . '/bootstrap.php';
|
|||||||
|
|
||||||
class MockDriver extends Dibi\Drivers\SqlsrvDriver
|
class MockDriver extends Dibi\Drivers\SqlsrvDriver
|
||||||
{
|
{
|
||||||
function __construct()
|
public function __construct()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
function connect(array &$config)
|
|
||||||
{}
|
|
||||||
|
|
||||||
function query($sql)
|
public function connect(array &$config)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function query($sql)
|
||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResultColumns()
|
|
||||||
|
public function getResultColumns()
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetch($assoc)
|
|
||||||
|
public function fetch($assoc)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -4,8 +4,8 @@
|
|||||||
* @dataProvider ../databases.ini
|
* @dataProvider ../databases.ini
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Tester\Assert;
|
|
||||||
use Dibi\Row;
|
use Dibi\Row;
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ Assert::equal([
|
|||||||
|
|
||||||
|
|
||||||
// more complex association array
|
// more complex association array
|
||||||
if (!in_array($config['system'], ['odbc', 'sqlsrv'])) {
|
if (!in_array($config['system'], ['odbc', 'sqlsrv'], true)) {
|
||||||
$res = $conn->select(['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)')
|
||||||
|
@@ -25,7 +25,7 @@ Assert::same(
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) {
|
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'], true)) {
|
||||||
Assert::same(
|
Assert::same(
|
||||||
['products.product_id', 'orders.order_id', 'customers.name', 'xXx'],
|
['products.product_id', 'orders.order_id', 'customers.name', 'xXx'],
|
||||||
$info->getColumnNames(true)
|
$info->getColumnNames(true)
|
||||||
@@ -36,18 +36,18 @@ if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) {
|
|||||||
$columns = $info->getColumns();
|
$columns = $info->getColumns();
|
||||||
|
|
||||||
Assert::same('product_id', $columns[0]->getName());
|
Assert::same('product_id', $columns[0]->getName());
|
||||||
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) {
|
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'], true)) {
|
||||||
Assert::same('products', $columns[0]->getTableName());
|
Assert::same('products', $columns[0]->getTableName());
|
||||||
}
|
}
|
||||||
Assert::null($columns[0]->getVendorInfo('xxx'));
|
Assert::null($columns[0]->getVendorInfo('xxx'));
|
||||||
if (!in_array($config['system'], ['sqlite', 'sqlsrv'])) {
|
if (!in_array($config['system'], ['sqlite', 'sqlsrv'], true)) {
|
||||||
Assert::same('i', $columns[0]->getType());
|
Assert::same('i', $columns[0]->getType());
|
||||||
}
|
}
|
||||||
Assert::null($columns[0]->isNullable());
|
Assert::null($columns[0]->isNullable());
|
||||||
|
|
||||||
Assert::same('xXx', $columns[3]->getName());
|
Assert::same('xXx', $columns[3]->getName());
|
||||||
Assert::null($columns[3]->getTableName());
|
Assert::null($columns[3]->getTableName());
|
||||||
if (!in_array($config['system'], ['sqlite', 'sqlsrv'])) {
|
if (!in_array($config['system'], ['sqlite', 'sqlsrv'], true)) {
|
||||||
Assert::same('i', $columns[0]->getType());
|
Assert::same('i', $columns[0]->getType());
|
||||||
}
|
}
|
||||||
Assert::null($columns[3]->isNullable());
|
Assert::null($columns[3]->isNullable());
|
||||||
|
@@ -1,17 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Tester\Assert;
|
|
||||||
use Dibi\Type;
|
use Dibi\Type;
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
|
||||||
class MockResult extends Dibi\Result
|
class MockResult extends Dibi\Result
|
||||||
{
|
{
|
||||||
function __construct()
|
public function __construct()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
function test($row)
|
|
||||||
|
public function test($row)
|
||||||
{
|
{
|
||||||
$normalize = new ReflectionMethod('Dibi\Result', 'normalize');
|
$normalize = new ReflectionMethod('Dibi\Result', 'normalize');
|
||||||
$normalize->setAccessible(true);
|
$normalize->setAccessible(true);
|
||||||
|
@@ -9,7 +9,7 @@ use Tester\Assert;
|
|||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
$conn = new Dibi\Connection($config);
|
$conn = new Dibi\Connection($config);
|
||||||
$conn->loadFile(__DIR__ . "/data/sqlsrv.insert.sql");
|
$conn->loadFile(__DIR__ . '/data/sqlsrv.insert.sql');
|
||||||
|
|
||||||
for ($i = 1; $i <= 5; $i++) {
|
for ($i = 1; $i <= 5; $i++) {
|
||||||
$conn->query('INSERT INTO %n DEFAULT VALUES', 'aaa');
|
$conn->query('INSERT INTO %n DEFAULT VALUES', 'aaa');
|
||||||
|
@@ -11,27 +11,37 @@ class TestClass
|
|||||||
|
|
||||||
public $public;
|
public $public;
|
||||||
|
|
||||||
protected $protected;
|
|
||||||
|
|
||||||
public static $publicStatic;
|
public static $publicStatic;
|
||||||
|
|
||||||
|
protected $protected;
|
||||||
|
|
||||||
|
|
||||||
public function publicMethod()
|
public function publicMethod()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function publicMethodStatic()
|
public static function publicMethodStatic()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function protectedMethod()
|
protected function protectedMethod()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static function protectedMethodS()
|
protected static function protectedMethodS()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getBar()
|
public function getBar()
|
||||||
{
|
{
|
||||||
return 123;
|
return 123;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isFoo()
|
public function isFoo()
|
||||||
{
|
{
|
||||||
return 456;
|
return 456;
|
||||||
|
@@ -4,8 +4,8 @@
|
|||||||
* @dataProvider ../databases.ini
|
* @dataProvider ../databases.ini
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Tester\Assert;
|
|
||||||
use Dibi\DateTime;
|
use Dibi\DateTime;
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ Assert::same(
|
|||||||
$conn->translate('TEST %and', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'])
|
$conn->translate('TEST %and', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'])
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
|
||||||
$where = [];
|
$where = [];
|
||||||
$where[] = '[age] > 20';
|
$where[] = '[age] > 20';
|
||||||
$where[] = '[email] IS NOT NULL';
|
$where[] = '[email] IS NOT NULL';
|
||||||
@@ -156,7 +156,7 @@ if ($config['system'] === 'odbc') {
|
|||||||
Assert::same(
|
Assert::same(
|
||||||
reformat([
|
reformat([
|
||||||
'sqlsrv' => 'SELECT * FROM [products] OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY',
|
'sqlsrv' => 'SELECT * FROM [products] OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY',
|
||||||
'SELECT * FROM [products] LIMIT 2 OFFSET 1'
|
'SELECT * FROM [products] LIMIT 2 OFFSET 1',
|
||||||
]),
|
]),
|
||||||
$conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1)
|
$conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1)
|
||||||
);
|
);
|
||||||
@@ -549,7 +549,7 @@ Assert::same(
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
setLocale(LC_ALL, 'czech');
|
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"),
|
||||||
|
@@ -63,7 +63,7 @@ function reformat($s)
|
|||||||
return strtr($s, '[]', '``');
|
return strtr($s, '[]', '``');
|
||||||
} elseif ($config['system'] === 'postgre') {
|
} elseif ($config['system'] === 'postgre') {
|
||||||
return strtr($s, '[]', '""');
|
return strtr($s, '[]', '""');
|
||||||
} elseif (in_array($config['system'], ['odbc', 'sqlite', 'sqlsrv'])) {
|
} elseif (in_array($config['system'], ['odbc', 'sqlite', 'sqlsrv'], true)) {
|
||||||
return $s;
|
return $s;
|
||||||
} else {
|
} else {
|
||||||
trigger_error("Unsupported driver $config[system]", E_USER_WARNING);
|
trigger_error("Unsupported driver $config[system]", E_USER_WARNING);
|
||||||
|
@@ -15,7 +15,7 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
|||||||
|
|
||||||
$e = Assert::exception(function () use ($conn) {
|
$e = Assert::exception(function () use ($conn) {
|
||||||
$conn->query('SELECT');
|
$conn->query('SELECT');
|
||||||
}, 'Dibi\DriverException', "%a% error in your SQL syntax;%a%", 1064);
|
}, 'Dibi\DriverException', '%a% error in your SQL syntax;%a%', 1064);
|
||||||
|
|
||||||
Assert::same('SELECT', $e->getSql());
|
Assert::same('SELECT', $e->getSql());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user