merge freeResult and checkError functions back into queryHelper() since they're only used once
This commit is contained in:
38
db.class.php
38
db.class.php
@@ -550,6 +550,7 @@ class MeekroDB {
|
|||||||
protected function queryHelper() {
|
protected function queryHelper() {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$type = array_shift($args);
|
$type = array_shift($args);
|
||||||
|
$db = $this->get();
|
||||||
|
|
||||||
$is_buffered = true;
|
$is_buffered = true;
|
||||||
$row_type = 'assoc'; // assoc, list, raw
|
$row_type = 'assoc'; // assoc, list, raw
|
||||||
@@ -578,29 +579,25 @@ class MeekroDB {
|
|||||||
|
|
||||||
$sql = call_user_func_array(array($this, 'parseQueryParams'), $args);
|
$sql = call_user_func_array(array($this, 'parseQueryParams'), $args);
|
||||||
|
|
||||||
$db = $this->get();
|
|
||||||
|
|
||||||
if ($this->success_handler) $starttime = microtime(true);
|
if ($this->success_handler) $starttime = microtime(true);
|
||||||
$result = $db->query($sql, $is_buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT);
|
$result = $db->query($sql, $is_buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT);
|
||||||
if ($this->success_handler) $runtime = microtime(true) - $starttime;
|
if ($this->success_handler) $runtime = microtime(true) - $starttime;
|
||||||
else $runtime = 0;
|
else $runtime = 0;
|
||||||
|
|
||||||
// ----- BEGIN ERROR HANDLING
|
// ----- BEGIN ERROR HANDLING
|
||||||
|
if (!$sql || $db->error) {
|
||||||
$error = '';
|
|
||||||
if (!$sql || $error = $this->checkError()) {
|
|
||||||
if ($this->error_handler) {
|
if ($this->error_handler) {
|
||||||
$error_handler = is_callable($this->error_handler) ? $this->error_handler : 'meekrodb_error_handler';
|
$error_handler = is_callable($this->error_handler) ? $this->error_handler : 'meekrodb_error_handler';
|
||||||
|
|
||||||
call_user_func($error_handler, array(
|
call_user_func($error_handler, array(
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'query' => $sql,
|
'query' => $sql,
|
||||||
'error' => $error
|
'error' => $db->error
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->throw_exception_on_error) {
|
if ($this->throw_exception_on_error) {
|
||||||
$e = new MeekroDBException($error, $sql);
|
$e = new MeekroDBException($db->error, $sql);
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
} else if ($this->success_handler) {
|
} else if ($this->success_handler) {
|
||||||
@@ -640,21 +637,14 @@ class MeekroDB {
|
|||||||
$return[] = $row;
|
$return[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->freeResult($result);
|
// free results
|
||||||
return $return;
|
$result->free();
|
||||||
}
|
|
||||||
|
|
||||||
protected function freeResult($result = null) {
|
|
||||||
if ($result instanceof MySQLi_Result) {
|
|
||||||
$result->free();
|
|
||||||
}
|
|
||||||
|
|
||||||
$db = $this->get();
|
|
||||||
while ($db->more_results()) {
|
while ($db->more_results()) {
|
||||||
$db->next_result();
|
$db->next_result();
|
||||||
if ($result = $db->use_result()) $result->free();
|
if ($result = $db->use_result()) $result->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function queryOneRow() { $args = func_get_args(); return call_user_func_array(array($this, 'queryFirstRow'), $args); }
|
public function queryOneRow() { $args = func_get_args(); return call_user_func_array(array($this, 'queryFirstRow'), $args); }
|
||||||
@@ -727,18 +717,6 @@ class MeekroDB {
|
|||||||
|
|
||||||
return $row[$column];
|
return $row[$column];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkError() {
|
|
||||||
$db = $this->get();
|
|
||||||
if ($db->error) {
|
|
||||||
$error = $db->error;
|
|
||||||
$db->rollback();
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WhereClause {
|
class WhereClause {
|
||||||
|
|||||||
Reference in New Issue
Block a user