summaryrefslogtreecommitdiff
path: root/includes/database.pear.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/database.pear.inc')
-rw-r--r--includes/database.pear.inc62
1 files changed, 51 insertions, 11 deletions
diff --git a/includes/database.pear.inc b/includes/database.pear.inc
index 4a5faef9b..0b56efcdf 100644
--- a/includes/database.pear.inc
+++ b/includes/database.pear.inc
@@ -23,6 +23,7 @@ function db_connect($url) {
* @return sql result resource
*/
function db_query($query) {
+
$args = func_get_args();
if (count($args) > 1) {
$args = array_map("check_query", $args);
@@ -52,11 +53,19 @@ function _db_query($query, $debug = 0) {
global $db_handle, $queries;
if (variable_get("dev_query", 0)) {
- $queries[] = $query;
+ list($usec, $sec) = explode(" ", microtime());
+ $timer = (float)$usec + (float)$sec;
}
$result = $db_handle->query($query);
+ if (variable_get("dev_query", 0)) {
+ list($usec, $sec) = explode(" ", microtime());
+ $stop = (float)$usec + (float)$sec;
+ $diff = $stop - $timer;
+ $queries[] = array($query, $diff);
+ }
+
if ($debug) {
print "<p>query: $query</p>";
}
@@ -103,7 +112,13 @@ function db_error() {
function db_next_id($name) {
global $db_handle;
- return $db_handle->nextID($name);
+ $result = $db_handle->nextID($name);
+ if (DB::isError($result)) {
+ watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($query));
+ }
+ else {
+ return $result;
+ }
}
function db_affected_rows() {
@@ -113,21 +128,46 @@ function db_affected_rows() {
}
/**
- * Generates a limited query
- *
- * @param string $query query
- * @param integer $from the row to start to fetching
- * @param integer $count the numbers of rows to fetch
+ * Runs a LIMIT query in the database.
*
+ * @param $query sql query followed by 'from' and 'count' parameters, followed by a variable number of arguments which are substituted into query by sprintf. 'from' is the row to start to fetching. 'count' the numbers of rows to fetch.
* @return mixed a DB_Result object or a DB_Error
*
* @access public
*/
+function db_query_range($query) {
+ global $db_handle, $queries;
-function db_query_range($query, $from, $count) {
- global $db_handle;
+ if (variable_get("dev_query", 0)) {
+ list($usec, $sec) = explode(" ", microtime());
+ $timer = (float)$usec + (float)$sec;
+ }
- return $db_handle->limitQuery($query, $from, $count);
+ $args = func_get_args();
+ $count = array_pop($args);
+ $from = array_pop($args);
+ if (count(func_get_args()) > 3) {
+ $args = array_map("check_query", $args);
+ $args[0] = $query;
+ $result = $db_handle->limitQuery(call_user_func_array("sprintf", $args), $from, $count);
+ }
+ else {
+ $result = $db_handle->limitQuery(func_get_arg(0), $from, $count);
+ }
+
+ if (variable_get("dev_query", 0)) {
+ list($usec, $sec) = explode(" ", microtime());
+ $stop = (float)$usec + (float)$sec;
+ $diff = $stop - $timer;
+ $queries[] = array($query. " [LIMIT $from, $count]", $diff);
+ }
+
+ if (DB::isError($result)) {
+ watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($query));
+ }
+ else {
+ return $result;
+ }
}
-?>
+?> \ No newline at end of file