mirror of
https://github.com/dg/dibi.git
synced 2025-08-12 17:14:16 +02:00
* fixed odbc_num_rows and pg_affected_rows
This commit is contained in:
@@ -105,8 +105,7 @@ abstract class DibiDriver
|
||||
final public function query($args)
|
||||
{
|
||||
// receive arguments
|
||||
if (!is_array($args))
|
||||
$args = func_get_args();
|
||||
if (!is_array($args)) $args = func_get_args();
|
||||
|
||||
// and generate SQL
|
||||
$trans = new DibiTranslator($this);
|
||||
@@ -121,7 +120,10 @@ abstract class DibiDriver
|
||||
if ($res === FALSE) { // query error
|
||||
if (dibi::$logFile) { // log to file
|
||||
$info = $this->errorInfo();
|
||||
if ($info['code']) $info['message'] = "[$info[code]] $info[message]";
|
||||
if ($info['code']) {
|
||||
$info['message'] = "[$info[code]] $info[message]";
|
||||
}
|
||||
|
||||
dibi::log(
|
||||
"ERROR: $info[message]"
|
||||
. "\n-- SQL: " . $sql
|
||||
@@ -135,7 +137,10 @@ abstract class DibiDriver
|
||||
throw new DibiException('Query error (driver ' . $this->config['driver'] . ')', $info, $sql);
|
||||
} else {
|
||||
$info = $this->errorInfo();
|
||||
if ($info['code']) $info['message'] = "[$info[code]] $info[message]";
|
||||
if ($info['code']) {
|
||||
$info['message'] = "[$info[code]] $info[message]";
|
||||
}
|
||||
|
||||
trigger_error("dibi: $info[message]", E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
|
@@ -37,12 +37,14 @@ class DibiException extends Exception
|
||||
}
|
||||
|
||||
|
||||
|
||||
final public function getSql()
|
||||
{
|
||||
return $this->sql;
|
||||
}
|
||||
|
||||
|
||||
|
||||
final public function getDbError()
|
||||
{
|
||||
return $this->dbError;
|
||||
@@ -56,13 +58,16 @@ class DibiException extends Exception
|
||||
|
||||
if ($this->dbError) {
|
||||
$s .= "\n\nDatabase error: ";
|
||||
if (isset($this->dbError['code']))
|
||||
if (isset($this->dbError['code'])) {
|
||||
$s .= "[" . $this->dbError['code'] . "] ";
|
||||
}
|
||||
|
||||
$s .= $this->dbError['message'];
|
||||
}
|
||||
|
||||
if ($this->sql) $s .= "\nSQL: " . $this->sql;
|
||||
if ($this->sql) {
|
||||
$s .= "\nSQL: " . $this->sql;
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
@@ -107,14 +107,14 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
final public function fetch()
|
||||
{
|
||||
$row = $this->doFetch();
|
||||
if (!is_array($row))
|
||||
return FALSE;
|
||||
if (!is_array($row)) return FALSE;
|
||||
|
||||
// types-converting?
|
||||
if ($t = $this->convert) { // little speed-up
|
||||
foreach ($row as $key => $value) {
|
||||
if (isset($t[$key]))
|
||||
if (isset($t[$key])) {
|
||||
$row[$key] = $this->convert($value, $t[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +130,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
final function fetchSingle()
|
||||
{
|
||||
$row = $this->doFetch();
|
||||
if (!is_array($row))
|
||||
return FALSE;
|
||||
if (!is_array($row)) return FALSE;
|
||||
|
||||
// types-converting?
|
||||
if ($t = $this->convert) { // little speed-up
|
||||
@@ -155,8 +154,7 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
{
|
||||
@$this->seek(0);
|
||||
$row = $this->fetch();
|
||||
if (!$row)
|
||||
return array(); // empty resultset
|
||||
if (!$row) return array(); // empty resultset
|
||||
|
||||
$data = array();
|
||||
if (count($row) === 1) {
|
||||
@@ -296,14 +294,15 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
|
||||
final public function setType($field, $type = NULL)
|
||||
{
|
||||
if ($field === TRUE)
|
||||
if ($field === TRUE) {
|
||||
$this->detectTypes();
|
||||
|
||||
elseif (is_array($field))
|
||||
} elseif (is_array($field)) {
|
||||
$this->convert = $field;
|
||||
|
||||
else
|
||||
} else {
|
||||
$this->convert[$field] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -318,19 +317,22 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
|
||||
final public function convert($value, $type)
|
||||
{
|
||||
if ($value === NULL || $value === FALSE)
|
||||
if ($value === NULL || $value === FALSE) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (isset(self::$types[$type])) {
|
||||
settype($value, self::$types[$type]);
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($type === dibi::FIELD_DATE)
|
||||
if ($type === dibi::FIELD_DATE) {
|
||||
return strtotime($value); // !!! not good
|
||||
}
|
||||
|
||||
if ($type === dibi::FIELD_DATETIME)
|
||||
if ($type === dibi::FIELD_DATETIME) {
|
||||
return strtotime($value); // !!! not good
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
@@ -344,7 +346,9 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
final public function getFields()
|
||||
{
|
||||
// lazy init
|
||||
if ($this->meta === NULL) $this->buildMeta();
|
||||
if ($this->meta === NULL) {
|
||||
$this->buildMeta();
|
||||
}
|
||||
return array_keys($this->meta);
|
||||
}
|
||||
|
||||
@@ -358,7 +362,9 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
final public function getMetaData($field)
|
||||
{
|
||||
// lazy init
|
||||
if ($this->meta === NULL) $this->buildMeta();
|
||||
if ($this->meta === NULL) {
|
||||
$this->buildMeta();
|
||||
}
|
||||
return isset($this->meta[$field]) ? $this->meta[$field] : FALSE;
|
||||
}
|
||||
|
||||
@@ -370,7 +376,9 @@ abstract class DibiResult implements IteratorAggregate, Countable
|
||||
*/
|
||||
final protected function detectTypes()
|
||||
{
|
||||
if ($this->meta === NULL) $this->buildMeta();
|
||||
if ($this->meta === NULL) {
|
||||
$this->buildMeta();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -102,7 +102,9 @@ final class DibiTranslator
|
||||
}
|
||||
|
||||
// default processing
|
||||
if (!$comment) $sql[] = $this->formatValue($arg, $mod);
|
||||
if (!$comment) {
|
||||
$sql[] = $this->formatValue($arg, $mod);
|
||||
}
|
||||
$mod = FALSE;
|
||||
} // foreach
|
||||
|
||||
@@ -116,16 +118,18 @@ final class DibiTranslator
|
||||
|
||||
// error handling
|
||||
if ($this->hasError) {
|
||||
if (dibi::$logFile) // log to file
|
||||
if (dibi::$logFile) { // log to file
|
||||
dibi::log(
|
||||
"ERROR: SQL generate error"
|
||||
. "\n-- SQL: " . $sql
|
||||
. ";\n-- " . date('Y-m-d H:i:s ')
|
||||
);
|
||||
}
|
||||
|
||||
if (dibi::$throwExceptions)
|
||||
if (dibi::$throwExceptions) {
|
||||
throw new DibiException('SQL generate error', NULL, $sql);
|
||||
else {
|
||||
|
||||
} else {
|
||||
trigger_error("dibi: SQL generate error: $sql", E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
@@ -164,19 +168,23 @@ final class DibiTranslator
|
||||
$pair = explode('%', $k, 2);
|
||||
|
||||
// generate arrays
|
||||
if ($kx !== NULL) $kx[] = $this->delimite($pair[0]);
|
||||
if ($kx !== NULL) {
|
||||
$kx[] = $this->delimite($pair[0]);
|
||||
}
|
||||
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : FALSE);
|
||||
}
|
||||
|
||||
if ($kx === NULL)
|
||||
if ($kx === NULL) {
|
||||
return '(' . implode(', ', $vx) . ')';
|
||||
else
|
||||
} else {
|
||||
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
foreach ($value as $v)
|
||||
foreach ($value as $v) {
|
||||
$vx[] = $this->formatValue($v, $modifier);
|
||||
}
|
||||
|
||||
return implode(', ', $vx);
|
||||
}
|
||||
@@ -185,10 +193,13 @@ final class DibiTranslator
|
||||
|
||||
// with modifier procession
|
||||
if ($modifier) {
|
||||
if ($value === NULL) return 'NULL';
|
||||
if ($value === NULL) {
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
if ($value instanceof DibiVariableInterface)
|
||||
if ($value instanceof DibiVariableInterface) {
|
||||
return $value->toSql($this->driver, $modifier);
|
||||
}
|
||||
|
||||
if (!is_scalar($value)) { // array is already processed
|
||||
$this->hasError = TRUE;
|
||||
@@ -226,8 +237,9 @@ final class DibiTranslator
|
||||
// speed-up - is regexp required?
|
||||
$toSkip = strcspn($value, '`[\'"%');
|
||||
|
||||
if (strlen($value) === $toSkip) // needn't be translated
|
||||
if (strlen($value) === $toSkip) { // needn't be translated
|
||||
return $value;
|
||||
}
|
||||
|
||||
// note: only this can change $this->modifier
|
||||
return substr($value, 0, $toSkip)
|
||||
|
Reference in New Issue
Block a user