summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/conf.php3
-rw-r--r--includes/database.pear.inc62
-rw-r--r--includes/pager.inc4
3 files changed, 56 insertions, 13 deletions
diff --git a/includes/conf.php b/includes/conf.php
index ae59d1047..920a94397 100644
--- a/includes/conf.php
+++ b/includes/conf.php
@@ -12,8 +12,9 @@
# and so on is likely to confuse the parser; use alpha-numerical
# characters instead.
-# $db_url = "pgsql://user:password@hostname/database";
# $db_url = "mysql://user:password@hostname/database";
+# $db_url = "pgsql://user:password@hostname/database";
+# $db_url = "mssql://user:password@hostname/database";
$db_url = "mysql://drupal:drupal@localhost/drupal";
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
diff --git a/includes/pager.inc b/includes/pager.inc
index 6f5a38773..c31693ec4 100644
--- a/includes/pager.inc
+++ b/includes/pager.inc
@@ -287,6 +287,7 @@ function pager_query($query, $limit = 10, $element = 0, $count_query = "") {
// count the total number of records in this query:
if ($count_query == "") {
$pager_total[$element] = db_result(db_query(preg_replace(array("/SELECT.*FROM/i", "/ORDER BY .*/"), array("SELECT COUNT(*) FROM", ""), $query)));
+
}
else {
$pager_total[$element] = db_result(db_query($count_query));
@@ -296,6 +297,7 @@ function pager_query($query, $limit = 10, $element = 0, $count_query = "") {
$pager_from_array = explode(",", $from);
return db_query_range($query, (int)$pager_from_array[$element], (int)$limit);
+
}
function pager_link($from_new, $attributes = array()) {
@@ -329,4 +331,4 @@ function pager_load_array($value, $element, $old_array) {
return $new_array;
}
-?>
+?> \ No newline at end of file