diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-08-12 15:55:36 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-08-12 15:55:36 +0000 |
commit | b134b023e11902ceae12f3ab861da1f0a2fdbdbd (patch) | |
tree | fc0f0be2b23f047dd692e615e3671318f6d60f4d /includes | |
parent | 4e6068baf2c4dcb776efbdeb16621ffbdfa42c0f (diff) | |
download | brdo-b134b023e11902ceae12f3ab861da1f0a2fdbdbd.tar.gz brdo-b134b023e11902ceae12f3ab861da1f0a2fdbdbd.tar.bz2 |
- Patch #163191 by hswong3i: removed db_num_rows() for compatibility with Oracle and DB2. Also a performance improvement.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 2 | ||||
-rw-r--r-- | includes/database.mysql.inc | 23 | ||||
-rw-r--r-- | includes/database.mysqli.inc | 23 | ||||
-rw-r--r-- | includes/database.pgsql.inc | 21 | ||||
-rw-r--r-- | includes/locale.inc | 2 | ||||
-rw-r--r-- | includes/menu.inc | 2 | ||||
-rw-r--r-- | includes/session.inc | 4 |
7 files changed, 16 insertions, 61 deletions
diff --git a/includes/common.inc b/includes/common.inc index bd81a54bd..3a9aeeb03 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -807,7 +807,7 @@ function flood_register_event($name) { * True if the user did not exceed the hourly threshold. False otherwise. */ function flood_is_allowed($name, $threshold) { - $number = db_num_rows(db_query("SELECT event FROM {flood} WHERE event = '%s' AND hostname = '%s' AND timestamp > %d", $name, ip_address(), time() - 3600)); + $number = db_result(db_query("SELECT COUNT(*) FROM {flood} WHERE event = '%s' AND hostname = '%s' AND timestamp > %d", $name, ip_address(), time() - 3600)); return ($number < $threshold ? TRUE : FALSE); } diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc index 50819a19a..20cb9ae80 100644 --- a/includes/database.mysql.inc +++ b/includes/database.mysql.inc @@ -191,20 +191,6 @@ function db_fetch_array($result) { } /** - * Determine how many result rows were found by the preceding query. - * - * @param $result - * A database query result resource, as returned from db_query(). - * @return - * The number of result rows. - */ -function db_num_rows($result) { - if ($result) { - return mysql_num_rows($result); - } -} - -/** * Return an individual result field from the previous query. * * Only use this function if exactly one field is being selected; otherwise, @@ -295,9 +281,8 @@ function db_query_range($query) { * so that they can be properly escaped to avoid SQL injection attacks. * * Note that if you need to know how many results were returned, you should do - * a SELECT COUNT(*) on the temporary table afterwards. db_num_rows() and - * db_affected_rows() do not give consistent result across different database - * types in this case. + * a SELECT COUNT(*) on the temporary table afterwards. db_affected_rows() does + * not give consistent result across different database types in this case. * * @param $query * A string containing a normal SELECT SQL query. @@ -383,14 +368,14 @@ function db_unlock_tables() { * Check if a table exists. */ function db_table_exists($table) { - return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'")); + return db_fetch_object(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'")) ? TRUE : FALSE; } /** * Check if a column exists in the given table. */ function db_column_exists($table, $column) { - return db_num_rows(db_query("SHOW COLUMNS FROM {%s} LIKE '%s'", $table, $column)); + return db_fetch_object(db_query("SHOW COLUMNS FROM {%s} LIKE '%s'", $table, $column)) ? TRUE : FALSE; } /** diff --git a/includes/database.mysqli.inc b/includes/database.mysqli.inc index 38c3ce572..b51502a75 100644 --- a/includes/database.mysqli.inc +++ b/includes/database.mysqli.inc @@ -190,20 +190,6 @@ function db_fetch_array($result) { } /** - * Determine how many result rows were found by the preceding query. - * - * @param $result - * A database query result resource, as returned from db_query(). - * @return - * The number of result rows. - */ -function db_num_rows($result) { - if ($result) { - return mysqli_num_rows($result); - } -} - -/** * Return an individual result field from the previous query. * * Only use this function if exactly one field is being selected; otherwise, @@ -294,9 +280,8 @@ function db_query_range($query) { * so that they can be properly escaped to avoid SQL injection attacks. * * Note that if you need to know how many results were returned, you should do - * a SELECT COUNT(*) on the temporary table afterwards. db_num_rows() and - * db_affected_rows() do not give consistent result across different database - * types in this case. + * a SELECT COUNT(*) on the temporary table afterwards. db_affected_rows() does + * not give consistent result across different database types in this case. * * @param $query * A string containing a normal SELECT SQL query. @@ -382,14 +367,14 @@ function db_unlock_tables() { * Check if a table exists. */ function db_table_exists($table) { - return db_num_rows(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'")); + return db_fetch_object(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'")) ? TRUE : FALSE; } /** * Check if a column exists in the given table. */ function db_column_exists($table, $column) { - return db_num_rows(db_query("SHOW COLUMNS FROM {%s} LIKE '%s'", $table, $column)); + return db_fetch_object(db_query("SHOW COLUMNS FROM {%s} LIKE '%s'", $table, $column)) ? TRUE : FALSE; } /** diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc index e63f00b9d..c5fd4401b 100644 --- a/includes/database.pgsql.inc +++ b/includes/database.pgsql.inc @@ -208,20 +208,6 @@ function db_fetch_array($result) { } /** - * Determine how many result rows were found by the preceding query. - * - * @param $result - * A database query result resource, as returned from db_query(). - * @return - * The number of result rows. - */ -function db_num_rows($result) { - if ($result) { - return pg_num_rows($result); - } -} - -/** * Return an individual result field from the previous query. * * Only use this function if exactly one field is being selected; otherwise, @@ -323,9 +309,8 @@ function db_query_range($query) { * so that they can be properly escaped to avoid SQL injection attacks. * * Note that if you need to know how many results were returned, you should do - * a SELECT COUNT(*) on the temporary table afterwards. db_num_rows() and - * db_affected_rows() do not give consistent result across different database - * types in this case. + * a SELECT COUNT(*) on the temporary table afterwards. db_affected_rows() does + * not give consistent result across different database types in this case. * * @param $query * A string containing a normal SELECT SQL query. @@ -414,7 +399,7 @@ function db_unlock_tables() { * Check if a table exists. */ function db_table_exists($table) { - return db_num_rows(db_query("SELECT relname FROM pg_class WHERE relname = '{". db_escape_table($table) ."}'")); + return db_result(db_query("SELECT COUNT(*) FROM pg_class WHERE relname = '{". db_escape_table($table) ."}'")); } /** diff --git a/includes/locale.inc b/includes/locale.inc index 485dc841c..1397e3416 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -282,7 +282,7 @@ function _locale_languages_common_controls(&$form, $language = NULL) { function locale_languages_predefined_form_validate($form, &$form_state) { $langcode = $form_state['values']['langcode']; - if ($duplicate = db_num_rows(db_query("SELECT language FROM {languages} WHERE language = '%s'", $langcode)) != 0) { + if ($duplicate = db_result(db_query("SELECT COUNT(*) FROM {languages} WHERE language = '%s'", $langcode)) != 0) { form_set_error('langcode', t('The language %language (%code) already exists.', array('%language' => $form_state['values']['name'], '%code' => $langcode))); } diff --git a/includes/menu.inc b/includes/menu.inc index 373715533..624ee923b 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -724,7 +724,7 @@ function menu_tree_page_data($menu_name = 'navigation') { $args[] = $item['mlid']; } $placeholders = implode(', ', array_fill(0, count($args), '%d')); - } while (db_num_rows($result)); + } while ($item); } array_unshift($args, $menu_name); } diff --git a/includes/session.inc b/includes/session.inc index b842b1218..f79f11736 100644 --- a/includes/session.inc +++ b/includes/session.inc @@ -61,9 +61,9 @@ function sess_write($key, $value) { return TRUE; } - $result = db_query("SELECT sid FROM {sessions} WHERE sid = '%s'", $key); + $result = db_result(db_query("SELECT COUNT(*) FROM {sessions} WHERE sid = '%s'", $key)); - if (!db_num_rows($result)) { + if (!$result) { // Only save session data when when the browser sends a cookie. This keeps // crawlers out of session table. This reduces memory and server load, // and gives more useful statistics. We can't eliminate anonymous session |