1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-08 07:06:52 +02:00

- DibiTranslator: empty arrays generate NULL (it may cause an BC break!)

- Dibi: disables magic_quotes_runtime
This commit is contained in:
David Grudl
2009-04-16 02:15:20 +00:00
parent 496c224be5
commit 6589519419
8 changed files with 12 additions and 43 deletions

View File

@@ -26,6 +26,7 @@ if (version_compare(PHP_VERSION, '5.1.0', '<')) {
throw new Exception('dibi needs PHP 5.1.0 or newer.');
}
@set_magic_quotes_runtime(FALSE); // intentionally @
@@ -525,7 +526,7 @@ class dibi
public static function select($args)
{
$args = func_get_args();
return self::getConnection()->command()->__call('select', $args);
return call_user_func_array(array(self::getConnection(), 'select'), $args);
}
@@ -648,7 +649,8 @@ class dibi
public static function setSubstFallback($callback)
{
if (!is_callable($callback)) {
throw new InvalidArgumentException("Invalid callback.");
$able = is_callable($callback, TRUE, $textual);
throw new InvalidArgumentException("Handler '$textual' is not " . ($able ? 'callable.' : 'valid PHP callback.'));
}
self::$substFallBack = $callback;

View File

@@ -260,7 +260,7 @@ final class DibiTranslator extends DibiObject
$pair = explode('%', $k, 2); // split into identifier & modifier
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE);
}
return '(' . implode(', ', $vx) . ')';
return '(' . ($vx ? implode(', ', $vx) : 'NULL') . ')';
case 'v': // (key, key, ...) VALUES (val, val, ...)
@@ -291,7 +291,7 @@ final class DibiTranslator extends DibiObject
foreach ($value as $v) {
$vx[] = $this->formatValue($v, $modifier);
}
return implode(', ', $vx);
return $vx ? implode(', ', $vx) : 'NULL';
}
}

View File

@@ -122,8 +122,6 @@ interface IDibiDriver
*/
function connect(array &$config);
/**
* Disconnects from a database.
* @return void
@@ -131,8 +129,6 @@ interface IDibiDriver
*/
function disconnect();
/**
* Internal: Executes the SQL query.
* @param string SQL statement.
@@ -141,24 +137,18 @@ interface IDibiDriver
*/
function query($sql);
/**
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
* @return int|FALSE number of rows or FALSE on error
*/
function getAffectedRows();
/**
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
* @return int|FALSE int on success or FALSE on failure
*/
function getInsertId($sequence);
/**
* Begins a transaction (if supported).
* @param string optinal savepoint name
@@ -167,8 +157,6 @@ interface IDibiDriver
*/
function begin($savepoint = NULL);
/**
* Commits statements in a transaction.
* @param string optinal savepoint name
@@ -177,8 +165,6 @@ interface IDibiDriver
*/
function commit($savepoint = NULL);
/**
* Rollback changes in a transaction.
* @param string optinal savepoint name
@@ -187,8 +173,6 @@ interface IDibiDriver
*/
function rollback($savepoint = NULL);
/**
* Returns the connection resource.
* @return mixed
@@ -210,8 +194,6 @@ interface IDibiDriver
*/
function escape($value, $type);
/**
* Decodes data from result set.
* @param string value
@@ -221,8 +203,6 @@ interface IDibiDriver
*/
function unescape($value, $type);
/**
* Injects LIMIT/OFFSET to the SQL query.
* @param string &$sql The SQL query that will be modified.
@@ -244,8 +224,6 @@ interface IDibiDriver
*/
function getRowCount();
/**
* Moves cursor position without fetching row.
* @param int the 0-based cursor pos to seek to
@@ -254,8 +232,6 @@ interface IDibiDriver
*/
function seek($row);
/**
* Fetches the row at current position and moves the internal cursor to the next position.
* @param bool TRUE for associative array, FALSE for numeric
@@ -264,8 +240,6 @@ interface IDibiDriver
*/
function fetch($type);
/**
* Frees the resources allocated for this result set.
* @param resource result set resource
@@ -273,8 +247,6 @@ interface IDibiDriver
*/
function free();
/**
* Returns metadata for all columns in a result set.
* @return array
@@ -282,8 +254,6 @@ interface IDibiDriver
*/
function getColumnsMeta();
/**
* Returns the result set resource.
* @return mixed
@@ -302,8 +272,6 @@ interface IDibiDriver
*/
function getTables();
/**
* Returns metadata for all columns in a table.
* @param string
@@ -311,8 +279,6 @@ interface IDibiDriver
*/
function getColumns($table);
/**
* Returns metadata for all indexes in a table.
* @param string
@@ -320,8 +286,6 @@ interface IDibiDriver
*/
function getIndexes($table);
/**
* Returns metadata for all foreign keys in a table.
* @param string

View File

@@ -4,8 +4,6 @@
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
// required since PHP 5.1.0
date_default_timezone_set('Europe/Prague');

View File

@@ -4,6 +4,8 @@
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
dibi::connect(array(
'driver' => 'sqlite',

View File

@@ -4,6 +4,8 @@
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
dibi::connect(array(
'driver' => 'sqlite',

View File

@@ -5,6 +5,8 @@
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
dibi::connect(array(
'driver' => 'sqlite',

View File

@@ -8,7 +8,6 @@ pre.dibi { padding-bottom: 10px; }
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
// required since PHP 5.1.0
date_default_timezone_set('Europe/Prague');