Index: trunk/core/kernel/db/db_connection.php =================================================================== diff -u -N -r4446 -r4758 --- trunk/core/kernel/db/db_connection.php (.../db_connection.php) (revision 4446) +++ trunk/core/kernel/db/db_connection.php (.../db_connection.php) (revision 4758) @@ -1,11 +1,11 @@ errorHandler = Array(&$this,'handleError'); } - else + else { $this->errorHandler=$errorHandler; } } - + /** * Set's custom error * @@ -106,9 +106,9 @@ function setError($code,$msg) { $this->errorCode=$code; - $this->errorMessage=$msg; + $this->errorMessage=$msg; } - + /** * Checks if previous query execution * raised an error. @@ -118,9 +118,9 @@ */ function hasError() { - return !($this->errorCode == 0); + return !($this->errorCode == 0); } - + /** * Caches function specific to requested * db type @@ -134,14 +134,14 @@ { case 'mysql': $ret = Array(); // only define functions, that name differs from "dbType_" - + break; - - + + } $this->metaFunctions = $ret; - } - + } + /** * Get's function for specific db type * based on it's meta name @@ -154,16 +154,16 @@ { if( !isset($this->metaFunctions[$name]) ) { - if(function_exists($this->dbType.'_'.$name)) return $this->dbType.'_'.$name; + if(function_exists($this->dbType.'_'.$name)) return $this->dbType.'_'.$name; } - else + else { return $this->dbType.$name; } return false; } - - + + /** * Try to connect to database server * using specified parameters and set @@ -185,14 +185,14 @@ $this->showError(); } } - + function ReConnect($host,$user,$pass,$db) { $func = $this->getMetaFunction('close'); $func($this->connectionID); $this->Connect($host,$user,$pass,$db); } - + /** * Shows error message from previous operation * if it failed @@ -213,7 +213,7 @@ $func = $this->errorHandler[1]; $ret = $this->errorHandler[0]->$func($this->errorCode,$this->errorMessage,$sql); } - else + else { $func = $this->errorHandler; $ret = $func($this->errorCode,$this->errorMessage,$sql); @@ -222,7 +222,7 @@ } } } - + /** * Default error handler for sql errors * @@ -238,7 +238,7 @@ echo 'Error ('.$code.'): '.$msg.'
'; return false; } - + /** * Set's database name for connection * to $new_name @@ -253,12 +253,12 @@ $func = $this->getMetaFunction('select_db'); return $func($new_name); } - + /** * Returns first field of first line * of recordset if query ok or false * otherwise - * + * * @param string $sql * @param int $offset * @return string @@ -268,14 +268,14 @@ { $row = $this->GetRow($sql, $offset); if(!$row) return false; - + return array_shift($row); } - + /** * Returns first row of recordset * if query ok, false otherwise - * + * * @param stirng $sql * @param int $offset * @return Array @@ -285,11 +285,11 @@ { $sql .= ' '.$this->getLimitClause($offset, 1); $ret = $this->Query($sql); - if(!$ret) return false; - + if(!$ret) return false; + return array_shift($ret); } - + /** * Returns 1st column of recordset as * one-dimensional array or false otherwise @@ -306,7 +306,7 @@ { $rows = $this->Query($sql); if(!$rows) return $rows; - + $i = 0; $row_count = count($rows); $ret = Array(); if(isset($key_field)) @@ -317,7 +317,7 @@ $i++; } } - else + else { while ($i < $row_count) { @@ -327,7 +327,7 @@ } return $ret; } - + /** * Queries db with $sql query supplied * and returns rows selected if any, false @@ -356,7 +356,7 @@ $ret[$row[$key_field]] = $row; } } - else + else { while( ($row = $fetch_func($this->queryID)) ) { @@ -369,18 +369,18 @@ $this->showError($sql); return false; } - + function ChangeQuery($sql) { $this->Query($sql); return $this->errorCode==0 ? true : false; } - + function debugQuery($sql, $key_field = null) { global $debugger; $query_func = $this->getMetaFunction('query'); - + // set 1st checkpoint: begin $isSkipTable=true; $profileSQLs=defined('DBG_SQL_PROFILE')&&DBG_SQL_PROFILE; @@ -394,16 +394,9 @@ } } // set 1st checkpoint: end - + $this->queryID = $query_func($sql,$this->connectionID); - - // set 2nd checkpoint: begin - if(!$isSkipTable) { - $debugger->profileFinish('sql_'.$queryID); - $debugger->profilerAddTotal('sql', 'sql_'.$queryID); - } - // set 2nd checkpoint: end - + if( is_resource($this->queryID) ) { $ret = Array(); @@ -415,20 +408,34 @@ $ret[$row[$key_field]] = $row; } } - else + else { while( ($row = $fetch_func($this->queryID)) ) { $ret[] = $row; } } + // set 2nd checkpoint: begin + if(!$isSkipTable) { + $debugger->profileFinish('sql_'.$queryID); + $debugger->profilerAddTotal('sql', 'sql_'.$queryID); + } $this->Destroy(); + // set 2nd checkpoint: end return $ret; } + else { + // set 2nd checkpoint: begin + if(!$isSkipTable) { + $debugger->profileFinish('sql_'.$queryID); + $debugger->profilerAddTotal('sql', 'sql_'.$queryID); + } + // set 2nd checkpoint: end + } $this->showError($sql); return false; } - + /** * Free memory used to hold recordset handle * @@ -438,12 +445,12 @@ { if($this->queryID) { - $free_func = $this->getMetaFunction('free_result'); + $free_func = $this->getMetaFunction('free_result'); $free_func($this->queryID); $this->queryID = null; } } - + /** * Returns auto increment field value from * insert like operation if any, zero otherwise @@ -456,7 +463,7 @@ $func = $this->getMetaFunction('insert_id'); return $func($this->connectionID); } - + /** * Returns row count affected by last query * @@ -466,9 +473,9 @@ function getAffectedRows() { $func = $this->getMetaFunction('affected_rows'); - return $func($this->connectionID); + return $func($this->connectionID); } - + /** * Returns LIMIT sql clause part for specific db * @@ -480,20 +487,20 @@ function getLimitClause($offset, $rows) { if(!($rows > 0)) return ''; - + switch ($this->dbType) { - + default: return 'LIMIT '.$offset.','.$rows; break; } } - + /** * Correctly quotes a string so that all strings are escaped. We prefix and append * to the string single-quotes. * An example is $db->qstr("Don't bother",magic_quotes_runtime()); - * + * * @param s the string to quote * @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc(). * This undoes the stupidity of magic quotes for GPC. @@ -527,7 +534,7 @@ return "'".str_replace("\\'",$replaceQuote,$s)."'"; } } - + /** * Returns last error code occured * @@ -537,7 +544,7 @@ { return $this->errorCode; } - + /** * Returns last error message * @@ -548,7 +555,7 @@ { return $this->errorMessage; } - + function doInsert($fields_hash, $table, $type = 'INSERT') { $fields_sql = ''; @@ -557,27 +564,27 @@ $fields_sql .= '`'.$field_name.'`,'; $values_sql .= $this->qstr($field_value).','; } - + $fields_sql = preg_replace('/(.*),$/', '\\1', $fields_sql); $values_sql = preg_replace('/(.*),$/', '\\1', $values_sql); $sql = strtoupper($type).' INTO `'.$table.'` ('.$fields_sql.') VALUES ('.$values_sql.')'; - + return $this->ChangeQuery($sql); } - + function doUpdate($fields_hash, $table, $key_clause) { if (!$fields_hash) return true; - + $fields_sql = ''; foreach ($fields_hash as $field_name => $field_value) { $fields_sql .= '`'.$field_name.'` = '.$this->qstr($field_value).','; } - + $fields_sql = preg_replace('/(.*),$/', '\\1', $fields_sql); - + $sql = 'UPDATE `'.$table.'` SET '.$fields_sql.' WHERE '.$key_clause; - + return $this->ChangeQuery($sql); } }