Skip to content

Commit

Permalink
Simplify add_table_prefixes. In Kohana 2.4, it returns the bare table
Browse files Browse the repository at this point in the history
name, not the prefixed one so this makes our logic easier.
  • Loading branch information
bharat committed Dec 18, 2009
1 parent c99a75b commit 2aba8c4
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions modules/gallery/libraries/MY_Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class Database extends Database_Core {
* table prefix . $1
*/
public function query($sql = '') {
if (!empty($sql)) {
if ($this->config["table_prefix"] && !empty($sql)) {
$sql = $this->add_table_prefixes($sql);
}
return parent::query($sql);
Expand All @@ -49,19 +49,12 @@ public function add_table_prefixes($sql) {

if (!isset($this->_table_names)) {
// This should only run once on the first query
$this->_table_names =array();
$len = strlen($prefix);
$this->_table_names = array();
foreach($this->list_tables() as $table_name) {
if ($len > 0) {
$naked_name = strpos($table_name, $prefix) !== 0 ?
$table_name : substr($table_name, $len);
} else {
$naked_name = $table_name;
}
$this->_table_names["{{$naked_name}}"] = $table_name;
$this->_table_names["{{$table_name}}"] = $prefix . $table_name;
}
}

return empty($this->_table_names) ? $sql : strtr($sql, $this->_table_names);
return strtr($sql, $this->_table_names);
}
}

0 comments on commit 2aba8c4

Please sign in to comment.