diff options
Diffstat (limited to 'kohana/libraries/Database.php')
-rw-r--r-- | kohana/libraries/Database.php | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/kohana/libraries/Database.php b/kohana/libraries/Database.php index c1ff0764..c98faffb 100644 --- a/kohana/libraries/Database.php +++ b/kohana/libraries/Database.php @@ -264,7 +264,7 @@ class Database_Core { if ($this->config['benchmark'] == TRUE) { // Benchmark the query - self::$benchmarks[] = array('query' => $sql, 'time' => $stop - $start, 'rows' => count($result)); + Database::$benchmarks[] = array('query' => $sql, 'time' => $stop - $start, 'rows' => count($result)); } return $result; @@ -299,9 +299,9 @@ class Database_Core { { if (preg_match('/^DISTINCT\s++(.+)$/i', $val, $matches)) { - /* ****** Begin Gallery 3 Local Change *********** */ - $val = (strpos($matches[1], '.') !== FALSE) ? $this->config['table_prefix'].$matches[1] : $matches[1]; - /* ****** End Gallery 3 Local Change *********** */ + // Only prepend with table prefix if table name is specified + $val = (strpos($matches[1], '.') !== FALSE) ? $this->config['table_prefix'].$matches[1] : $matches[1]; + $this->distinct = TRUE; } else @@ -336,27 +336,32 @@ class Database_Core { } else { - $sql = (array) $sql; + $sql = array($sql); } foreach ($sql as $val) { if (($val = trim($val)) === '') continue; - // TODO: Temporary solution, this should be moved to database driver (AS is checked for twice) - if (stripos($val, ' AS ') !== FALSE) + if (is_string($val)) { - $val = str_ireplace(' AS ', ' AS ', $val); + // TODO: Temporary solution, this should be moved to database driver (AS is checked for twice) + if (stripos($val, ' AS ') !== FALSE) + { + $val = str_ireplace(' AS ', ' AS ', $val); - list($table, $alias) = explode(' AS ', $val); + list($table, $alias) = explode(' AS ', $val); - // Attach prefix to both sides of the AS - $this->from[] = $this->config['table_prefix'].$table.' AS '.$this->config['table_prefix'].$alias; - } - else - { - $this->from[] = $this->config['table_prefix'].$val; + // Attach prefix to both sides of the AS + $val = $this->config['table_prefix'].$table.' AS '.$this->config['table_prefix'].$alias; + } + else + { + $val = $this->config['table_prefix'].$val; + } } + + $this->from[] = $val; } return $this; @@ -404,23 +409,34 @@ class Database_Core { $cond[] = $this->driver->where($key, $value, 'AND ', count($cond), FALSE); } - if( ! is_array($this->join)) { $this->join = array(); } + if ( ! is_array($this->join)) + { + $this->join = array(); + } + + if ( ! is_array($table)) + { + $table = array($table); + } - foreach ((array) $table as $t) + foreach ($table as $t) { - // TODO: Temporary solution, this should be moved to database driver (AS is checked for twice) - if (stripos($t, ' AS ') !== FALSE) + if (is_string($t)) { - $t = str_ireplace(' AS ', ' AS ', $t); + // TODO: Temporary solution, this should be moved to database driver (AS is checked for twice) + if (stripos($t, ' AS ') !== FALSE) + { + $t = str_ireplace(' AS ', ' AS ', $t); - list($table, $alias) = explode(' AS ', $t); + list($table, $alias) = explode(' AS ', $t); - // Attach prefix to both sides of the AS - $t = $this->config['table_prefix'].$table.' AS '.$this->config['table_prefix'].$alias; - } - else - { - $t = $this->config['table_prefix'].$t; + // Attach prefix to both sides of the AS + $t = $this->config['table_prefix'].$table.' AS '.$this->config['table_prefix'].$alias; + } + else + { + $t = $this->config['table_prefix'].$t; + } } $join['tables'][] = $this->driver->escape_column($t); |