diff --git a/classes/db_pdo.php b/classes/db_pdo.php index 202880e..8e26a0c 100644 --- a/classes/db_pdo.php +++ b/classes/db_pdo.php @@ -37,7 +37,7 @@ abstract class DB_PDO extends PDO { // Last query executed public $last_query; - + // Prefix to apply to table namesa public $table_prefix = ''; @@ -62,7 +62,7 @@ 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)) { @@ -196,21 +196,21 @@ abstract class DB_PDO extends PDO { } // -------------------------------------------------------------------------- - + /** * Quote database table name, and set prefix - * + * * @param string $table * @return string */ public function quote_table($table) - { + { // If there isn't a prefix set, just quote the table name if (empty($this->table_prefix)) { return $this->quote_ident($table); } - + // Split indentifier by period, will split into: // database.schema.table OR // schema.table OR @@ -218,25 +218,25 @@ abstract class DB_PDO extends PDO { // table $idents = (array) explode('.', $table); $segments = count($idents); - + // Reference the last item in the split string $last =& $idents[$segments - 1]; - + // Quote the last item $last = $this->_prefix($last); - + // Rejoin - $table = implode('.', $idents); - + $table = implode('.', $idents); + // Finally, quote the table return $this->quote_ident($table); } - + // -------------------------------------------------------------------------- - - /** + + /** * Sets the table prefix on the passed string - * + * * @param string $str * @return string */ @@ -247,10 +247,10 @@ abstract class DB_PDO extends PDO { { return $str; } - + return $this->table_prefix.$str; } - + // -------------------------------------------------------------------------- /** diff --git a/classes/query_builder.php b/classes/query_builder.php index 6ec348b..4c28c0d 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -116,6 +116,8 @@ class Query_Builder implements iQuery_Builder { // Instantiate the Query Parser $this->parser = new Query_Parser(); + $this->queries['total_time'] = 0; + // Make things just slightly shorter $this->sql = $this->db->sql; } @@ -1190,10 +1192,31 @@ class Query_Builder implements iQuery_Builder { $sql = $this->_compile($type, $table); $vals = array_merge($this->values, (array) $this->where_values); + $start_time = microtime(TRUE); + $res = ($simple) ? $this->db->query($sql) : $this->db->prepare_execute($sql, $vals); + $end_time = microtime(TRUE); + + $total_time = number_format($end_time - $start_time, 5); + + // Add the interpreted query to the list of executed queries + $esql = str_replace('?', '%s', $sql); + array_unshift($vals, $esql); + + $this->queries[] = array( + 'time' => $total_time, + 'sql' => call_user_func_array('sprintf', $vals), + ); + $this->queries['total_time'] += $total_time; + + array_shift($vals); + + // Set the last query to get rowcounts properly + $this->db->last_query = $sql; + $this->reset_query(); return $res; @@ -1300,14 +1323,6 @@ class Query_Builder implements iQuery_Builder { $sql = $this->sql->limit($sql, $this->limit, $this->offset); } - // Add the query to the list of executed queries - $this->queries[] = $sql; - - // Set the last query to get rowcounts properly - $this->db->last_query = $sql; - - // echo $sql . '
'; - return $sql; } } diff --git a/tests/core/db_qb_test.php b/tests/core/db_qb_test.php index 32e1588..0bba7fa 100644 --- a/tests/core/db_qb_test.php +++ b/tests/core/db_qb_test.php @@ -18,16 +18,21 @@ */ abstract class QBTest extends UnitTestCase { + public function __destruct() + { + // echo '
' . print_r($this->db->queries, TRUE) . '
'; + } + // -------------------------------------------------------------------------- // ! Get Tests // -------------------------------------------------------------------------- - + public function TestQueryFunctionAlias() { if (empty($this->db)) return; - + $db = Query(); - + $this->assertReference($this->db, $db); } diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 6d31427..a7155a8 100755 Binary files a/tests/db_files/FB_TEST_DB.FDB and b/tests/db_files/FB_TEST_DB.FDB differ