From 47d493537e390bc92d3b901ba1e746cc92325163 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 7 Nov 2012 20:48:15 -0500 Subject: [PATCH] Remove some extra recursion and explicitly call more methods --- classes/db_pdo.php | 19 ++++++++++------- classes/query_builder.php | 38 +++++++++++++++------------------- tests/db_files/FB_TEST_DB.FDB | Bin 802816 -> 802816 bytes 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/classes/db_pdo.php b/classes/db_pdo.php index 58111dd..43da9dc 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -62,6 +62,15 @@ abstract class DB_PDO extends PDO { $this->util = new $class($this); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Set additional driver options, if they exist + if ( ! empty($driver_options) && is_array($driver_options)) + { + foreach($driver_options as $key => $val) + { + $this->setAttribute($key, $val); + } + } } // -------------------------------------------------------------------------- @@ -191,17 +200,11 @@ abstract class DB_PDO extends PDO { /** * Quote database table name, and set prefix * - * @param mixed $table + * @param string $table * @return string */ public function quote_table($table) - { - // An array is only passed if it's a table with alias - if (is_array($table)) - { - $table =& $table[0]; - } - + { // If there isn't a prefix set, just quote the table name if (empty($this->table_prefix)) { diff --git a/classes/query_builder.php b/classes/query_builder.php index 8653bfc..29709ba 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -73,9 +73,6 @@ class Query_Builder { // Alias to $this->db->sql public $sql; - // Database table prefix - public $table_prefix = ''; - // Query component order mapping // for complex select queries // @@ -134,7 +131,6 @@ class Query_Builder { // Set the table prefix, if it exists if (isset($params->prefix)) { - $this->table_prefix = $params->prefix; $this->db->table_prefix = $params->prefix; } @@ -234,7 +230,7 @@ class Query_Builder { } // Quote the identifiers - $safe_array = array_map(array($this->db, 'quote_ident'), $fields_array); + $safe_array = $this->db->quote_ident($fields_array); unset($fields_array); @@ -266,10 +262,10 @@ class Query_Builder { private function _select($field, $as = FALSE) { // Escape the identifiers - $field = $this->quote_ident($field); + $field = $this->db->quote_ident($field); $as = ($as !== FALSE) - ? $this->quote_ident($as) + ? $this->db->quote_ident($as) : $field; return "({$field}) AS {$as} "; @@ -393,7 +389,7 @@ class Query_Builder { */ private function _like($field, $val, $pos, $like='LIKE', $conj='AND') { - $field = $this->quote_ident($field); + $field = $this->db->quote_ident($field); // Add the like string into the order map $l = $field. " {$like} ?"; @@ -506,7 +502,7 @@ class Query_Builder { // is an operator such as >, <, !=, etc. $f_array = explode(' ', trim($f)); - $item = $this->quote_ident($f_array[0]); + $item = $this->db->quote_ident($f_array[0]); // Simple key value, or an operator $item .= (count($f_array) === 1) ? '=?' : " {$f_array[1]} ?"; @@ -604,7 +600,7 @@ class Query_Builder { // is an operator such as >, <, !=, etc. $f_array = explode(' ', trim($f)); - $item = $this->quote_ident($f_array[0]); + $item = $this->db->quote_ident($f_array[0]); // Simple key value, or an operator $item .= (count($f_array) === 1) ? '=?' : " {$f_array[1]} ?"; @@ -633,7 +629,7 @@ class Query_Builder { */ private function _where_in($key, $val=array(), $in='IN', $conj='AND') { - $key = $this->quote_ident($key); + $key = $this->db->quote_ident($key); $params = array_fill(0, count($val), '?'); foreach($val as $v) @@ -769,7 +765,7 @@ class Query_Builder { // Use the keys of the array to make the insert/update string // Escape the field names - $this->set_array_keys = array_map(array($this->db, 'quote_ident'), $this->set_array_keys); + $this->set_array_keys = $this->db->quote_ident($this->set_array_keys); // Generate the "set" string $this->set_string = implode('=?,', $this->set_array_keys); @@ -805,7 +801,7 @@ class Query_Builder { { if (in_array($parts['combined'][$i], $parts['identifiers']) && ! is_numeric($parts['combined'][$i])) { - $parts['combined'][$i] = $this->quote_ident($parts['combined'][$i]); + $parts['combined'][$i] = $this->db->quote_ident($parts['combined'][$i]); } } @@ -834,11 +830,11 @@ class Query_Builder { { if ( ! is_scalar($field)) { - $this->group_array = array_map(array($this->db, 'quote_ident'), $field); + $this->group_array = $this->db->quote_ident($field); } else { - $this->group_array[] = $this->quote_ident($field); + $this->group_array[] = $this->db->quote_ident($field); } $this->group_string = ' GROUP BY ' . implode(',', $this->group_array); @@ -864,7 +860,7 @@ class Query_Builder { } // Set fields for later manipulation - $field = $this->quote_ident($field); + $field = $this->db->quote_ident($field); $this->order_array[$field] = $type; $order_clauses = array(); @@ -1044,8 +1040,8 @@ class Query_Builder { */ public function count_all($table) { - $sql = 'SELECT * FROM '.$this->quote_table($table); - $res = $this->query($sql); + $sql = 'SELECT * FROM '.$this->db->quote_table($table); + $res = $this->db->query($sql); return (int) count($res->fetchAll()); } @@ -1278,8 +1274,8 @@ class Query_Builder { $vals = array_merge($this->values, (array) $this->where_values); $res = ($simple) - ? $this->query($sql) - : $this->prepare_execute($sql, $vals); + ? $this->db->query($sql) + : $this->db->prepare_execute($sql, $vals); $this->reset_query(); @@ -1318,7 +1314,7 @@ class Query_Builder { { $sql = ''; - $table = $this->quote_table($table); + $table = $this->db->quote_table($table); switch($type) { diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 7c38340a0529dabdbe2000c953085faf0d24d0b5..045d94bdccecc653d102a0a77d69237d82f39136 100644 GIT binary patch delta 1855 zcmZ`(O=u)V6n@py)9L9qlT;>gj6>9MC)1hr2Qt|#A|4bk-hu~Nmc_%a1Ol>TU~}*w z=pfn`4+e-!7&L$gCwvyaj z;qaReW~bfZ{(V8s(e0>5UnhOqi#xQy9g1rWdMoMCuSu7V;|6^dpP`TN|1bO>#a+4> z_h}7#J?`0K_M!&;lbj)%vXS_sNk1SebzD#_H1FlytkBlb+&2OOE}IWL5JILjnsUNpORc+UKGm*>Pczr&pWc@h(>@7hNb4#&|AjV z^2$|nBj;8qm2N?_gwe^eR@>X>oYi0zR)RbrWxmY$apxy6`w#mmd-~>3dZ>H~Md#%f zDWK;Y1%WBQENU<%mQ_61Z&m5a)$QRc1w5p>6ubO9O_rYDOBuhzu`&&;V z%Lg9{IWYFJC(Fy0Ow@~?bPcfwSq~2rKYeAGNlAeU?;yv^1(S(tqj+@8O4j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