mirror of
https://github.com/dg/dibi.git
synced 2025-08-30 09:19:48 +02:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8f0d0fb115 | ||
|
965570c067 | ||
|
4ae4f49c21 | ||
|
5b9ffe14ba | ||
|
2d9358e4f7 | ||
|
e3748420f5 | ||
|
d708ac2aeb | ||
|
806ee1ccd1 | ||
|
0ec544043f | ||
|
6dcdd68d6d | ||
|
9ad502887b | ||
|
f06425b9a0 | ||
|
ca99b0b822 | ||
|
462ef6934b | ||
|
84c85bc536 | ||
|
d3151f7c65 | ||
|
66afffcddc | ||
|
7762da1bbb | ||
|
6f6a63881a | ||
|
999f51a7bd | ||
|
64b3d0c6f4 | ||
|
06440ab6dc | ||
|
b341b66d43 | ||
|
aac83ba849 | ||
|
2de32b66e1 | ||
|
1829366fc9 | ||
|
94f34a2a33 | ||
|
a3e5ac86f7 | ||
|
89d7148b04 | ||
|
38aa393dc3 | ||
|
84f9a6fdd8 | ||
|
eb64adeb05 | ||
|
3779a5034a | ||
|
090bb2f182 | ||
|
056c0702a1 | ||
|
020b15c0e2 |
12
.travis.yml
12
.travis.yml
@@ -4,10 +4,12 @@ php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
- php: hhvm
|
||||
|
||||
script:
|
||||
@@ -20,11 +22,17 @@ after_failure:
|
||||
|
||||
before_script:
|
||||
# Install Nette Tester & Code Checker
|
||||
- composer install --no-interaction --dev --prefer-source
|
||||
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
|
||||
- travis_retry composer install --no-interaction
|
||||
- travis_retry composer create-project nette/code-checker code-checker ~2.5 --no-interaction
|
||||
|
||||
# Create databases.ini
|
||||
- cp ./tests/databases.sample.ini ./tests/databases.ini
|
||||
|
||||
# Create Postgre database
|
||||
- psql -c 'CREATE DATABASE dibi_test' -U postgres
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
@@ -7,7 +7,7 @@
|
||||
"authors": [
|
||||
{
|
||||
"name": "David Grudl",
|
||||
"homepage": "http://davidgrudl.com"
|
||||
"homepage": "https://davidgrudl.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
|
27
contributing.md
Normal file
27
contributing.md
Normal file
@@ -0,0 +1,27 @@
|
||||
How to contribute & use the issue tracker
|
||||
=========================================
|
||||
|
||||
The issue tracker is the preferred channel for bug reports, features requests
|
||||
and submitting pull requests, but please respect the following restrictions:
|
||||
|
||||
* Please **do not** use the issue tracker for personal support requests (use
|
||||
[dibi forum](http://forum.dibiphp.com) or [Stack Overflow](http://stackoverflow.com)).
|
||||
|
||||
* Please **do not** derail or troll issues. Keep the discussion on topic and
|
||||
respect the opinions of others.
|
||||
|
||||
* Use the GitHub **issue search** — check if the issue has already been
|
||||
reported.
|
||||
|
||||
A good **bug report** shouldn't leave others needing to chase you up for more
|
||||
information. Please try to be as detailed as possible in your report.
|
||||
|
||||
**Feature requests** are welcome. But take a moment to find out whether your idea
|
||||
fits with the scope and aims of the project. It's up to *you* to make a strong
|
||||
case to convince the project's developers of the merits of this feature.
|
||||
|
||||
We welcome **pull requests**. If you'd like to contribute, please take a moment
|
||||
to [read the guidelines](https://nette.org/en/contributing) in order to make
|
||||
the contribution process easy and effective for everyone involved.
|
||||
|
||||
Thanks!
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Dibi extension for Nette Framework 2.1. Creates 'connection' service.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\nette
|
||||
* @phpversion 5.3
|
||||
*/
|
||||
@@ -36,7 +35,8 @@ class DibiNette21Extension extends Nette\DI\CompilerExtension
|
||||
}
|
||||
|
||||
$connection = $container->addDefinition($this->prefix('connection'))
|
||||
->setClass('DibiConnection', array($config));
|
||||
->setClass('DibiConnection', array($config))
|
||||
->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE);
|
||||
|
||||
if ($useProfiler) {
|
||||
$panel = $container->addDefinition($this->prefix('panel'))
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
use Nette\Diagnostics\Debugger;
|
||||
@@ -11,7 +11,6 @@ use Nette\Diagnostics\Debugger;
|
||||
/**
|
||||
* Dibi panel for Nette\Diagnostics.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\nette
|
||||
*/
|
||||
class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel
|
||||
@@ -104,9 +103,10 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel
|
||||
try {
|
||||
$backup = array($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime);
|
||||
$event->connection->onEvent = NULL;
|
||||
$cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN' : '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);
|
||||
} catch (DibiException $e) {}
|
||||
} catch (DibiException $e) {
|
||||
}
|
||||
list($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime) = $backup;
|
||||
}
|
||||
|
||||
|
@@ -2,19 +2,18 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
namespace Dibi\Bridges\Nette;
|
||||
|
||||
use dibi,
|
||||
Nette;
|
||||
use dibi;
|
||||
use Nette;
|
||||
|
||||
|
||||
/**
|
||||
* Dibi extension for Nette Framework 2.2. Creates 'connection' & 'panel' services.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\nette
|
||||
*/
|
||||
class DibiExtension22 extends Nette\DI\CompilerExtension
|
||||
@@ -40,7 +39,8 @@ class DibiExtension22 extends Nette\DI\CompilerExtension
|
||||
}
|
||||
|
||||
$connection = $container->addDefinition($this->prefix('connection'))
|
||||
->setClass('DibiConnection', array($config));
|
||||
->setClass('DibiConnection', array($config))
|
||||
->setAutowired(isset($config['autowired']) ? $config['autowired'] : TRUE);
|
||||
|
||||
if ($useProfiler) {
|
||||
$panel = $container->addDefinition($this->prefix('panel'))
|
||||
|
@@ -2,19 +2,18 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
namespace Dibi\Bridges\Tracy;
|
||||
|
||||
use dibi,
|
||||
Tracy;
|
||||
use dibi;
|
||||
use Tracy;
|
||||
|
||||
|
||||
/**
|
||||
* Dibi panel for Tracy.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\nette
|
||||
*/
|
||||
class Panel extends \DibiObject implements Tracy\IBarPanel
|
||||
{
|
||||
@@ -81,13 +80,14 @@ class Panel extends \DibiObject implements Tracy\IBarPanel
|
||||
public function getTab()
|
||||
{
|
||||
$totalTime = 0;
|
||||
$count = count($this->events);
|
||||
foreach ($this->events as $event) {
|
||||
$totalTime += $event->time;
|
||||
}
|
||||
return '<span title="dibi"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC" />'
|
||||
. count($this->events) . ' queries'
|
||||
return '<span title="dibi"><svg viewBox="0 0 2048 2048" style="vertical-align: bottom; width:1.23em; height:1.55em"><path fill="' . ($count ? '#b079d6' : '#aaa') . '" d="M1024 896q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0 768q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-384q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-1152q208 0 385 34.5t280 93.5 103 128v128q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-128q0-69 103-128t280-93.5 385-34.5z"/></svg><span class="tracy-label">'
|
||||
. $count . ' queries'
|
||||
. ($totalTime ? sprintf(' / %0.1f ms', $totalTime * 1000) : '')
|
||||
. '</span>';
|
||||
. '</span></span>';
|
||||
}
|
||||
|
||||
|
||||
@@ -106,9 +106,10 @@ class Panel extends \DibiObject implements Tracy\IBarPanel
|
||||
try {
|
||||
$backup = array($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime);
|
||||
$event->connection->onEvent = NULL;
|
||||
$cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN' : '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);
|
||||
} catch (\DibiException $e) {}
|
||||
} catch (\DibiException $e) {
|
||||
}
|
||||
list($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime) = $backup;
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* dibi - smart database abstraction layer (http://dibiphp.com)
|
||||
*
|
||||
* Copyright (c) 2005, 2012 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005, 2012 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* - resource (resource) => existing connection resource
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author Tomáš Kraina, Roman Sklenář
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultDriver, IDibiReflector
|
||||
@@ -88,7 +87,6 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
||||
throw new DibiDriverException(ibase_errmsg(), ibase_errcode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -349,7 +347,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
||||
*/
|
||||
public function getRowCount()
|
||||
{
|
||||
throw new DibiNotSupportedException("Firebird/Interbase do not support returning number of rows in result set.");
|
||||
throw new DibiNotSupportedException('Firebird/Interbase do not support returning number of rows in result set.');
|
||||
}
|
||||
|
||||
|
||||
@@ -379,13 +377,13 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws DibiException
|
||||
*/
|
||||
public function seek($row)
|
||||
{
|
||||
throw new DibiNotSupportedException("Firebird/Interbase do not support seek in result set.");
|
||||
throw new DibiNotSupportedException('Firebird/Interbase do not support seek in result set.');
|
||||
}
|
||||
|
||||
|
||||
@@ -656,7 +654,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
||||
END AS TRIGGER_ENABLED
|
||||
FROM RDB\$TRIGGERS
|
||||
WHERE RDB\$SYSTEM_FLAG = 0"
|
||||
. ($table === NULL ? ";" : " AND RDB\$RELATION_NAME = UPPER('$table');")
|
||||
. ($table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table');")
|
||||
);
|
||||
$triggers = array();
|
||||
while ($row = $res->fetch(TRUE)) {
|
||||
@@ -683,7 +681,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
||||
$q = "SELECT TRIM(RDB\$TRIGGER_NAME)
|
||||
FROM RDB\$TRIGGERS
|
||||
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);
|
||||
$triggers = array();
|
||||
@@ -808,8 +806,6 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD
|
||||
/**
|
||||
* Database procedure exception.
|
||||
*
|
||||
* @author Roman Sklenář
|
||||
* @copyright Copyright (c) 2010
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiProcedureException extends DibiException
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -17,12 +17,11 @@ require_once dirname(__FILE__) . '/DibiMsSql2005Reflector.php';
|
||||
* - username (or user)
|
||||
* - password (or pass)
|
||||
* - database => the database name to select
|
||||
* - options (array) => connection options {@link http://msdn.microsoft.com/en-us/library/cc296161(SQL.90).aspx}
|
||||
* - options (array) => connection options {@link https://msdn.microsoft.com/en-us/library/cc296161(SQL.90).aspx}
|
||||
* - charset => character encoding to set (default is UTF-8)
|
||||
* - resource (resource) => existing connection resource
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
@@ -226,7 +225,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
|
||||
case dibi::IDENTIFIER:
|
||||
// @see http://msdn.microsoft.com/en-us/library/ms176027.aspx
|
||||
// @see https://msdn.microsoft.com/en-us/library/ms176027.aspx
|
||||
return '[' . str_replace(']', ']]', $value) . ']';
|
||||
|
||||
case dibi::BOOL:
|
||||
@@ -327,8 +326,8 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
{
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The dibi reflector for MSSQL2005 databases.
|
||||
*
|
||||
* @author Daniel Kouba
|
||||
* @package dibi\drivers
|
||||
* @internal
|
||||
*/
|
||||
@@ -104,7 +103,7 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector
|
||||
{
|
||||
$keyUsagesRes = $this->driver->query("SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = {$this->driver->escape($table, dibi::TEXT)}");
|
||||
$keyUsages = array();
|
||||
while( $row = $keyUsagesRes->fetch(TRUE) ) {
|
||||
while ($row = $keyUsagesRes->fetch(TRUE)) {
|
||||
$keyUsages[$row['CONSTRAINT_NAME']][(int) $row['ORDINAL_POSITION'] - 1] = $row['COLUMN_NAME'];
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/DibiMsSqlReflector.php';
|
||||
@@ -19,7 +19,6 @@ require_once dirname(__FILE__) . '/DibiMsSqlReflector.php';
|
||||
* - resource (resource) => existing connection resource
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
@@ -211,7 +210,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
||||
return "'" . str_replace("'", "''", $value) . "'";
|
||||
|
||||
case dibi::IDENTIFIER:
|
||||
// @see http://msdn.microsoft.com/en-us/library/ms176027.aspx
|
||||
// @see https://msdn.microsoft.com/en-us/library/ms176027.aspx
|
||||
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']';
|
||||
|
||||
case dibi::BOOL:
|
||||
@@ -363,5 +362,4 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
||||
return is_resource($this->resultSet) ? $this->resultSet : NULL;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,17 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005, 2010 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* @package dibi\drivers
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The dibi reflector for MsSQL databases.
|
||||
*
|
||||
* @author Steven Bredenberg
|
||||
* @package dibi\drivers
|
||||
* @internal
|
||||
*/
|
||||
@@ -34,10 +30,10 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
||||
*/
|
||||
public function getTables()
|
||||
{
|
||||
$res = $this->driver->query("
|
||||
$res = $this->driver->query('
|
||||
SELECT TABLE_NAME, TABLE_TYPE
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
");
|
||||
');
|
||||
$tables = array();
|
||||
while ($row = $res->fetch(FALSE)) {
|
||||
$tables[] = array(
|
||||
@@ -52,12 +48,12 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
||||
/**
|
||||
* Returns count of rows in a table
|
||||
* @param string
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function getTableCount($table, $fallback=true)
|
||||
public function getTableCount($table, $fallback = TRUE)
|
||||
{
|
||||
if (empty($table)) {
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
$result = $this->driver->query("
|
||||
SELECT MAX(rowcnt)
|
||||
@@ -71,7 +67,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
||||
$row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escape($table, dibi::IDENTIFIER)}")->fetch(FALSE);
|
||||
$count = intval($row[0]);
|
||||
} else {
|
||||
$count = false;
|
||||
$count = FALSE;
|
||||
}
|
||||
} else {
|
||||
$count = intval($row[0]);
|
||||
@@ -96,16 +92,16 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
||||
");
|
||||
$columns = array();
|
||||
while ($row = $res->fetch(TRUE)) {
|
||||
$size = false;
|
||||
$size = FALSE;
|
||||
$type = strtoupper($row['DATA_TYPE']);
|
||||
|
||||
$size_cols = array(
|
||||
'DATETIME'=>'DATETIME_PRECISION',
|
||||
'DECIMAL'=>'NUMERIC_PRECISION',
|
||||
'CHAR'=>'CHARACTER_MAXIMUM_LENGTH',
|
||||
'NCHAR'=>'CHARACTER_OCTET_LENGTH',
|
||||
'NVARCHAR'=>'CHARACTER_OCTET_LENGTH',
|
||||
'VARCHAR'=>'CHARACTER_OCTET_LENGTH'
|
||||
'DATETIME' => 'DATETIME_PRECISION',
|
||||
'DECIMAL' => 'NUMERIC_PRECISION',
|
||||
'CHAR' => 'CHARACTER_MAXIMUM_LENGTH',
|
||||
'NCHAR' => 'CHARACTER_OCTET_LENGTH',
|
||||
'NVARCHAR' => 'CHARACTER_OCTET_LENGTH',
|
||||
'VARCHAR' => 'CHARACTER_OCTET_LENGTH',
|
||||
);
|
||||
|
||||
if (isset($size_cols[$type])) {
|
||||
@@ -122,7 +118,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
||||
'unsigned' => NULL,
|
||||
'nullable' => $row['IS_NULLABLE'] === 'YES',
|
||||
'default' => $row['COLUMN_DEFAULT'],
|
||||
'autoincrement' => false,
|
||||
'autoincrement' => FALSE,
|
||||
'vendor' => $row,
|
||||
);
|
||||
}
|
||||
@@ -161,8 +157,8 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
||||
if (!isset($indexes[$index_name])) {
|
||||
$indexes[$index_name] = array();
|
||||
$indexes[$index_name]['name'] = $index_name;
|
||||
$indexes[$index_name]['unique'] = (bool)$row['is_unique'];
|
||||
$indexes[$index_name]['primary'] = (bool)$row['is_primary_key'];
|
||||
$indexes[$index_name]['unique'] = (bool) $row['is_unique'];
|
||||
$indexes[$index_name]['primary'] = (bool) $row['is_primary_key'];
|
||||
$indexes[$index_name]['columns'] = array();
|
||||
}
|
||||
$indexes[$index_name]['columns'][] = $row['column_name'];
|
||||
@@ -203,8 +199,8 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
|
||||
$keys[$key_name]['local'] = array($row['column_name']); // local columns
|
||||
$keys[$key_name]['table'] = $row['reference_table_name']; // referenced table
|
||||
$keys[$key_name]['foreign'] = array($row['reference_column_name']); // referenced columns
|
||||
$keys[$key_name]['onDelete'] = false;
|
||||
$keys[$key_name]['onUpdate'] = false;
|
||||
$keys[$key_name]['onDelete'] = FALSE;
|
||||
$keys[$key_name]['onUpdate'] = FALSE;
|
||||
} else {
|
||||
$keys[$key_name]['local'][] = $row['column_name']; // local columns
|
||||
$keys[$key_name]['foreign'][] = $row['reference_column_name']; // referenced columns
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ require_once dirname(__FILE__) . '/DibiMySqlReflector.php';
|
||||
* - resource (resource) => existing connection resource
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
@@ -406,8 +405,8 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws DibiException
|
||||
*/
|
||||
public function seek($row)
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The dibi reflector for MySQL databases.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
* @internal
|
||||
*/
|
||||
@@ -31,12 +30,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
||||
*/
|
||||
public function getTables()
|
||||
{
|
||||
/*$this->query("
|
||||
SELECT TABLE_NAME as name, TABLE_TYPE = 'VIEW' as view
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
");*/
|
||||
$res = $this->driver->query("SHOW FULL TABLES");
|
||||
$res = $this->driver->query('SHOW FULL TABLES');
|
||||
$tables = array();
|
||||
while ($row = $res->fetch(FALSE)) {
|
||||
$tables[] = array(
|
||||
@@ -55,12 +49,6 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
||||
*/
|
||||
public function getColumns($table)
|
||||
{
|
||||
/*$table = $this->escape($table, dibi::TEXT);
|
||||
$this->query("
|
||||
SELECT *
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE()
|
||||
");*/
|
||||
$res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escape($table, dibi::IDENTIFIER)}");
|
||||
$columns = array();
|
||||
while ($row = $res->fetch(TRUE)) {
|
||||
@@ -88,13 +76,6 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
||||
*/
|
||||
public function getIndexes($table)
|
||||
{
|
||||
/*$table = $this->escape($table, dibi::TEXT);
|
||||
$this->query("
|
||||
SELECT *
|
||||
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE()
|
||||
AND REFERENCED_COLUMN_NAME IS NULL
|
||||
");*/
|
||||
$res = $this->driver->query("SHOW INDEX FROM {$this->driver->escape($table, dibi::IDENTIFIER)}");
|
||||
$indexes = array();
|
||||
while ($row = $res->fetch(TRUE)) {
|
||||
@@ -138,9 +119,9 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
|
||||
$keyName = $row['CONSTRAINT_NAME'];
|
||||
|
||||
$foreignKeys[$keyName]['name'] = $keyName;
|
||||
$foreignKeys[$keyName]['local'] = explode(",", $row['COLUMNS']);
|
||||
$foreignKeys[$keyName]['local'] = explode(',', $row['COLUMNS']);
|
||||
$foreignKeys[$keyName]['table'] = $row['REFERENCED_TABLE_NAME'];
|
||||
$foreignKeys[$keyName]['foreign'] = explode(",", $row['REFERENCED_COLUMNS']);
|
||||
$foreignKeys[$keyName]['foreign'] = explode(',', $row['REFERENCED_COLUMNS']);
|
||||
$foreignKeys[$keyName]['onDelete'] = $row['DELETE_RULE'];
|
||||
$foreignKeys[$keyName]['onUpdate'] = $row['UPDATE_RULE'];
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ require_once dirname(__FILE__) . '/DibiMySqlReflector.php';
|
||||
* - resource (mysqli) => existing connection resource
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
@@ -389,8 +388,8 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws DibiException
|
||||
*/
|
||||
public function seek($row)
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* - resource (resource) => existing connection resource
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDriver, IDibiReflector
|
||||
@@ -339,7 +338,9 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
||||
}
|
||||
$count = odbc_num_fields($set);
|
||||
$cols = array();
|
||||
for ($i = 1; $i <= $count; $i++) $cols[] = odbc_result($set, $i);
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$cols[] = odbc_result($set, $i);
|
||||
}
|
||||
return $cols;
|
||||
}
|
||||
}
|
||||
@@ -347,8 +348,8 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
{
|
||||
@@ -378,10 +379,10 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive
|
||||
$columns = array();
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$columns[] = array(
|
||||
'name' => odbc_field_name($this->resultSet, $i),
|
||||
'table' => NULL,
|
||||
'fullname' => odbc_field_name($this->resultSet, $i),
|
||||
'nativetype'=> odbc_field_type($this->resultSet, $i),
|
||||
'name' => odbc_field_name($this->resultSet, $i),
|
||||
'table' => NULL,
|
||||
'fullname' => odbc_field_name($this->resultSet, $i),
|
||||
'nativetype' => odbc_field_type($this->resultSet, $i),
|
||||
);
|
||||
}
|
||||
return $columns;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
* - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDriver, IDibiReflector
|
||||
@@ -103,7 +102,7 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
||||
{
|
||||
$res = oci_parse($this->connection, $sql);
|
||||
if ($res) {
|
||||
oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT);
|
||||
@oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT);
|
||||
$err = oci_error($res);
|
||||
if ($err) {
|
||||
throw new DibiDriverException($err['message'], $err['code'], $sql);
|
||||
@@ -336,8 +335,8 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
{
|
||||
@@ -365,11 +364,12 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
||||
$count = oci_num_fields($this->resultSet);
|
||||
$columns = array();
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
$type = oci_field_type($this->resultSet, $i);
|
||||
$columns[] = array(
|
||||
'name' => oci_field_name($this->resultSet, $i),
|
||||
'table' => NULL,
|
||||
'fullname' => oci_field_name($this->resultSet, $i),
|
||||
'nativetype'=> oci_field_type($this->resultSet, $i),
|
||||
'nativetype' => $type === 'NUMBER' && oci_field_scale($this->resultSet, $i) === 0 ? 'INTEGER' : $type,
|
||||
);
|
||||
}
|
||||
return $columns;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ require_once dirname(__FILE__) . '/DibiSqliteReflector.php';
|
||||
* - password (or pass)
|
||||
* - options (array) => driver specific options {@see PDO::__construct}
|
||||
* - resource (PDO) => existing connection
|
||||
* - version
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
@@ -38,6 +38,9 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
/** @var string */
|
||||
private $driverName;
|
||||
|
||||
/** @var string */
|
||||
private $serverVersion;
|
||||
|
||||
|
||||
/**
|
||||
* @throws DibiNotSupportedException
|
||||
@@ -64,17 +67,21 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
if ($config['resource'] instanceof PDO) {
|
||||
$this->connection = $config['resource'];
|
||||
|
||||
} else try {
|
||||
$this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
if ($e->getMessage() === 'could not find driver') {
|
||||
throw new DibiNotSupportedException("PHP extension for PDO is not loaded.");
|
||||
} else {
|
||||
try {
|
||||
$this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
|
||||
} catch (PDOException $e) {
|
||||
if ($e->getMessage() === 'could not find driver') {
|
||||
throw new DibiNotSupportedException('PHP extension for PDO is not loaded.');
|
||||
}
|
||||
throw new DibiDriverException($e->getMessage(), $e->getCode());
|
||||
}
|
||||
throw new DibiDriverException($e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
$this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
$this->serverVersion = isset($config['version'])
|
||||
? $config['version']
|
||||
: @$this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); // @ - may be not supported
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +105,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
{
|
||||
// must detect if SQL returns result set or num of affected rows
|
||||
$cmd = strtoupper(substr(ltrim($sql), 0, 6));
|
||||
static $list = array('UPDATE'=>1, 'DELETE'=>1, 'INSERT'=>1, 'REPLAC'=>1);
|
||||
static $list = array('UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1);
|
||||
$this->affectedRows = FALSE;
|
||||
|
||||
if (isset($list[$cmd])) {
|
||||
@@ -268,6 +275,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
case 'mssql':
|
||||
return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']';
|
||||
|
||||
case 'dblib':
|
||||
case 'sqlsrv':
|
||||
return '[' . str_replace(']', ']]', $value) . ']';
|
||||
|
||||
@@ -288,7 +296,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
$value = new DibiDateTime($value);
|
||||
}
|
||||
if ($this->driverName === 'odbc') {
|
||||
return $value->format($type === dibi::DATETIME ? "#m/d/Y H:i:s#" : "#m/d/Y#");
|
||||
return $value->format($type === dibi::DATETIME ? '#m/d/Y H:i:s#' : '#m/d/Y#');
|
||||
} else {
|
||||
return $value->format($type === dibi::DATETIME ? "'Y-m-d H:i:s'" : "'Y-m-d'");
|
||||
}
|
||||
@@ -330,6 +338,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
|
||||
case 'odbc':
|
||||
case 'mssql':
|
||||
case 'dblib':
|
||||
case 'sqlsrv':
|
||||
$value = strtr($value, array("'" => "''", '%' => '[%]', '_' => '[_]', '[' => '[[]'));
|
||||
return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
|
||||
@@ -396,10 +405,19 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
}
|
||||
break;
|
||||
|
||||
case 'odbc':
|
||||
case 'dblib':
|
||||
case 'mssql':
|
||||
case 'sqlsrv':
|
||||
case 'dblib':
|
||||
if (version_compare($this->serverVersion, '11.0') >= 0) {
|
||||
if ($offset >= 0 || $limit >= 0) {
|
||||
$sql .= ' OFFSET ' . (int) $offset . ' ROWS'
|
||||
. ($limit > 0 ? ' FETCH NEXT ' . (int) $limit . ' ROWS ONLY' : '');
|
||||
}
|
||||
break;
|
||||
}
|
||||
// intentionally break omitted
|
||||
|
||||
case 'odbc':
|
||||
if ($offset < 1) {
|
||||
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
|
||||
break;
|
||||
@@ -438,8 +456,8 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* - resource (resource) => existing connection resource
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDriver, IDibiReflector
|
||||
@@ -67,7 +66,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
$string = '';
|
||||
DibiConnection::alias($config, 'user', 'username');
|
||||
DibiConnection::alias($config, 'dbname', 'database');
|
||||
foreach (array('host','hostaddr','port','dbname','user','password','connect_timeout','options','sslmode','service') as $key) {
|
||||
foreach (array('host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service') as $key) {
|
||||
if (isset($config[$key])) {
|
||||
$string .= $key . '=' . $config[$key] . ' ';
|
||||
}
|
||||
@@ -115,7 +114,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
|
||||
/**
|
||||
* Pings database.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function ping()
|
||||
{
|
||||
@@ -164,7 +163,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
{
|
||||
if ($sequence === NULL) {
|
||||
// PostgreSQL 8.1 is needed
|
||||
$res = $this->query("SELECT LASTVAL()");
|
||||
$res = $this->query('SELECT LASTVAL()');
|
||||
} else {
|
||||
$res = $this->query("SELECT CURRVAL('$sequence')");
|
||||
}
|
||||
@@ -385,8 +384,8 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
*/
|
||||
public function seek($row)
|
||||
{
|
||||
@@ -415,9 +414,9 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
$columns = array();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$row = array(
|
||||
'name' => pg_field_name($this->resultSet, $i),
|
||||
'table' => pg_field_table($this->resultSet, $i),
|
||||
'nativetype'=> pg_field_type($this->resultSet, $i),
|
||||
'name' => pg_field_name($this->resultSet, $i),
|
||||
'table' => pg_field_table($this->resultSet, $i),
|
||||
'nativetype' => pg_field_type($this->resultSet, $i),
|
||||
);
|
||||
$row['fullname'] = $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'];
|
||||
$columns[] = $row;
|
||||
@@ -464,14 +463,14 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
table_schema = ANY (current_schemas(false))";
|
||||
|
||||
if ($version >= 9.3) {
|
||||
$query .= "
|
||||
$query .= '
|
||||
UNION ALL
|
||||
SELECT
|
||||
matviewname, 1
|
||||
FROM
|
||||
pg_matviews
|
||||
WHERE
|
||||
schemaname = ANY (current_schemas(false))";
|
||||
schemaname = ANY (current_schemas(false))';
|
||||
}
|
||||
|
||||
$res = $this->query($query);
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ require_once dirname(__FILE__) . '/DibiSqliteReflector.php';
|
||||
* - resource (SQLite3) => existing connection resource
|
||||
* - lazy, profiler, result, substitutes, ... => see DibiConnection options
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
*/
|
||||
class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDriver
|
||||
@@ -66,11 +65,12 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
|
||||
if (isset($config['resource']) && $config['resource'] instanceof SQLite3) {
|
||||
$this->connection = $config['resource'];
|
||||
} else try {
|
||||
$this->connection = new SQLite3($config['database']);
|
||||
|
||||
} catch (Exception $e) {
|
||||
throw new DibiDriverException($e->getMessage(), $e->getCode());
|
||||
} else {
|
||||
try {
|
||||
$this->connection = new SQLite3($config['database']);
|
||||
} catch (Exception $e) {
|
||||
throw new DibiDriverException($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
$this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset'];
|
||||
@@ -82,7 +82,7 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
// enable foreign keys support (defaultly disabled; if disabled then foreign key constraints are not enforced)
|
||||
$version = SQLite3::version();
|
||||
if ($version['versionNumber'] >= '3006019') {
|
||||
$this->query("PRAGMA foreign_keys = ON");
|
||||
$this->query('PRAGMA foreign_keys = ON');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,8 +336,8 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws DibiNotSupportedException
|
||||
*/
|
||||
public function seek($row)
|
||||
@@ -368,7 +368,7 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr
|
||||
static $types = array(SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null');
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$columns[] = array(
|
||||
'name' => $this->resultSet->columnName($i),
|
||||
'name' => $this->resultSet->columnName($i),
|
||||
'table' => NULL,
|
||||
'fullname' => $this->resultSet->columnName($i),
|
||||
'nativetype' => $types[$this->resultSet->columnType($i)],
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -332,8 +332,8 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
||||
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return boolean TRUE on success, FALSE if unable to seek to specified record
|
||||
* @param int the 0-based cursor pos to seek to
|
||||
* @return bool TRUE on success, FALSE if unable to seek to specified record
|
||||
* @throws DibiException
|
||||
*/
|
||||
public function seek($row)
|
||||
@@ -367,7 +367,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver, IDibiResultDri
|
||||
$name = str_replace(array('[', ']'), '', sqlite_field_name($this->resultSet, $i));
|
||||
$pair = explode('.', $name);
|
||||
$columns[] = array(
|
||||
'name' => isset($pair[1]) ? $pair[1] : $pair[0],
|
||||
'name' => isset($pair[1]) ? $pair[1] : $pair[0],
|
||||
'table' => isset($pair[1]) ? $pair[0] : NULL,
|
||||
'fullname' => $name,
|
||||
'nativetype' => NULL,
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The dibi reflector for SQLite database.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\drivers
|
||||
* @internal
|
||||
*/
|
||||
@@ -52,12 +51,6 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
|
||||
*/
|
||||
public function getColumns($table)
|
||||
{
|
||||
$meta = $this->driver->query("
|
||||
SELECT sql FROM sqlite_master WHERE type = 'table' AND name = {$this->driver->escape($table, dibi::TEXT)}
|
||||
UNION ALL
|
||||
SELECT sql FROM sqlite_temp_master WHERE type = 'table' AND name = {$this->driver->escape($table, dibi::TEXT)}
|
||||
")->fetch(TRUE);
|
||||
|
||||
$res = $this->driver->query("PRAGMA table_info({$this->driver->escape($table, dibi::IDENTIFIER)})");
|
||||
$columns = array();
|
||||
while ($row = $res->fetch(TRUE)) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
* This class is static container class for creating DB objects and
|
||||
* store connections info.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class dibi
|
||||
@@ -29,18 +28,18 @@ class dibi
|
||||
AFFECTED_ROWS = 'a';
|
||||
|
||||
/** @deprecated */
|
||||
const FIELD_TEXT = dibi::TEXT,
|
||||
FIELD_BINARY = dibi::BINARY,
|
||||
FIELD_BOOL = dibi::BOOL,
|
||||
FIELD_INTEGER = dibi::INTEGER,
|
||||
FIELD_FLOAT = dibi::FLOAT,
|
||||
FIELD_DATE = dibi::DATE,
|
||||
FIELD_DATETIME = dibi::DATETIME,
|
||||
FIELD_TIME = dibi::TIME;
|
||||
const FIELD_TEXT = self::TEXT,
|
||||
FIELD_BINARY = self::BINARY,
|
||||
FIELD_BOOL = self::BOOL,
|
||||
FIELD_INTEGER = self::INTEGER,
|
||||
FIELD_FLOAT = self::FLOAT,
|
||||
FIELD_DATE = self::DATE,
|
||||
FIELD_DATETIME = self::DATETIME,
|
||||
FIELD_TIME = self::TIME;
|
||||
|
||||
/** version */
|
||||
const VERSION = '2.3.0',
|
||||
REVISION = 'released on 2015-01-23';
|
||||
const VERSION = '2.3.3',
|
||||
REVISION = 'released on 2015-10-22';
|
||||
|
||||
/** sorting order */
|
||||
const ASC = 'ASC',
|
||||
@@ -76,7 +75,7 @@ class dibi
|
||||
*/
|
||||
final public function __construct()
|
||||
{
|
||||
throw new LogicException("Cannot instantiate static class " . get_class($this));
|
||||
throw new LogicException('Cannot instantiate static class ' . get_class($this));
|
||||
}
|
||||
|
||||
|
||||
@@ -86,14 +85,12 @@ class dibi
|
||||
/**
|
||||
* Creates a new DibiConnection object and connects it to specified database.
|
||||
* @param mixed connection parameters
|
||||
* @param string connection name
|
||||
* @return DibiConnection
|
||||
* @throws DibiException
|
||||
*/
|
||||
public static function connect($config = array(), $name = 0)
|
||||
{
|
||||
if ($name) {
|
||||
trigger_error(__METHOD__ . '(): named connections are deprecated.', E_USER_DEPRECATED);
|
||||
}
|
||||
return self::$connection = self::$registry[$name] = new DibiConnection($config, $name);
|
||||
}
|
||||
|
||||
@@ -120,6 +117,7 @@ class dibi
|
||||
|
||||
/**
|
||||
* Retrieve active connection.
|
||||
* @param string connection registy name
|
||||
* @return DibiConnection
|
||||
* @throws DibiException
|
||||
*/
|
||||
@@ -133,8 +131,6 @@ class dibi
|
||||
return self::$connection;
|
||||
}
|
||||
|
||||
trigger_error(__METHOD__ . '(): named connections are deprecated.', E_USER_DEPRECATED);
|
||||
|
||||
if (!isset(self::$registry[$name])) {
|
||||
throw new DibiException("There is no connection named '$name'.");
|
||||
}
|
||||
@@ -297,7 +293,7 @@ class dibi
|
||||
* @return int
|
||||
* @throws DibiException
|
||||
*/
|
||||
public static function getInsertId($sequence=NULL)
|
||||
public static function getInsertId($sequence = NULL)
|
||||
{
|
||||
return self::getConnection()->getInsertId($sequence);
|
||||
}
|
||||
@@ -309,7 +305,7 @@ class dibi
|
||||
* @return int
|
||||
* @throws DibiException
|
||||
*/
|
||||
public static function insertId($sequence=NULL)
|
||||
public static function insertId($sequence = NULL)
|
||||
{
|
||||
return self::getConnection()->getInsertId($sequence);
|
||||
}
|
||||
@@ -372,18 +368,6 @@ class dibi
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replacement for majority of dibi::methods() in future.
|
||||
*/
|
||||
public static function __callStatic($name, $args)
|
||||
{
|
||||
//if ($name = 'select', 'update', ...') {
|
||||
// return self::command()->$name($args);
|
||||
//}
|
||||
return call_user_func_array(array(self::getConnection(), $name), $args);
|
||||
}
|
||||
|
||||
|
||||
/********************* fluent SQL builders ****************d*g**/
|
||||
|
||||
|
||||
@@ -472,7 +456,7 @@ class dibi
|
||||
$sql = self::$sql;
|
||||
}
|
||||
|
||||
static $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|OFFSET|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE|START\s+TRANSACTION|BEGIN|COMMIT|ROLLBACK(?:\s+TO\s+SAVEPOINT)?|(?:RELEASE\s+)?SAVEPOINT';
|
||||
static $keywords1 = 'SELECT|(?:ON\s+DUPLICATE\s+KEY)?UPDATE|INSERT(?:\s+INTO)?|REPLACE(?:\s+INTO)?|DELETE|CALL|UNION|FROM|WHERE|HAVING|GROUP\s+BY|ORDER\s+BY|LIMIT|OFFSET|FETCH\s+NEXT|SET|VALUES|LEFT\s+JOIN|INNER\s+JOIN|TRUNCATE|START\s+TRANSACTION|BEGIN|COMMIT|ROLLBACK(?:\s+TO\s+SAVEPOINT)?|(?:RELEASE\s+)?SAVEPOINT';
|
||||
static $keywords2 = 'ALL|DISTINCT|DISTINCTROW|IGNORE|AS|USING|ON|AND|OR|IN|IS|NOT|NULL|LIKE|RLIKE|REGEXP|TRUE|FALSE';
|
||||
|
||||
// insert new lines
|
||||
@@ -480,7 +464,7 @@ class dibi
|
||||
$sql = preg_replace("#(?<=[\\s,(])($keywords1)(?=[\\s,)])#i", "\n\$1", $sql);
|
||||
|
||||
// reduce spaces
|
||||
$sql = preg_replace('#[ \t]{2,}#', " ", $sql);
|
||||
$sql = preg_replace('#[ \t]{2,}#', ' ', $sql);
|
||||
|
||||
$sql = wordwrap($sql, 100);
|
||||
$sql = preg_replace("#([ \t]*\r?\n){2,}#", "\n", $sql);
|
||||
|
@@ -2,26 +2,21 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* dibi connection.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*
|
||||
* @property-read bool $connected
|
||||
* @property-read mixed $config
|
||||
* @property-read IDibiDriver $driver
|
||||
* @property-read int $affectedRows
|
||||
* @property-read int $insertId
|
||||
* @property-read DibiDatabaseInfo $databaseInfo
|
||||
*/
|
||||
class DibiConnection extends DibiObject
|
||||
{
|
||||
/** @var array of function(DibiEvent $event); Occurs after query is executed */
|
||||
/** @var array of function (DibiEvent $event); Occurs after query is executed */
|
||||
public $onEvent;
|
||||
|
||||
/** @var array Current connection configuration */
|
||||
|
@@ -2,20 +2,14 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of IDataSource for dibi.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*
|
||||
* @property-read DibiConnection $connection
|
||||
* @property-read DibiResult $result
|
||||
* @property-read DibiResultIterator $iterator
|
||||
* @property-read int $totalCount
|
||||
*/
|
||||
class DibiDataSource extends DibiObject implements IDataSource
|
||||
{
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Reflection metadata class for a database.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\reflection
|
||||
*
|
||||
* @property-read string $name
|
||||
@@ -115,7 +114,6 @@ class DibiDatabaseInfo extends DibiObject
|
||||
/**
|
||||
* Reflection metadata class for a database table.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\reflection
|
||||
*
|
||||
* @property-read string $name
|
||||
@@ -307,7 +305,6 @@ class DibiTableInfo extends DibiObject
|
||||
/**
|
||||
* Reflection metadata class for a result set.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\reflection
|
||||
*
|
||||
* @property-read array $columns
|
||||
@@ -404,7 +401,6 @@ class DibiResultInfo extends DibiObject
|
||||
/**
|
||||
* Reflection metadata class for a table or result set column.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\reflection
|
||||
*
|
||||
* @property-read string $name
|
||||
@@ -604,7 +600,6 @@ class DibiColumnInfo extends DibiObject
|
||||
/**
|
||||
* Reflection metadata class for a foreign key.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\reflection
|
||||
* @todo
|
||||
*
|
||||
@@ -650,7 +645,6 @@ class DibiForeignKeyInfo extends DibiObject
|
||||
/**
|
||||
* Reflection metadata class for a index or primary key.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\reflection
|
||||
*
|
||||
* @property-read string $name
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* DateTime with serialization and timestamp support for PHP 5.2.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiDateTime extends DateTime
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Profiler & logger event.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiEvent
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* dibi common exception.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiException extends Exception
|
||||
@@ -54,7 +53,6 @@ class DibiException extends Exception
|
||||
/**
|
||||
* database server exception.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiDriverException extends DibiException
|
||||
@@ -114,11 +112,10 @@ class DibiDriverException extends DibiException
|
||||
/**
|
||||
* PCRE exception.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiPcreException extends Exception {
|
||||
|
||||
class DibiPcreException extends Exception
|
||||
{
|
||||
public function __construct($message = '%msg.')
|
||||
{
|
||||
static $messages = array(
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* dibi file logger.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiFileLogger extends DibiObject
|
||||
@@ -58,7 +57,7 @@ class DibiFileLogger extends DibiObject
|
||||
);
|
||||
} else {
|
||||
fwrite($handle,
|
||||
"OK: " . $event->sql
|
||||
'OK: ' . $event->sql
|
||||
. ($event->count ? ";\n-- rows: " . $event->count : '')
|
||||
. "\n-- takes: " . sprintf('%0.3f ms', $event->time * 1000)
|
||||
. "\n-- source: " . implode(':', $event->source)
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* dibi FirePHP logger.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiFirePhpLogger extends DibiObject
|
||||
@@ -72,7 +71,7 @@ class DibiFirePhpLogger extends DibiObject
|
||||
sprintf('%0.3f', $event->time * 1000),
|
||||
strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql,
|
||||
$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(
|
||||
|
@@ -2,19 +2,15 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* dibi SQL builder via fluent interfaces. EXPERIMENTAL!
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*
|
||||
* @property-read string $command
|
||||
* @property-read DibiConnection $connection
|
||||
* @property-read DibiResultIterator $iterator
|
||||
* @method DibiFluent select($field)
|
||||
* @method DibiFluent distinct()
|
||||
* @method DibiFluent from($table)
|
||||
@@ -319,11 +315,12 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
if ($this->command === 'SELECT') {
|
||||
return $this->query($this->_export(NULL, array('%lmt', 1)))->fetch();
|
||||
} else {
|
||||
return $this->query($this->_export())->fetch();
|
||||
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
||||
$result = $this->query($this->limit(1)->_export())->fetch();
|
||||
$this->removeClause('LIMIT');
|
||||
return $result;
|
||||
}
|
||||
return $this->query($this->_export())->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -333,11 +330,12 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
*/
|
||||
public function fetchSingle()
|
||||
{
|
||||
if ($this->command === 'SELECT') {
|
||||
return $this->query($this->_export(NULL, array('%lmt', 1)))->fetchSingle();
|
||||
} else {
|
||||
return $this->query($this->_export())->fetchSingle();
|
||||
if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) {
|
||||
$result = $this->query($this->limit(1)->_export())->fetchSingle();
|
||||
$this->removeClause('LIMIT');
|
||||
return $result;
|
||||
}
|
||||
return $this->query($this->_export())->fetchSingle();
|
||||
}
|
||||
|
||||
|
||||
@@ -405,7 +403,7 @@ class DibiFluent extends DibiObject implements IDataSource
|
||||
public function count()
|
||||
{
|
||||
return (int) $this->query(array(
|
||||
'SELECT COUNT(*) FROM (%ex', $this->_export(), ') AS [data]'
|
||||
'SELECT COUNT(*) FROM (%ex', $this->_export(), ') [data]',
|
||||
))->fetchSingle();
|
||||
}
|
||||
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Lazy cached storage.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
* @internal
|
||||
*/
|
||||
@@ -45,7 +44,6 @@ abstract class DibiHashMapBase
|
||||
/**
|
||||
* Lazy cached storage.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @internal
|
||||
*/
|
||||
final class DibiHashMap extends DibiHashMapBase
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* SQL literal value.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiLiteral extends DibiObject
|
||||
|
@@ -2,14 +2,14 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* DibiObject is the ultimate ancestor of all instantiable classes.
|
||||
*
|
||||
* DibiObject is copy of Nette\Object from Nette Framework (http://nette.org).
|
||||
* DibiObject is copy of Nette\Object from Nette Framework (https://nette.org).
|
||||
*
|
||||
* It defines some handful methods and enhances object core of PHP:
|
||||
* - access to undeclared members throws exceptions
|
||||
@@ -39,12 +39,11 @@
|
||||
* Adding method to class (i.e. to all instances) works similar to JavaScript
|
||||
* prototype property. The syntax for adding a new method is:
|
||||
* <code>
|
||||
* MyClass::extensionMethod('newMethod', function(MyClass $obj, $arg, ...) { ... });
|
||||
* MyClass::extensionMethod('newMethod', function (MyClass $obj, $arg, ...) { ... });
|
||||
* $obj = new MyClass;
|
||||
* $obj->newMethod($x);
|
||||
* </code>
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
abstract class DibiObject
|
||||
@@ -209,8 +208,8 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
// property getter support
|
||||
$name[0] = $name[0] & "\xDF"; // case-sensitive checking, capitalize first character
|
||||
$m = 'get' . $name;
|
||||
$uname = ucfirst($name);
|
||||
$m = 'get' . $uname;
|
||||
if (self::hasAccessor($class, $m)) {
|
||||
// ampersands:
|
||||
// - uses & __get() because declaration should be forward compatible (e.g. with Nette\Web\Html)
|
||||
@@ -219,13 +218,12 @@ abstract class DibiObject
|
||||
return $val;
|
||||
}
|
||||
|
||||
$m = 'is' . $name;
|
||||
$m = 'is' . $uname;
|
||||
if (self::hasAccessor($class, $m)) {
|
||||
$val = $this->$m();
|
||||
return $val;
|
||||
}
|
||||
|
||||
$name = func_get_arg(0);
|
||||
throw new LogicException("Cannot read an undeclared property $class::\$$name.");
|
||||
}
|
||||
|
||||
@@ -246,20 +244,18 @@ abstract class DibiObject
|
||||
}
|
||||
|
||||
// property setter support
|
||||
$name[0] = $name[0] & "\xDF"; // case-sensitive checking, capitalize first character
|
||||
if (self::hasAccessor($class, 'get' . $name) || self::hasAccessor($class, 'is' . $name)) {
|
||||
$uname = ucfirst($name);
|
||||
if (self::hasAccessor($class, 'get' . $uname) || self::hasAccessor($class, 'is' . $uname)) {
|
||||
$m = 'set' . $name;
|
||||
if (self::hasAccessor($class, $m)) {
|
||||
$this->$m($value);
|
||||
return;
|
||||
|
||||
} else {
|
||||
$name = func_get_arg(0);
|
||||
throw new LogicException("Cannot assign to a read-only property $class::\$$name.");
|
||||
}
|
||||
}
|
||||
|
||||
$name = func_get_arg(0);
|
||||
throw new LogicException("Cannot assign to an undeclared property $class::\$$name.");
|
||||
}
|
||||
|
||||
@@ -271,8 +267,7 @@ abstract class DibiObject
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
$name[0] = $name[0] & "\xDF";
|
||||
return $name !== '' && self::hasAccessor(get_class($this), 'get' . $name);
|
||||
return $name !== '' && self::hasAccessor(get_class($this), 'get' . ucfirst($name));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -22,15 +22,9 @@
|
||||
* unset($result);
|
||||
* </code>
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*
|
||||
* @property-read mixed $resource
|
||||
* @property-read IDibiResultDriver $driver
|
||||
* @property-read int $rowCount
|
||||
* @property-read DibiResultIterator $iterator
|
||||
* @property string $rowClass
|
||||
* @property-read DibiResultInfo $info
|
||||
*/
|
||||
class DibiResult extends DibiObject implements IDataSource
|
||||
{
|
||||
@@ -109,7 +103,7 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
/**
|
||||
* Moves cursor position without fetching row.
|
||||
* @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 DibiException
|
||||
*/
|
||||
final public function seek($row)
|
||||
@@ -188,7 +182,7 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
/**
|
||||
* Fetches the row at current position, process optional type conversion.
|
||||
* and moves the internal cursor to the next position
|
||||
* @return DibiRow|FALSE array on success, FALSE if no next record
|
||||
* @return DibiRow|FALSE array on success, FALSE if no next record
|
||||
*/
|
||||
final public function fetch()
|
||||
{
|
||||
@@ -209,7 +203,7 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
|
||||
/**
|
||||
* Like fetch(), but returns only first field.
|
||||
* @return mixed value on success, FALSE if no next record
|
||||
* @return mixed value on success, FALSE if no next record
|
||||
*/
|
||||
final public function fetchSingle()
|
||||
{
|
||||
@@ -303,16 +297,16 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
$x = & $x[];
|
||||
|
||||
} elseif ($as === '=') { // "value" node
|
||||
$x = $row->{$assoc[$i+1]};
|
||||
$x = $row->{$assoc[$i + 1]};
|
||||
continue 2;
|
||||
|
||||
} elseif ($as === '->') { // "object" node
|
||||
if ($x === NULL) {
|
||||
$x = clone $row;
|
||||
$x = & $x->{$assoc[$i+1]};
|
||||
$x = & $x->{$assoc[$i + 1]};
|
||||
$x = NULL; // prepare child node
|
||||
} else {
|
||||
$x = & $x->{$assoc[$i+1]};
|
||||
$x = & $x->{$assoc[$i + 1]};
|
||||
}
|
||||
|
||||
} elseif ($as !== '|') { // associative-array node
|
||||
@@ -369,22 +363,21 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
} elseif ($as === '=') { // "record" node
|
||||
if ($x === NULL) {
|
||||
$x = $row->toArray();
|
||||
$x = & $x[ $assoc[$i+1] ];
|
||||
$x = & $x[ $assoc[$i + 1] ];
|
||||
$x = NULL; // prepare child node
|
||||
} else {
|
||||
$x = & $x[ $assoc[$i+1] ];
|
||||
$x = & $x[ $assoc[$i + 1] ];
|
||||
}
|
||||
|
||||
} elseif ($as === '@') { // "object" node
|
||||
if ($x === NULL) {
|
||||
$x = clone $row;
|
||||
$x = & $x->{$assoc[$i+1]};
|
||||
$x = & $x->{$assoc[$i + 1]};
|
||||
$x = NULL; // prepare child node
|
||||
} else {
|
||||
$x = & $x->{$assoc[$i+1]};
|
||||
$x = & $x->{$assoc[$i + 1]};
|
||||
}
|
||||
|
||||
|
||||
} else { // associative-array node
|
||||
$x = & $x[$row->$as];
|
||||
}
|
||||
@@ -424,7 +417,7 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
|
||||
if ($value === NULL) {
|
||||
if ($key !== NULL) {
|
||||
throw new InvalidArgumentException("Either none or both columns must be specified.");
|
||||
throw new InvalidArgumentException('Either none or both columns must be specified.');
|
||||
}
|
||||
|
||||
// autodetect
|
||||
@@ -478,7 +471,8 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
foreach ($this->getResultDriver()->getResultColumns() as $col) {
|
||||
$this->types[$col['name']] = $cache->{$col['nativetype']};
|
||||
}
|
||||
} catch (DibiNotSupportedException $e) {}
|
||||
} catch (DibiNotSupportedException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -494,13 +488,23 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
continue;
|
||||
}
|
||||
$value = $row[$key];
|
||||
if ($value === FALSE || $type === dibi::TEXT) {
|
||||
if ($type === dibi::TEXT) {
|
||||
|
||||
} elseif ($type === dibi::INTEGER) {
|
||||
$row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;
|
||||
|
||||
} elseif ($type === dibi::FLOAT) {
|
||||
$row[$key] = str_replace(',', '.', ltrim((string) ($tmp = (float) $value), '0')) === ltrim(rtrim(rtrim($value, '0'), '.'), '0') ? $tmp : $value;
|
||||
$value = ltrim($value, '0');
|
||||
$p = strpos($value, '.');
|
||||
if ($p !== FALSE) {
|
||||
$value = rtrim(rtrim($value, '0'), '.');
|
||||
}
|
||||
if ($value === '' || $value[0] === '.') {
|
||||
$value = '0' . $value;
|
||||
}
|
||||
$row[$key] = $value === str_replace(',', '.', (string) ($float = (float) $value))
|
||||
? $float
|
||||
: $value;
|
||||
|
||||
} elseif ($type === dibi::BOOL) {
|
||||
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
|
||||
@@ -619,7 +623,7 @@ class DibiResult extends DibiObject implements IDataSource
|
||||
|
||||
foreach ($row as $col => $val) {
|
||||
$spaces = $maxLen - mb_strlen($col) + 2;
|
||||
echo "$col" . str_repeat(" ", $spaces) . "$val\n";
|
||||
echo "$col" . str_repeat(' ', $spaces) . "$val\n";
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* unset($result);
|
||||
* </code>
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiResultIterator implements Iterator, Countable
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Result set single row.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiRow implements ArrayAccess, IteratorAggregate, Countable
|
||||
|
@@ -2,14 +2,13 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* dibi SQL translator.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
final class DibiTranslator extends DibiObject
|
||||
@@ -160,7 +159,7 @@ final class DibiTranslator extends DibiObject
|
||||
|
||||
|
||||
if ($comment) {
|
||||
$sql[] = "*/";
|
||||
$sql[] = '*/';
|
||||
}
|
||||
|
||||
$sql = implode(' ', $sql);
|
||||
@@ -187,7 +186,7 @@ final class DibiTranslator extends DibiObject
|
||||
public function formatValue($value, $modifier)
|
||||
{
|
||||
if ($this->comment) {
|
||||
return "...";
|
||||
return '...';
|
||||
}
|
||||
|
||||
if (!$this->driver) {
|
||||
@@ -216,7 +215,7 @@ final class DibiTranslator extends DibiObject
|
||||
$v = $this->formatValue($v, FALSE);
|
||||
$vx[] = $k . ($v === 'NULL' ? 'IS ' : '= ') . $v;
|
||||
|
||||
} elseif ($pair[1] === 'ex') { // TODO: this will be removed
|
||||
} elseif ($pair[1] === 'ex') {
|
||||
$vx[] = $k . $this->formatValue($v, 'ex');
|
||||
|
||||
} else {
|
||||
@@ -357,19 +356,24 @@ final class DibiTranslator extends DibiObject
|
||||
|
||||
case 'i': // signed int
|
||||
case 'u': // unsigned int, ignored
|
||||
// support for long numbers - keep them unchanged
|
||||
if (is_string($value) && preg_match('#[+-]?\d++(e\d+)?\z#A', $value)) {
|
||||
return $value;
|
||||
if ($value === NULL) {
|
||||
return 'NULL';
|
||||
} elseif (is_string($value) && preg_match('#[+-]?\d++(?:e\d+)?\z#A', $value)) {
|
||||
return $value; // support for long numbers - keep them unchanged
|
||||
} elseif (is_string($value) && substr($value, 1, 1) === 'x' && is_numeric($value)) {
|
||||
trigger_error('Support for hex strings has been deprecated.', E_USER_DEPRECATED);
|
||||
return (string) hexdec($value);
|
||||
} else {
|
||||
return $value === NULL ? 'NULL' : (string) (int) ($value + 0);
|
||||
return (string) (int) $value;
|
||||
}
|
||||
|
||||
case 'f': // float
|
||||
// support for extreme numbers - keep them unchanged
|
||||
if (is_string($value) && is_numeric($value) && strpos($value, 'x') === FALSE) {
|
||||
return $value; // something like -9E-005 is accepted by SQL, HEX values are not
|
||||
if ($value === NULL) {
|
||||
return 'NULL';
|
||||
} elseif (is_string($value) && is_numeric($value) && substr($value, 1, 1) !== 'x') {
|
||||
return $value; // support for extreme numbers - keep them unchanged
|
||||
} else {
|
||||
return $value === NULL ? 'NULL' : rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
|
||||
return rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
|
||||
}
|
||||
|
||||
case 'd': // date
|
||||
@@ -489,7 +493,7 @@ final class DibiTranslator extends DibiObject
|
||||
|
||||
if ($cursor >= count($this->args)) {
|
||||
$this->hasError = TRUE;
|
||||
return "**Extra placeholder**";
|
||||
return '**Extra placeholder**';
|
||||
}
|
||||
|
||||
$cursor++;
|
||||
@@ -512,7 +516,7 @@ final class DibiTranslator extends DibiObject
|
||||
// open comment
|
||||
$this->ifLevelStart = $this->ifLevel;
|
||||
$this->comment = TRUE;
|
||||
return "/*";
|
||||
return '/*';
|
||||
}
|
||||
return '';
|
||||
|
||||
@@ -520,11 +524,11 @@ final class DibiTranslator extends DibiObject
|
||||
if ($this->ifLevelStart === $this->ifLevel) {
|
||||
$this->ifLevelStart = 0;
|
||||
$this->comment = FALSE;
|
||||
return "*/";
|
||||
return '*/';
|
||||
} elseif (!$this->comment) {
|
||||
$this->ifLevelStart = $this->ifLevel;
|
||||
$this->comment = TRUE;
|
||||
return "/*";
|
||||
return '/*';
|
||||
}
|
||||
|
||||
} elseif ($mod === 'end') {
|
||||
@@ -533,7 +537,7 @@ final class DibiTranslator extends DibiObject
|
||||
// close comment
|
||||
$this->ifLevelStart = 0;
|
||||
$this->comment = FALSE;
|
||||
return "*/";
|
||||
return '*/';
|
||||
}
|
||||
return '';
|
||||
|
||||
@@ -578,10 +582,10 @@ final class DibiTranslator extends DibiObject
|
||||
return $this->identifiers->{$matches[2]};
|
||||
|
||||
} elseif ($matches[3]) { // SQL strings: '...'
|
||||
return $this->driver->escape( str_replace("''", "'", $matches[4]), dibi::TEXT);
|
||||
return $this->driver->escape(str_replace("''", "'", $matches[4]), dibi::TEXT);
|
||||
|
||||
} elseif ($matches[5]) { // SQL strings: "..."
|
||||
return $this->driver->escape( str_replace('""', '"', $matches[6]), dibi::TEXT);
|
||||
return $this->driver->escape(str_replace('""', '"', $matches[6]), dibi::TEXT);
|
||||
|
||||
} elseif ($matches[7]) { // string quote
|
||||
$this->hasError = TRUE;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
|
||||
*/
|
||||
|
||||
|
||||
@@ -184,7 +184,6 @@ interface IDibiResultDriver
|
||||
/**
|
||||
* dibi driver reflection.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
interface IDibiReflector
|
||||
|
@@ -11,11 +11,10 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
echo '<p>Connecting to Sqlite: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -26,11 +25,10 @@ echo "</p>\n";
|
||||
echo '<p>Connecting to Sqlite: ';
|
||||
try {
|
||||
$connection = new DibiConnection(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -42,7 +40,6 @@ echo '<p>Connecting to MySQL: ';
|
||||
try {
|
||||
dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=cp1250');
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -53,18 +50,17 @@ echo "</p>\n";
|
||||
echo '<p>Connecting to MySQLi: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'mysqli',
|
||||
'host' => 'localhost',
|
||||
'driver' => 'mysqli',
|
||||
'host' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'xxx',
|
||||
'database' => 'dibi',
|
||||
'options' => array(
|
||||
MYSQLI_OPT_CONNECT_TIMEOUT => 30
|
||||
'options' => array(
|
||||
MYSQLI_OPT_CONNECT_TIMEOUT => 30,
|
||||
),
|
||||
'flags' => MYSQLI_CLIENT_COMPRESS,
|
||||
'flags' => MYSQLI_CLIENT_COMPRESS,
|
||||
));
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -75,13 +71,12 @@ echo "</p>\n";
|
||||
echo '<p>Connecting to ODBC: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'odbc',
|
||||
'driver' => 'odbc',
|
||||
'username' => 'root',
|
||||
'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';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -92,12 +87,11 @@ echo "</p>\n";
|
||||
echo '<p>Connecting to PostgreSql: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'postgre',
|
||||
'string' => 'host=localhost port=5432 dbname=mary',
|
||||
'driver' => 'postgre',
|
||||
'string' => 'host=localhost port=5432 dbname=mary',
|
||||
'persistent' => TRUE,
|
||||
));
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -108,11 +102,10 @@ echo "</p>\n";
|
||||
echo '<p>Connecting to Sqlite via PDO: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'pdo',
|
||||
'dsn' => 'sqlite2::memory:',
|
||||
'driver' => 'pdo',
|
||||
'dsn' => 'sqlite2::memory:',
|
||||
));
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -123,13 +116,12 @@ echo "</p>\n";
|
||||
echo '<p>Connecting to MS SQL: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'mssql',
|
||||
'host' => 'localhost',
|
||||
'driver' => 'mssql',
|
||||
'host' => 'localhost',
|
||||
'username' => 'root',
|
||||
'password' => 'xxx',
|
||||
));
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -140,14 +132,13 @@ echo "</p>\n";
|
||||
echo '<p>Connecting to MS SQL 2005: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'mssql2005',
|
||||
'host' => '(local)',
|
||||
'driver' => 'mssql2005',
|
||||
'host' => '(local)',
|
||||
'username' => 'Administrator',
|
||||
'password' => 'xxx',
|
||||
'database' => 'main',
|
||||
));
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
@@ -158,13 +149,12 @@ echo "</p>\n";
|
||||
echo '<p>Connecting to Oracle: ';
|
||||
try {
|
||||
dibi::connect(array(
|
||||
'driver' => 'oracle',
|
||||
'driver' => 'oracle',
|
||||
'username' => 'root',
|
||||
'password' => 'xxx',
|
||||
'database' => 'db',
|
||||
));
|
||||
echo 'OK';
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
@@ -37,7 +37,7 @@ foreach ($table->getColumns() as $column) {
|
||||
echo "</ul>\n";
|
||||
|
||||
|
||||
echo "Indexes";
|
||||
echo 'Indexes';
|
||||
echo "<ul>\n";
|
||||
foreach ($table->getIndexes() as $index) {
|
||||
echo "<li>{$index->name} " . ($index->primary ? 'primary ' : '') . ($index->unique ? 'unique' : '') . ' (';
|
||||
|
@@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
|
@@ -12,7 +12,7 @@ Tracy\Debugger::enable();
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
|
@@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
|
@@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
@@ -32,13 +32,13 @@ dibi::test('
|
||||
|
||||
|
||||
// if & else & (optional) end
|
||||
dibi::test("
|
||||
dibi::test('
|
||||
SELECT *
|
||||
FROM people
|
||||
WHERE id > 0
|
||||
%if", ($foo > 0), "AND foo=?", $foo, "
|
||||
%else %if", ($bar > 0), "AND bar=?", $bar, "
|
||||
");
|
||||
%if', ($foo > 0), 'AND foo=?', $foo, '
|
||||
%else %if', ($bar > 0), 'AND bar=?', $bar, '
|
||||
');
|
||||
// -> SELECT * FROM people WHERE id > 0 AND bar=2
|
||||
|
||||
|
||||
|
@@ -10,7 +10,7 @@ date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
@@ -45,26 +45,26 @@ $array = array(
|
||||
'brand' => NULL,
|
||||
'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', ...) , (...) , (...)
|
||||
|
||||
|
||||
// dibi detects UPDATE command
|
||||
dibi::test("
|
||||
UPDATE colors SET", array(
|
||||
dibi::test('
|
||||
UPDATE colors SET', array(
|
||||
'color' => 'blue',
|
||||
'order' => 12,
|
||||
), "
|
||||
WHERE id=?", 123);
|
||||
), '
|
||||
WHERE id=?', 123);
|
||||
// -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123
|
||||
|
||||
|
||||
// modifier applied to array
|
||||
$array = array(1, 2, 3);
|
||||
dibi::test("
|
||||
dibi::test('
|
||||
SELECT *
|
||||
FROM people
|
||||
WHERE id IN (?)", $array
|
||||
WHERE id IN (?)', $array
|
||||
);
|
||||
// -> SELECT * FROM people WHERE id IN ( 1, 2, 3 )
|
||||
|
||||
@@ -74,11 +74,11 @@ $order = array(
|
||||
'field1' => 'asc',
|
||||
'field2' => 'desc',
|
||||
);
|
||||
dibi::test("
|
||||
dibi::test('
|
||||
SELECT *
|
||||
FROM people
|
||||
ORDER BY %by", $order, "
|
||||
");
|
||||
ORDER BY %by', $order, '
|
||||
');
|
||||
// -> SELECT * FROM people ORDER BY [field1] ASC, [field2] DESC
|
||||
|
||||
|
||||
|
@@ -14,7 +14,7 @@ date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
@@ -27,7 +27,7 @@ $res->setType('customer_id', Dibi::INTEGER)
|
||||
->setFormat(dibi::DATETIME, 'Y-m-d H:i:s');
|
||||
|
||||
|
||||
Tracy\Dumper::dump( $res->fetch() );
|
||||
Tracy\Dumper::dump($res->fetch());
|
||||
// outputs:
|
||||
// DibiRow(3) {
|
||||
// customer_id => 1
|
||||
@@ -38,7 +38,7 @@ Tracy\Dumper::dump( $res->fetch() );
|
||||
// using auto-detection (works well with MySQL or other strictly typed databases)
|
||||
$res = dibi::query('SELECT * FROM [customers]');
|
||||
|
||||
Tracy\Dumper::dump( $res->fetch() );
|
||||
Tracy\Dumper::dump($res->fetch());
|
||||
// outputs:
|
||||
// DibiRow(3) {
|
||||
// customer_id => 1
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
<h1>Tracy & SQL Exceptions | dibi</h1>
|
||||
|
||||
<p>Dibi can display and log exceptions via <a href="http://tracy.nette.org">Tracy</a>.</p>
|
||||
<p>Dibi can display and log exceptions via <a href="https://tracy.nette.org">Tracy</a>.</p>
|
||||
|
||||
<?php
|
||||
|
||||
@@ -16,11 +16,11 @@ Tracy\Debugger::enable();
|
||||
|
||||
|
||||
$connection = dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
'profiler' => array(
|
||||
'run' => TRUE,
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1>Tracy | dibi</h1>
|
||||
|
||||
<p>Dibi can log queries and dump variables to the <a href="http://tracy.nette.org">Tracy</a>.</p>
|
||||
<p>Dibi can log queries and dump variables to the <a href="https://tracy.nette.org">Tracy</a>.</p>
|
||||
|
||||
<?php
|
||||
|
||||
@@ -18,11 +18,11 @@ Tracy\Debugger::enable();
|
||||
|
||||
|
||||
$connection = dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
'profiler' => array(
|
||||
'run' => TRUE,
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
|
||||
@@ -35,4 +35,4 @@ $panel->register($connection);
|
||||
dibi::query('SELECT 123');
|
||||
|
||||
// result set will be dumped
|
||||
Tracy\Debugger::barDump( dibi::fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]' );
|
||||
Tracy\Debugger::barDump(dibi::fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]');
|
||||
|
@@ -11,7 +11,7 @@ date_default_timezone_set('Europe/Prague');
|
||||
|
||||
// CHANGE TO REAL PARAMETERS!
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
'formatDate' => "'Y-m-d'",
|
||||
'formatDateTime' => "'Y-m-d H-i-s'",
|
||||
@@ -19,10 +19,10 @@ dibi::connect(array(
|
||||
|
||||
|
||||
// generate and dump SQL
|
||||
dibi::test("
|
||||
INSERT INTO [mytable]", array(
|
||||
'id' => 123,
|
||||
'date' => new DateTime('12.3.2007'),
|
||||
dibi::test('
|
||||
INSERT INTO [mytable]', array(
|
||||
'id' => 123,
|
||||
'date' => new DateTime('12.3.2007'),
|
||||
'stamp' => new DateTime('23.1.2007 10:23'),
|
||||
)
|
||||
);
|
||||
|
@@ -12,14 +12,13 @@ Tracy\Debugger::enable();
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
|
||||
// using the "prototype" to add custom method to class DibiResult
|
||||
DibiResult::extensionMethod('fetchShuffle', function(DibiResult $obj)
|
||||
{
|
||||
DibiResult::extensionMethod('fetchShuffle', function (DibiResult $obj) {
|
||||
$all = $obj->fetchAll();
|
||||
shuffle($all);
|
||||
return $all;
|
||||
|
@@ -10,15 +10,15 @@ date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
|
||||
$id = 10;
|
||||
$record = array(
|
||||
'title' => 'Super product',
|
||||
'price' => 318,
|
||||
'title' => 'Super product',
|
||||
'price' => 318,
|
||||
'active' => TRUE,
|
||||
);
|
||||
|
||||
|
@@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
|
@@ -10,7 +10,7 @@ date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
// enable query logging to this file
|
||||
'profiler' => array(
|
||||
@@ -26,13 +26,12 @@ try {
|
||||
$res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < ?', 5);
|
||||
|
||||
$res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < ?', 38);
|
||||
|
||||
} catch (DibiException $e) {
|
||||
echo '<p>', get_class($e), ': ', $e->getMessage(), '</p>';
|
||||
}
|
||||
|
||||
|
||||
// outputs a log file
|
||||
echo "<h2>File data/log.sql:</h2>";
|
||||
echo '<h2>File data/log.sql:</h2>';
|
||||
|
||||
echo '<pre>', file_get_contents('data/log.sql'), '</pre>';
|
||||
|
@@ -10,16 +10,16 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
'profiler' => array(
|
||||
'run' => TRUE,
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
|
||||
// execute some queries...
|
||||
for ($i=0; $i<20; $i++) {
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < ?', $i);
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
@@ -16,7 +16,7 @@ dibi::connect(array(
|
||||
// create new substitution :blog: ==> wp_
|
||||
dibi::getSubstitutes()->blog = 'wp_';
|
||||
|
||||
dibi::test("SELECT * FROM [:blog:items]");
|
||||
dibi::test('SELECT * FROM [:blog:items]');
|
||||
// -> SELECT * FROM [wp_items]
|
||||
|
||||
|
||||
|
@@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite3',
|
||||
'driver' => 'sqlite3',
|
||||
'database' => 'data/sample.s3db',
|
||||
));
|
||||
|
||||
|
@@ -16,7 +16,7 @@ remains intact.
|
||||
New BSD License
|
||||
---------------
|
||||
|
||||
Copyright (c) 2004, 2014 David Grudl (http://davidgrudl.com)
|
||||
Copyright (c) 2004, 2014 David Grudl (https://davidgrudl.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
|
@@ -1,13 +1,15 @@
|
||||
[Dibi](http://dibiphp.com) - smart database layer for PHP [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XXL5ZJHAYQUN)
|
||||
[Dibi](http://dibiphp.com) - smart database layer for PHP [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9XXL5ZJHAYQUN)
|
||||
=========================================================
|
||||
|
||||
[](https://packagist.org/packages/dibi/dibi)
|
||||
[](https://travis-ci.org/dg/dibi)
|
||||
[](https://github.com/dg/dibi/releases)
|
||||
[](https://github.com/dg/dibi/blob/master/license.md)
|
||||
|
||||
Database access functions in PHP are not standardised. This library
|
||||
hides the differences between them, and above all, it gives you a very handy interface.
|
||||
|
||||
The best way to install Dibi is to use a [Composer](http://getcomposer.org/download):
|
||||
The best way to install Dibi is to use a [Composer](https://getcomposer.org/download):
|
||||
|
||||
php composer.phar require dibi/dibi
|
||||
|
||||
|
@@ -11,9 +11,9 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
$ds = $conn->dataSource('SELECT * FROM products');
|
||||
Assert::match(
|
||||
reformat("
|
||||
reformat('
|
||||
SELECT *
|
||||
FROM (SELECT * FROM products) t"),
|
||||
FROM (SELECT * FROM products) t'),
|
||||
(string) $ds
|
||||
);
|
||||
|
||||
@@ -111,9 +111,9 @@ FROM (SELECT * FROM products) t
|
||||
|
||||
$ds = $conn->select('title')->from('products')->toDataSource();
|
||||
Assert::match(
|
||||
reformat("
|
||||
reformat('
|
||||
SELECT *
|
||||
FROM (SELECT [title] FROM [products]) t"),
|
||||
FROM (SELECT [title] FROM [products]) t'),
|
||||
(string) $ds
|
||||
);
|
||||
|
||||
@@ -148,9 +148,9 @@ Assert::equal(array(
|
||||
$ds = new DibiDataSource('products', $conn);
|
||||
|
||||
Assert::match(
|
||||
reformat("
|
||||
reformat('
|
||||
SELECT *
|
||||
FROM [products]"),
|
||||
FROM [products]'),
|
||||
(string) $ds
|
||||
);
|
||||
|
||||
|
@@ -9,7 +9,7 @@ use Tester\Assert;
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
|
||||
test(function() use ($config) {
|
||||
test(function () use ($config) {
|
||||
$conn = new DibiConnection($config);
|
||||
Assert::true($conn->isConnected());
|
||||
|
||||
@@ -18,7 +18,7 @@ test(function() use ($config) {
|
||||
});
|
||||
|
||||
|
||||
test(function() use ($config) { // lazy
|
||||
test(function () use ($config) { // lazy
|
||||
$conn = new DibiConnection($config + array('lazy' => TRUE));
|
||||
Assert::false($conn->isConnected());
|
||||
|
||||
@@ -27,7 +27,7 @@ test(function() use ($config) { // lazy
|
||||
});
|
||||
|
||||
|
||||
test(function() use ($config) { // query string
|
||||
test(function () use ($config) { // query string
|
||||
$conn = new DibiConnection(http_build_query($config, NULL, '&'));
|
||||
Assert::true($conn->isConnected());
|
||||
|
||||
|
@@ -13,16 +13,16 @@ $conn = new DibiConnection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
/*Assert::exception(function() use ($conn) {
|
||||
/*Assert::exception(function () use ($conn) {
|
||||
$conn->rollback();
|
||||
}, 'DibiException');
|
||||
|
||||
Assert::exception(function() use ($conn) {
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->commit();
|
||||
}, 'DibiException');
|
||||
|
||||
$conn->begin();
|
||||
Assert::exception(function() use ($conn) {
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->begin();
|
||||
}, 'DibiException');
|
||||
*/
|
||||
|
@@ -13,23 +13,23 @@ $dolly = clone $fluent;
|
||||
$dolly->where('y=1');
|
||||
$dolly->clause('FOO');
|
||||
|
||||
Assert::same( reformat('SELECT * FROM [table] WHERE x=1'), (string) $fluent );
|
||||
Assert::same( reformat('SELECT * FROM [table] WHERE x=1 AND y=1 FOO'), (string) $dolly );
|
||||
Assert::same(reformat('SELECT * FROM [table] WHERE x=1'), (string) $fluent);
|
||||
Assert::same(reformat('SELECT * FROM [table] WHERE x=1 AND y=1 FOO'), (string) $dolly);
|
||||
|
||||
|
||||
$fluent = new DibiFluent($conn);
|
||||
$fluent->select('id')->from('table')->where('id = %i',1);
|
||||
$fluent->select('id')->from('table')->where('id = %i', 1);
|
||||
$dolly = clone $fluent;
|
||||
$dolly->where('cd = %i',5);
|
||||
$dolly->where('cd = %i', 5);
|
||||
|
||||
Assert::same( reformat('SELECT [id] FROM [table] WHERE id = 1'), (string) $fluent );
|
||||
Assert::same( reformat('SELECT [id] FROM [table] WHERE id = 1 AND cd = 5'), (string) $dolly );
|
||||
Assert::same(reformat('SELECT [id] FROM [table] WHERE id = 1'), (string) $fluent);
|
||||
Assert::same(reformat('SELECT [id] FROM [table] WHERE id = 1 AND cd = 5'), (string) $dolly);
|
||||
|
||||
|
||||
$fluent = new DibiFluent($conn);
|
||||
$fluent->select("*")->from("table");
|
||||
$fluent->select('*')->from('table');
|
||||
$dolly = clone $fluent;
|
||||
$dolly->removeClause("select")->select("count(*)");
|
||||
$dolly->removeClause('select')->select('count(*)');
|
||||
|
||||
Assert::same( reformat('SELECT * FROM [table]'), (string) $fluent );
|
||||
Assert::same( reformat('SELECT count(*) FROM [table]'), (string) $dolly );
|
||||
Assert::same(reformat('SELECT * FROM [table]'), (string) $fluent);
|
||||
Assert::same(reformat('SELECT count(*) FROM [table]'), (string) $dolly);
|
||||
|
92
tests/dibi/DibiFluent.fetch.limit.phpt
Normal file
92
tests/dibi/DibiFluent.fetch.limit.phpt
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new DibiConnection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
// fetch & limit
|
||||
$fluent = $conn->select('*')
|
||||
->from('customers')
|
||||
->limit(1)
|
||||
->offset(3)
|
||||
->orderBy('customer_id');
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->limit(0);
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->removeClause('limit');
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] OFFSET 3'),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->removeClause('offset');
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id]'),
|
||||
(string) $fluent
|
||||
);
|
@@ -9,9 +9,9 @@ $conn = new DibiConnection($config);
|
||||
|
||||
|
||||
$arr = array(
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
);
|
||||
|
||||
$fluent = $conn->insert('table', $arr)
|
||||
|
@@ -58,7 +58,7 @@ Assert::same(
|
||||
$fluent->where('col > %i', $max)
|
||||
->or('col < %i', $min)
|
||||
->where('active = 1')
|
||||
->where('col')->in(array(1,2,3))
|
||||
->where('col')->in(array(1, 2, 3))
|
||||
->orderBy('val')->asc()
|
||||
->orderBy('[val2] DESC')
|
||||
->orderBy(array('val3' => -1));
|
||||
@@ -81,7 +81,7 @@ try {
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
Assert::same(
|
||||
reformat(' SELECT * FROM [table] LIMIT 1'),
|
||||
reformat('SELECT * FROM [table] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
|
||||
|
@@ -9,9 +9,9 @@ $conn = new DibiConnection($config);
|
||||
|
||||
|
||||
$arr = array(
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
);
|
||||
|
||||
$fluent = $conn->update('table', $arr)
|
||||
|
70
tests/dibi/DibiObject.phpt
Normal file
70
tests/dibi/DibiObject.phpt
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
|
||||
class TestClass extends DibiObject
|
||||
{
|
||||
public function getBar()
|
||||
{
|
||||
return 123;
|
||||
}
|
||||
|
||||
public function isFoo()
|
||||
{
|
||||
return 456;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// calling
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->undeclared();
|
||||
}, 'LogicException', 'Call to undefined method TestClass::undeclared().');
|
||||
|
||||
Assert::exception(function () {
|
||||
TestClass::undeclared();
|
||||
}, 'LogicException', 'Call to undefined static method TestClass::undeclared().');
|
||||
|
||||
|
||||
// writing
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->undeclared = 'value';
|
||||
}, 'LogicException', 'Cannot assign to an undeclared property TestClass::$undeclared.');
|
||||
|
||||
|
||||
// property getter
|
||||
$obj = new TestClass;
|
||||
Assert::true(isset($obj->bar));
|
||||
Assert::same(123, $obj->bar);
|
||||
Assert::false(isset($obj->foo));
|
||||
Assert::same(456, $obj->foo);
|
||||
|
||||
|
||||
// reading
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$val = $obj->undeclared;
|
||||
}, 'LogicException', 'Cannot read an undeclared property TestClass::$undeclared.');
|
||||
|
||||
|
||||
// unset/isset
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
unset($obj->undeclared);
|
||||
}, 'LogicException', 'Cannot unset the property TestClass::$undeclared.');
|
||||
|
||||
Assert::false(isset($obj->undeclared));
|
||||
|
||||
|
||||
// extension method
|
||||
TestClass::extensionMethod('join', $func = function (TestClass $that, $separator) {
|
||||
return $that->foo . $separator . $that->bar;
|
||||
});
|
||||
|
||||
$obj = new TestClass;
|
||||
Assert::same('456*123', $obj->join('*'));
|
130
tests/dibi/DibiResult.normalize.phpt
Normal file
130
tests/dibi/DibiResult.normalize.phpt
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
|
||||
class MockResult extends DibiResult
|
||||
{
|
||||
function __construct()
|
||||
{}
|
||||
|
||||
function test($row)
|
||||
{
|
||||
$normalize = new ReflectionMethod('DibiResult', 'normalize');
|
||||
$normalize->setAccessible(TRUE);
|
||||
$normalize->invokeArgs($this, array(& $row));
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
test(function () {
|
||||
$result = new MockResult;
|
||||
$result->setType('col', dibi::BOOL);
|
||||
|
||||
Assert::same(array('col' => NULL), $result->test(array('col' => NULL)));
|
||||
Assert::same(array('col' => TRUE), $result->test(array('col' => TRUE)));
|
||||
Assert::same(array('col' => FALSE), $result->test(array('col' => FALSE)));
|
||||
|
||||
Assert::same(array('col' => FALSE), $result->test(array('col' => '')));
|
||||
Assert::same(array('col' => FALSE), $result->test(array('col' => '0')));
|
||||
Assert::same(array('col' => TRUE), $result->test(array('col' => '1')));
|
||||
Assert::same(array('col' => TRUE), $result->test(array('col' => 't')));
|
||||
Assert::same(array('col' => FALSE), $result->test(array('col' => 'f')));
|
||||
Assert::same(array('col' => TRUE), $result->test(array('col' => 'T')));
|
||||
Assert::same(array('col' => FALSE), $result->test(array('col' => 'F')));
|
||||
Assert::same(array('col' => FALSE), $result->test(array('col' => 0)));
|
||||
Assert::same(array('col' => FALSE), $result->test(array('col' => 0.0)));
|
||||
Assert::same(array('col' => TRUE), $result->test(array('col' => 1)));
|
||||
Assert::same(array('col' => TRUE), $result->test(array('col' => 1.0)));
|
||||
});
|
||||
|
||||
|
||||
test(function () {
|
||||
$result = new MockResult;
|
||||
$result->setType('col', dibi::TEXT); // means TEXT or UNKNOWN
|
||||
|
||||
Assert::same(array('col' => NULL), $result->test(array('col' => NULL)));
|
||||
Assert::same(array('col' => TRUE), $result->test(array('col' => TRUE)));
|
||||
Assert::same(array('col' => FALSE), $result->test(array('col' => FALSE)));
|
||||
|
||||
Assert::same(array('col' => ''), $result->test(array('col' => '')));
|
||||
Assert::same(array('col' => '0'), $result->test(array('col' => '0')));
|
||||
Assert::same(array('col' => '1'), $result->test(array('col' => '1')));
|
||||
Assert::same(array('col' => 0), $result->test(array('col' => 0)));
|
||||
Assert::same(array('col' => 1), $result->test(array('col' => 1)));
|
||||
});
|
||||
|
||||
|
||||
test(function () {
|
||||
$result = new MockResult;
|
||||
$result->setType('col', dibi::FLOAT);
|
||||
|
||||
Assert::same(array('col' => NULL), $result->test(array('col' => NULL)));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => TRUE)));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => FALSE)));
|
||||
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '')));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '0')));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => '1')));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '.0')));
|
||||
Assert::same(array('col' => 0.1), $result->test(array('col' => '.1')));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '0.0')));
|
||||
Assert::same(array('col' => 0.1), $result->test(array('col' => '0.1')));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '0.000')));
|
||||
Assert::same(array('col' => 0.1), $result->test(array('col' => '0.100')));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => '1.0')));
|
||||
Assert::same(array('col' => 1.1), $result->test(array('col' => '1.1')));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => '1.000')));
|
||||
Assert::same(array('col' => 1.1), $result->test(array('col' => '1.100')));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => '001.000')));
|
||||
Assert::same(array('col' => 1.1), $result->test(array('col' => '001.100')));
|
||||
Assert::same(array('col' => 10.0), $result->test(array('col' => '10')));
|
||||
Assert::same(array('col' => 11.0), $result->test(array('col' => '11')));
|
||||
Assert::same(array('col' => 10.0), $result->test(array('col' => '0010')));
|
||||
Assert::same(array('col' => 11.0), $result->test(array('col' => '0011')));
|
||||
Assert::same(array('col' => '0.00000000000000000001'), $result->test(array('col' => '0.00000000000000000001')));
|
||||
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '12345678901234567890')));
|
||||
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '012345678901234567890')));
|
||||
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '12345678901234567890.000')));
|
||||
Assert::same(array('col' => '12345678901234567890.1'), $result->test(array('col' => '012345678901234567890.100')));
|
||||
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => 0)));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => 0.0)));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => 1)));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => 1.0)));
|
||||
|
||||
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '')));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '0')));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => '1')));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '.0')));
|
||||
Assert::same(array('col' => 0.1), $result->test(array('col' => '.1')));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '0.0')));
|
||||
Assert::same(array('col' => 0.1), $result->test(array('col' => '0.1')));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => '0.000')));
|
||||
Assert::same(array('col' => 0.1), $result->test(array('col' => '0.100')));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => '1.0')));
|
||||
Assert::same(array('col' => 1.1), $result->test(array('col' => '1.1')));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => '1.000')));
|
||||
Assert::same(array('col' => 1.1), $result->test(array('col' => '1.100')));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => '001.000')));
|
||||
Assert::same(array('col' => 1.1), $result->test(array('col' => '001.100')));
|
||||
Assert::same(array('col' => 10.0), $result->test(array('col' => '10')));
|
||||
Assert::same(array('col' => 11.0), $result->test(array('col' => '11')));
|
||||
Assert::same(array('col' => 10.0), $result->test(array('col' => '0010')));
|
||||
Assert::same(array('col' => 11.0), $result->test(array('col' => '0011')));
|
||||
Assert::same(array('col' => '0.00000000000000000001'), $result->test(array('col' => '0.00000000000000000001')));
|
||||
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '12345678901234567890')));
|
||||
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '012345678901234567890')));
|
||||
Assert::same(array('col' => '12345678901234567890'), $result->test(array('col' => '12345678901234567890.000')));
|
||||
Assert::same(array('col' => '12345678901234567890.1'), $result->test(array('col' => '012345678901234567890.100')));
|
||||
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => 0)));
|
||||
Assert::same(array('col' => 0.0), $result->test(array('col' => 0.0)));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => 1)));
|
||||
Assert::same(array('col' => 1.0), $result->test(array('col' => 1.0)));
|
||||
setlocale(LC_NUMERIC, 'C');
|
||||
});
|
42
tests/dibi/DibiRow.phpt
Normal file
42
tests/dibi/DibiRow.phpt
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini mysqli
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new DibiConnection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
$row = $conn->fetch('SELECT * FROM [products] ORDER BY product_id');
|
||||
|
||||
// existing
|
||||
Assert::same('Chair', $row->title);
|
||||
Assert::true(isset($row->title));
|
||||
Assert::same('Chair', $row['title']);
|
||||
Assert::true(isset($row['title']));
|
||||
|
||||
|
||||
// missing
|
||||
Assert::error(function () use ($row) {
|
||||
$x = $row->missing;
|
||||
}, E_NOTICE, 'Undefined property: DibiRow::$missing');
|
||||
|
||||
Assert::error(function () use ($row) {
|
||||
$x = $row['missing'];
|
||||
}, E_NOTICE, 'Undefined property: DibiRow::$missing');
|
||||
|
||||
Assert::false(isset($row->missing));
|
||||
Assert::false(isset($row['missing']));
|
||||
|
||||
|
||||
// to array
|
||||
Assert::same(array('product_id' => 1, 'title' => 'Chair'), iterator_to_array($row));
|
||||
Assert::same(array('product_id' => 1, 'title' => 'Chair'), $row->toArray());
|
||||
|
||||
// counting
|
||||
Assert::same(2, count($row));
|
@@ -13,10 +13,10 @@ $conn = new DibiConnection($config);
|
||||
|
||||
// if & end
|
||||
Assert::same(
|
||||
reformat("
|
||||
reformat('
|
||||
SELECT *
|
||||
FROM [customers]
|
||||
/* WHERE ... LIKE ... */"),
|
||||
/* WHERE ... LIKE ... */'),
|
||||
|
||||
$conn->translate('
|
||||
SELECT *
|
||||
@@ -27,9 +27,9 @@ FROM [customers]
|
||||
|
||||
// if & else & end (last end is optional)
|
||||
Assert::same(
|
||||
reformat("
|
||||
reformat('
|
||||
SELECT *
|
||||
FROM [customers] /* ... */"),
|
||||
FROM [customers] /* ... */'),
|
||||
|
||||
$conn->translate('
|
||||
SELECT *
|
||||
@@ -39,21 +39,21 @@ FROM %if', TRUE, '[customers] %else [products]'
|
||||
|
||||
// if & else & (optional) end
|
||||
Assert::match(
|
||||
reformat("
|
||||
reformat('
|
||||
SELECT *
|
||||
FROM [people]
|
||||
WHERE [id] > 0
|
||||
/* AND ...=...
|
||||
*/ AND [bar]=1
|
||||
"),
|
||||
'),
|
||||
|
||||
$conn->translate("
|
||||
$conn->translate('
|
||||
SELECT *
|
||||
FROM [people]
|
||||
WHERE [id] > 0
|
||||
%if", FALSE, "AND [foo]=%i", 1, "
|
||||
%else %if", TRUE, "AND [bar]=%i", 1, "
|
||||
"));
|
||||
%if', FALSE, 'AND [foo]=%i', 1, '
|
||||
%else %if', TRUE, 'AND [bar]=%i', 1, '
|
||||
'));
|
||||
|
||||
|
||||
// nested condition
|
||||
|
@@ -15,32 +15,32 @@ $conn = new DibiConnection($config + array('formatDateTime' => "'Y-m-d H:i:s'",
|
||||
Assert::same(
|
||||
reformat("REPLACE INTO [products] ([title], [price]) VALUES ('Drticka', 318)"),
|
||||
$conn->translate('REPLACE INTO [products]', array(
|
||||
'title' => 'Drticka',
|
||||
'price' => 318,
|
||||
'title' => 'Drticka',
|
||||
'price' => 318,
|
||||
)));
|
||||
|
||||
|
||||
// multiple INSERT command
|
||||
$array = array(
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
'title' => 'Super Product',
|
||||
'price' => 12,
|
||||
'brand' => NULL,
|
||||
);
|
||||
Assert::same(
|
||||
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)
|
||||
);
|
||||
|
||||
|
||||
// multiple INSERT command II
|
||||
$array = array(
|
||||
array('pole' => 'hodnota1', 'bit' => 1),
|
||||
array('pole' => 'hodnota2', 'bit' => 1),
|
||||
array('pole' => 'hodnota3', 'bit' => 1)
|
||||
array('pole' => 'hodnota1', 'bit' => 1),
|
||||
array('pole' => 'hodnota2', 'bit' => 1),
|
||||
array('pole' => 'hodnota3', 'bit' => 1),
|
||||
);
|
||||
Assert::same(
|
||||
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)
|
||||
);
|
||||
|
||||
|
||||
@@ -50,38 +50,32 @@ Assert::same(
|
||||
$conn->translate('UPDATE [colors] SET', array(
|
||||
'color' => 'blue',
|
||||
'order' => 12,
|
||||
), "WHERE [id]=%i", 123));
|
||||
), 'WHERE [id]=%i', 123));
|
||||
|
||||
|
||||
// IN array
|
||||
$array = array(1, 2, 3);
|
||||
Assert::same(
|
||||
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, ')')
|
||||
);
|
||||
|
||||
|
||||
// long numbers
|
||||
Assert::same(
|
||||
reformat('SELECT -123456789123456789123456789'),
|
||||
$conn->translate("SELECT %i", '-123456789123456789123456789')
|
||||
$conn->translate('SELECT %i', '-123456789123456789123456789')
|
||||
);
|
||||
|
||||
// long float numbers
|
||||
Assert::same(
|
||||
reformat('SELECT -.12345678912345678912345678e10'),
|
||||
$conn->translate("SELECT %f", '-.12345678912345678912345678e10')
|
||||
);
|
||||
|
||||
// hex numbers
|
||||
Assert::same(
|
||||
reformat('SELECT 17'),
|
||||
$conn->translate("SELECT %i", '0x11')
|
||||
$conn->translate('SELECT %f', '-.12345678912345678912345678e10')
|
||||
);
|
||||
|
||||
// invalid input
|
||||
$e = Assert::exception(function() use ($conn) {
|
||||
$conn->translate("SELECT %s", (object) array(123), ', %m', 123);
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->translate('SELECT %s', (object) array(123), ', %m', 123);
|
||||
}, 'DibiException', 'SQL translate error');
|
||||
Assert::same('SELECT **Unexpected type object** , **Unknown or invalid modifier %m**', $e->getSql());
|
||||
|
||||
@@ -137,8 +131,8 @@ $order = array(
|
||||
'field6' => FALSE,
|
||||
);
|
||||
Assert::same(
|
||||
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)
|
||||
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)
|
||||
);
|
||||
|
||||
|
||||
@@ -152,7 +146,7 @@ Assert::same(
|
||||
);
|
||||
|
||||
if ($config['system'] === 'odbc') {
|
||||
Assert::exception(function() use ($conn) {
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1);
|
||||
}, 'DibiException');
|
||||
} else {
|
||||
@@ -181,7 +175,7 @@ Assert::same(
|
||||
'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)",
|
||||
)),
|
||||
$conn->translate("INSERT INTO test", array(
|
||||
$conn->translate('INSERT INTO test', array(
|
||||
'a2' => new DibiDateTime('1212-09-26'),
|
||||
'a4' => new DibiDateTime(-10000),
|
||||
'b1%d' => '1212-09-26',
|
||||
@@ -199,10 +193,10 @@ Assert::same(
|
||||
|
||||
// like
|
||||
$args = array(
|
||||
"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',
|
||||
'r',
|
||||
"a\n%_\\'\""
|
||||
"a\n%_\\'\"",
|
||||
);
|
||||
|
||||
if ($config['system'] === 'pgsql') {
|
||||
@@ -219,7 +213,6 @@ if ($config['system'] === 'pgsql') {
|
||||
"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])
|
||||
);
|
||||
|
||||
} elseif ($config['driver'] !== 'sqlite') { // sqlite2
|
||||
Assert::same(
|
||||
reformat(array(
|
||||
@@ -232,7 +225,7 @@ if ($config['system'] === 'pgsql') {
|
||||
}
|
||||
|
||||
|
||||
$e = Assert::exception(function() use ($conn) {
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->translate("SELECT '");
|
||||
}, 'DibiException', 'SQL translate error');
|
||||
Assert::same('SELECT **Alone quote**', $e->getSql());
|
||||
@@ -254,12 +247,12 @@ HAVING MAX(salary) > %i 123
|
||||
INTO OUTFILE '/tmp/result''.txt'
|
||||
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
|
||||
LINES TERMINATED BY '\\n'
|
||||
"
|
||||
",
|
||||
)),
|
||||
$conn->translate('%sql', "SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT
|
||||
CONCAT(last_name, \", \", first_name) AS full_name
|
||||
$conn->translate('%sql', 'SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT
|
||||
CONCAT(last_name, ", ", first_name) AS full_name
|
||||
GROUP BY [user]
|
||||
HAVING MAX(salary) > %i", 123, "
|
||||
HAVING MAX(salary) > %i', 123, "
|
||||
INTO OUTFILE '/tmp/result''.txt'
|
||||
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
|
||||
LINES TERMINATED BY '\\n'
|
||||
@@ -278,10 +271,10 @@ $array3 = array(
|
||||
'col3' => 'three',
|
||||
);
|
||||
$array4 = array(
|
||||
'a' => 12,
|
||||
'b' => NULL,
|
||||
'c' => new DibiDateTime('12.3.2007'),
|
||||
'd' => 'any string',
|
||||
'a' => 12,
|
||||
'b' => NULL,
|
||||
'c' => new DibiDateTime('12.3.2007'),
|
||||
'd' => 'any string',
|
||||
);
|
||||
|
||||
$array5 = array('RAND()', '[col1] > [col2]');
|
||||
@@ -371,26 +364,26 @@ WHERE ([test].[a] LIKE '1995-03-01'
|
||||
LIMIT 10",
|
||||
)),
|
||||
|
||||
$conn->translate("SELECT *
|
||||
$conn->translate('SELECT *
|
||||
FROM [db.table]
|
||||
WHERE ([test.a] LIKE %d", '1995-03-01', "
|
||||
OR [b1] IN (", $array1, ")
|
||||
OR [b2] IN (%s", $array1, ")
|
||||
OR [b3] IN (%s", array(), ")
|
||||
OR [b4] IN (", $array2, ")
|
||||
OR [b5] IN (%n", $array3, ")
|
||||
OR [b6] IN %l", $array3, "
|
||||
OR [b7] IN %in", array(), "
|
||||
OR [b8] IN (%sql", $array5, ")
|
||||
OR [b9] IN (", array(), ")
|
||||
WHERE ([test.a] LIKE %d', '1995-03-01', '
|
||||
OR [b1] IN (', $array1, ')
|
||||
OR [b2] IN (%s', $array1, ')
|
||||
OR [b3] IN (%s', array(), ')
|
||||
OR [b4] IN (', $array2, ')
|
||||
OR [b5] IN (%n', $array3, ')
|
||||
OR [b6] IN %l', $array3, '
|
||||
OR [b7] IN %in', array(), '
|
||||
OR [b8] IN (%sql', $array5, ')
|
||||
OR [b9] IN (', array(), ")
|
||||
AND [c] = 'embedded '' string'
|
||||
OR [d]=%i", 10.3, "
|
||||
OR [e]=%i", NULL, "
|
||||
OR [true]=", TRUE, "
|
||||
OR [false]=", FALSE, "
|
||||
OR [str_null]=%sn", '', "
|
||||
OR [str_not_null]=%sn", 'hello', "
|
||||
LIMIT 10")
|
||||
OR [d]=%i", 10.3, '
|
||||
OR [e]=%i', NULL, '
|
||||
OR [true]=', TRUE, '
|
||||
OR [false]=', FALSE, '
|
||||
OR [str_null]=%sn', '', '
|
||||
OR [str_not_null]=%sn', 'hello', '
|
||||
LIMIT 10')
|
||||
);
|
||||
|
||||
|
||||
@@ -472,7 +465,7 @@ Assert::same(
|
||||
);
|
||||
|
||||
|
||||
$e = Assert::exception(function() use ($conn) {
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$array6 = array(
|
||||
'id' => array(1, 2, 3, 4),
|
||||
'text' => array('ahoj', 'jak', 'se', array('SUM(%i)', '5')),
|
||||
@@ -494,14 +487,14 @@ Assert::same(
|
||||
);
|
||||
|
||||
|
||||
$by = array (
|
||||
$by = array(
|
||||
array('funkce(nazev_pole) ASC'),
|
||||
'jine_pole' => 'DESC'
|
||||
'jine_pole' => 'DESC',
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM table ORDER BY funkce(nazev_pole) ASC, [jine_pole] DESC'),
|
||||
$conn->translate("SELECT * FROM table ORDER BY %by", $by)
|
||||
$conn->translate('SELECT * FROM table ORDER BY %by', $by)
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
@@ -520,12 +513,12 @@ setLocale(LC_ALL, 'czech');
|
||||
Assert::same(
|
||||
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', array(
|
||||
'color' => 'blue',
|
||||
'price' => -12.4,
|
||||
'spec%f' => '-9E-005',
|
||||
'spec2%f' => 1000.00,
|
||||
'spec3%i' => 10000,
|
||||
'spec4' => 10000,
|
||||
), "WHERE [price]=%f", 123.5)
|
||||
), 'WHERE [price]=%f', 123.5)
|
||||
);
|
||||
|
80
tests/dibi/PdoMssql.limits.phpt
Normal file
80
tests/dibi/PdoMssql.limits.phpt
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
if ($config['system'] !== 'mssql' || $config['driver'] !== 'pdo') {
|
||||
Tester\Environment::skip("Not supported system '$config[system]'.");
|
||||
}
|
||||
|
||||
$tests = function ($conn) {
|
||||
$version = $conn->getDriver()->getResource()->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
|
||||
// MsSQL2012+
|
||||
if (version_compare($version, '11.0') >= 0) {
|
||||
// Limit and offset
|
||||
Assert::same(
|
||||
'SELECT 1 OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY',
|
||||
$conn->translate('SELECT 1 %ofs %lmt', 10, 10)
|
||||
);
|
||||
|
||||
// Limit only
|
||||
Assert::same(
|
||||
'SELECT 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY',
|
||||
$conn->translate('SELECT 1 %lmt', 10)
|
||||
);
|
||||
|
||||
// Offset only
|
||||
Assert::same(
|
||||
'SELECT 1 OFFSET 10 ROWS',
|
||||
$conn->translate('SELECT 1 %ofs', 10)
|
||||
);
|
||||
|
||||
// Offset invalid
|
||||
Assert::same(
|
||||
'SELECT 1',
|
||||
$conn->translate('SELECT 1 %ofs', -10)
|
||||
);
|
||||
|
||||
// Limit invalid
|
||||
Assert::same(
|
||||
'SELECT 1',
|
||||
$conn->translate('SELECT 1 %lmt', -10)
|
||||
);
|
||||
|
||||
// Limit invalid, offset valid
|
||||
Assert::same(
|
||||
'SELECT 1',
|
||||
$conn->translate('SELECT 1 %ofs %lmt', 10, -10)
|
||||
);
|
||||
|
||||
// Limit valid, offset invalid
|
||||
Assert::same(
|
||||
'SELECT 1',
|
||||
$conn->translate('SELECT 1 %ofs %lmt', -10, 10)
|
||||
);
|
||||
} else {
|
||||
Assert::same(
|
||||
'SELECT TOP 1 * FROM (SELECT 1) t',
|
||||
$conn->translate('SELECT 1 %lmt', 1)
|
||||
);
|
||||
|
||||
Assert::same(
|
||||
'SELECT 1',
|
||||
$conn->translate('SELECT 1 %lmt', -10)
|
||||
);
|
||||
|
||||
Assert::exception(
|
||||
$conn->translate('SELECT 1 %ofs %lmt', 10, 10),
|
||||
'DibiNotSupportedException'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
$conn = new DibiConnection($config);
|
||||
$tests($conn);
|
@@ -13,16 +13,16 @@ if ($config['system'] !== 'pgsql') {
|
||||
}
|
||||
|
||||
|
||||
$tests = function($conn) {
|
||||
$tests = function ($conn) {
|
||||
Assert::false($conn->query("SELECT 'AAxBB' LIKE %~like~", 'A_B')->fetchSingle());
|
||||
Assert::true( $conn->query("SELECT 'AA_BB' LIKE %~like~", 'A_B')->fetchSingle());
|
||||
Assert::true($conn->query("SELECT 'AA_BB' LIKE %~like~", 'A_B')->fetchSingle());
|
||||
|
||||
Assert::false($conn->query("SELECT 'AAxBB' LIKE %~like~", 'A%B')->fetchSingle());
|
||||
Assert::true( $conn->query("SELECT 'AA%BB' LIKE %~like~", 'A%B')->fetchSingle());
|
||||
Assert::true($conn->query("SELECT 'AA%BB' LIKE %~like~", 'A%B')->fetchSingle());
|
||||
|
||||
Assert::same('AA\\BB', $conn->query("SELECT 'AA\\BB'")->fetchSingle());
|
||||
Assert::false($conn->query("SELECT 'AAxBB' LIKE %~like~", 'A\\B')->fetchSingle());
|
||||
Assert::true( $conn->query("SELECT 'AA\\BB' LIKE %~like~", 'A\\B')->fetchSingle());
|
||||
Assert::true($conn->query("SELECT 'AA\\BB' LIKE %~like~", 'A\\B')->fetchSingle());
|
||||
};
|
||||
|
||||
$conn = new DibiConnection($config);
|
||||
|
@@ -1 +0,0 @@
|
||||
Dibi 2.3.0 (released on 2015-01-23)
|
Reference in New Issue
Block a user