1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-30 01:09:50 +02:00

Compare commits

...

12 Commits

Author SHA1 Message Date
David Grudl
6f99db544f released 2.0.3 2013-04-03 14:40:16 +02:00
David Grudl
c399d79ab8 DibiResult: fixed detection of "123.000" as float [Closes #67] 2013-04-03 14:40:15 +02:00
David Grudl
67f8468a38 added .gitignore 2013-04-03 14:31:50 +02:00
David Grudl
72944ae012 composer: renamed to dibi/dibi 2013-04-03 14:30:29 +02:00
David Grudl
4843882e61 MySQLI: mysqli_affected_rows() returns -1 on error [Closes #80] 2013-04-03 14:29:46 +02:00
Filip Procházka
669ce73096 PdoDriver: fix notice undefined index native_type 2013-04-03 14:29:25 +02:00
David Grudl
6e4a6474cd dibi::$sql is always set 2013-04-03 14:28:15 +02:00
David Grudl
2dc30747e5 released 2.0.2 2012-12-04 14:43:02 +01:00
David Grudl
23531a0f3d reflectors: table names are correctly escaped 2012-12-04 14:42:12 +01:00
David Grudl
22c6f2dfda DibiTranslator: number of decimal points changed to 10 2012-12-04 14:42:08 +01:00
David Grudl
f51ac0b67e fixed invalid escaping sequences in double quoted strings, used \z instead of $ 2012-12-04 14:42:08 +01:00
David Grudl
43f5e08296 DibiConnection: fixed loadFromFile() and loading file without semicolon [Closes #63] 2012-12-04 14:42:08 +01:00
13 changed files with 36 additions and 32 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/vendor
/composer.lock

View File

@@ -1,7 +1,7 @@
{
"name": "dg/dibi",
"name": "dibi/dibi",
"description": "Dibi is Database Abstraction Library for PHP 5.",
"keywords": ["dibi", "database", "dbal", "mysql", "postgresql", "sqlite", "mssql", "oracle", "access", "pdo", "odbc"],
"keywords": ["database", "dbal", "mysql", "postgresql", "sqlite", "mssql", "oracle", "access", "pdo", "odbc"],
"homepage": "http://dibiphp.com/",
"license": ["BSD-3", "GPLv2", "GPLv3"],
"authors": [

View File

@@ -80,7 +80,7 @@ class dibi
FIELD_TIME = dibi::TIME;
/** version */
const VERSION = '2.0.1',
const VERSION = '2.0.3',
REVISION = '$WCREV$ released on $WCDATE$';
/** sorting order */

View File

@@ -65,18 +65,16 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
if (empty($table)) {
return false;
}
$table = $this->driver->escape($table, dibi::TEXT);
$result = $this->driver->query("
SELECT MAX(rowcnt)
FROM sys.sysindexes
WHERE id=OBJECT_ID({$table})
WHERE id=OBJECT_ID({$this->driver->escape($table, dibi::IDENTIFIER)})
");
$row = $result->fetch(FALSE);
if (!is_array($row) || count($row) < 1) {
if ($fallback) {
$row = $this->driver->query("SELECT COUNT(*) FROM {$table}")->fetch(FALSE);
$row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escape($table, dibi::IDENTIFIER)}")->fetch(FALSE);
$count = intval($row[0]);
} else {
$count = false;
@@ -100,7 +98,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
$res = $this->driver->query("
SELECT * FROM
INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '{$table}'
WHERE TABLE_NAME = {$this->driver->escape($table, dibi::TEXT)}
ORDER BY TABLE_NAME, ORDINAL_POSITION
");
$columns = array();
@@ -148,8 +146,6 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
*/
public function getIndexes($table)
{
$table = $this->driver->escape($table, dibi::TEXT);
$res = $this->driver->query(
"SELECT ind.name index_name, ind.index_id, ic.index_column_id,
col.name column_name, ind.is_unique, ind.is_primary_key
@@ -160,7 +156,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
(ic.object_id = col.object_id and ic.column_id = col.column_id)
INNER JOIN sys.tables t ON
(ind.object_id = t.object_id)
WHERE t.name = {$table}
WHERE t.name = {$this->driver->escape($table, dibi::TEXT)}
AND t.is_ms_shipped = 0
ORDER BY
t.name, ind.name, ind.index_id, ic.index_column_id
@@ -192,8 +188,6 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
*/
public function getForeignKeys($table)
{
$table = $this->driver->escape($table, dibi::TEXT);
$res = $this->driver->query("
SELECT f.name AS foreign_key,
OBJECT_NAME(f.parent_object_id) AS table_name,
@@ -206,7 +200,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
WHERE OBJECT_NAME(f.parent_object_id)={$table}
WHERE OBJECT_NAME(f.parent_object_id) = {$this->driver->escape($table, dibi::TEXT)}
");
$keys = array();

View File

@@ -68,7 +68,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE()
");*/
$res = $this->driver->query("SHOW FULL COLUMNS FROM `$table`");
$res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escape($table, dibi::IDENTIFIER)}");
$columns = array();
while ($row = $res->fetch(TRUE)) {
$type = explode('(', $row['Type']);
@@ -103,7 +103,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector
WHERE TABLE_NAME = $table AND TABLE_SCHEMA = DATABASE()
AND REFERENCED_COLUMN_NAME IS NULL
");*/
$res = $this->driver->query("SHOW INDEX FROM `$table`");
$res = $this->driver->query("SHOW INDEX FROM {$this->driver->escape($table, dibi::IDENTIFIER)}");
$indexes = array();
while ($row = $res->fetch(TRUE)) {
$indexes[$row['Key_name']]['name'] = $row['Key_name'];

View File

@@ -194,7 +194,7 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri
*/
public function getAffectedRows()
{
return mysqli_affected_rows($this->connection);
return mysqli_affected_rows($this->connection) === -1 ? FALSE : mysqli_affected_rows($this->connection);
}

View File

@@ -451,7 +451,10 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
// PHP < 5.2.3 compatibility
// @see: http://php.net/manual/en/pdostatement.getcolumnmeta.php#pdostatement.getcolumnmeta.changelog
$row['table'] = isset($row['table']) ? $row['table'] : NULL;
$row = $row + array(
'table' => NULL,
'native_type' => 'VAR_STRING',
);
$columns[] = array(
'name' => $row['name'],

View File

@@ -60,16 +60,16 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
public function getColumns($table)
{
$meta = $this->driver->query("
SELECT sql FROM sqlite_master WHERE type = 'table' AND name = '$table'
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 = '$table'"
)->fetch(TRUE);
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([$table])");
$res = $this->driver->query("PRAGMA table_info({$this->driver->escape($table, dibi::IDENTIFIER)})");
$columns = array();
while ($row = $res->fetch(TRUE)) {
$column = $row['name'];
$pattern = "/(\"$column\"|\[$column\]|$column)\s+[^,]+\s+PRIMARY\s+KEY\s+AUTOINCREMENT/Ui";
$pattern = "/(\"$column\"|\[$column\]|$column)\\s+[^,]+\\s+PRIMARY\\s+KEY\\s+AUTOINCREMENT/Ui";
$type = explode('(', $row['type']);
$columns[] = array(
'name' => $column,
@@ -95,7 +95,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
*/
public function getIndexes($table)
{
$res = $this->driver->query("PRAGMA index_list([$table])");
$res = $this->driver->query("PRAGMA index_list({$this->driver->escape($table, dibi::IDENTIFIER)})");
$indexes = array();
while ($row = $res->fetch(TRUE)) {
$indexes[$row['name']]['name'] = $row['name'];
@@ -103,7 +103,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
}
foreach ($indexes as $index => $values) {
$res = $this->driver->query("PRAGMA index_info([$index])");
$res = $this->driver->query("PRAGMA index_info({$this->driver->escape($index, dibi::IDENTIFIER)})");
while ($row = $res->fetch(TRUE)) {
$indexes[$index]['columns'][$row['seqno']] = $row['name'];
}
@@ -150,7 +150,7 @@ class DibiSqliteReflector extends DibiObject implements IDibiReflector
if (!($this->driver instanceof DibiSqlite3Driver)) {
// throw new DibiNotSupportedException; // @see http://www.sqlite.org/foreignkeys.html
}
$res = $this->driver->query("PRAGMA foreign_key_list([$table])");
$res = $this->driver->query("PRAGMA foreign_key_list({$this->driver->escape($table, dibi::IDENTIFIER)})");
$keys = array();
while ($row = $res->fetch(TRUE)) {
$keys[$row['id']]['name'] = $row['id']; // foreign key name

View File

@@ -338,6 +338,7 @@ class DibiConnection extends DibiObject
{
$this->connected || $this->connect();
dibi::$sql = $sql;
$event = $this->onEvent ? new DibiEvent($this, DibiEvent::QUERY, $sql) : NULL;
try {
$res = $this->driver->query($sql);
@@ -688,6 +689,10 @@ class DibiConnection extends DibiObject
$count++;
}
}
if (trim($sql) !== '') {
$this->driver->query($sql);
$count++;
}
fclose($handle);
return $count;
}

View File

@@ -181,7 +181,7 @@ class DibiFluent extends DibiObject implements IDataSource
if ($arg === TRUE) { // flag
return $this;
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*$#i', $arg)) { // identifier
} elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier
$args = array('%n', $arg);
} elseif (is_array($arg) || ($arg instanceof Traversable && !$arg instanceof self)) { // any array

View File

@@ -514,7 +514,7 @@ class DibiResult extends DibiObject implements IDataSource
$row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;
} elseif ($type === dibi::FLOAT) {
$row[$key] = (string) ($tmp = (float) $value) === $value ? $tmp : $value;
$row[$key] = (string) ($tmp = (float) $value) === rtrim(rtrim($value, '0'), '.') ? $tmp : $value;
} elseif ($type === dibi::BOOL) {
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';

View File

@@ -353,7 +353,7 @@ 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+)?$#A', $value)) {
if (is_string($value) && preg_match('#[+-]?\d++(e\d+)?\z#A', $value)) {
return $value;
} else {
return $value === NULL ? 'NULL' : (string) (int) ($value + 0);
@@ -364,7 +364,7 @@ final class DibiTranslator extends DibiObject
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
} else {
return $value === NULL ? 'NULL' : rtrim(rtrim(number_format($value + 0, 20, '.', ''), '0'), '.');
return $value === NULL ? 'NULL' : rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
}
case 'd': // date
@@ -436,7 +436,7 @@ final class DibiTranslator extends DibiObject
return (string) $value;
} elseif (is_float($value)) {
return rtrim(rtrim(number_format($value, 20, '.', ''), '0'), '.');
return rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');
} elseif (is_bool($value)) {
return $this->driver->escape($value, dibi::BOOL);

View File

@@ -1 +1 @@
Dibi 2.0.1 (revision $WCREV$ released on $WCDATE$)
Dibi 2.0.3 (revision $WCREV$ released on $WCDATE$)