? sites/default/files ? sites/default/settings.php Index: includes/database/database.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/database.inc,v retrieving revision 1.1 diff -u -p -r1.1 database.inc --- includes/database/database.inc 21 Aug 2008 19:36:36 -0000 1.1 +++ includes/database/database.inc 28 Aug 2008 17:10:43 -0000 @@ -146,6 +146,59 @@ abstract class DatabaseConnection extend */ public $lastStatement; + /** + * Drupal provides the following functions for portably generating SQL + * functions as strings to be merged into your SQL statements. + * + * Most implementation reference from ADOdb + * + * @link http://phplens.com/lens/adodb/tips_portable_sql.htm + */ + + /** + * String to use to quote identifiers and names. + */ + protected $nameQuote = '"'; + + /** + * Default concat operator. Change to || for Oracle/Interbase. + */ + protected $concat_operator = '+'; + + /** + * Uppercase function. + */ + public $upperCase = 'UPPER'; + + /** + * Random function. + */ + public $random = 'RAND()'; + + /** + * String length operator. + */ + public $length = 'LENGTH'; + + /** + * Substring operator. + */ + public $substr = 'SUBSTR'; + + /** + * Portably concatenate strings. + */ + public function concat($args) { + return implode($this->concat_operator, $args); + } + + /** + * Returns a string that is the equivalent of MySQL IFNULL or Oracle NVL. + */ + public function ifNull($expr1, $expr2) { + return " CASE WHEN $expr1 IS NULL THEN $expr2 ELSE $expr1 END "; + } + function __construct($dsn, $username, $password, $driver_options = array()) { $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; // Because the other methods don't seem to work right. parent::__construct($dsn, $username, $password, $driver_options); @@ -1123,6 +1176,58 @@ class DatabaseStatement extends PDOState */ /** + * Return the name of the SQL strtoupper function. + */ +function db_strtoupper() { + return Database::getActiveConnection()->upperCase; +} + +/** + * Return the SQL to generate a random number between 0.00 and 1.00. + */ +function db_rand() { + return Database::getActiveConnection()->random; +} + +/** + * Return the name of the SQL strlen function. + */ +function db_strlen() { + return Database::getActiveConnection()->length; +} + +/** + * Return the name of the SQL substr function. + */ +function db_substr() { + return Database::getActiveConnection()->substr; +} + +/** + * Different SQL databases used different methods to combine strings together. + * This function provides a wrapper. + * + * @param ... + * Variable number of string parameters. + * @return + * Portably concatenate strings. + */ +function db_strcat() { + $args = func_get_args(); + return Database::getActiveConnection()->concat($args); +} + +/** + * Returns a string that is the equivalent of MySQL IFNULL or Oracle NVL. + * + * @return + * If $expr1 is not NULL, returns $expr1; otherwise it returns $expr2. + */ +function db_if_null($expr1, $expr2) { + return Database::getActiveConnection()->ifNull($expr1, $expr2); +} + +/** * Execute an arbitrary query string against the active database. * * Do not use this function for INSERT, UPDATE, or DELETE queries. Those should Index: includes/database/mysql/database.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/mysql/database.inc,v retrieving revision 1.1 diff -u -p -r1.1 database.inc --- includes/database/mysql/database.inc 21 Aug 2008 19:36:36 -0000 1.1 +++ includes/database/mysql/database.inc 28 Aug 2008 17:10:43 -0000 @@ -14,6 +14,16 @@ class DatabaseConnection_mysql extends DatabaseConnection { protected $transactionSupport; + protected $nameQuote = '`'; + + public function concat($args) { + $return = implode(', ', $args); + return (strlen($return) > 0) ? "CONCAT($return)" : ''; + } + + public function ifNull($expr1, $expr2) { + return " IFNULL($expr1, $expr2) "; + } public function __construct(Array $connection_options = array()) { Index: includes/database/pgsql/database.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/pgsql/database.inc,v retrieving revision 1.2 diff -u -p -r1.2 database.inc --- includes/database/pgsql/database.inc 22 Aug 2008 12:46:25 -0000 1.2 +++ includes/database/pgsql/database.inc 28 Aug 2008 17:10:43 -0000 @@ -14,6 +14,13 @@ class DatabaseConnection_pgsql extends DatabaseConnection { protected $transactionSupport; + protected $concat_operator = '||'; + public $random = 'RANDOM()'; + public $substr = 'SUBSTRING'; + + public function ifNull($expr1, $expr2) { + return " COALESCE($expr1, $expr2) "; + } public function __construct(Array $connection_options = array()) { Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.647 diff -u -p -r1.647 comment.module --- modules/comment/comment.module 21 Aug 2008 19:36:36 -0000 1.647 +++ modules/comment/comment.module 28 Aug 2008 17:10:44 -0000 @@ -353,9 +353,9 @@ function comment_new_page_count($num_com else { // Threaded comments. // Find the first thread with a new comment. - $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1)) LIMIT 1', $node->nid, $new_replies); + $result = db_query('(SELECT thread FROM {comments} WHERE nid = %d AND status = 0 ORDER BY timestamp DESC LIMIT %d) ORDER BY ' . db_substr() . '(thread, 1, (' . db_strlen() . '(thread) - 1)) LIMIT 1', $node->nid, $new_replies); $thread = substr(db_result($result), 0, -1); - $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < '" . $thread . "'", $node->nid); + $result_count = db_query("SELECT COUNT(*) FROM {comments} WHERE nid = %d AND status = 0 AND " . db_substr() . "(thread, 1, (" . db_strlen() . "(thread) - 1)) < '" . $thread . "'", $node->nid); $count = db_result($result_count); $pageno = $count / $comments_per_page; } @@ -933,7 +933,7 @@ function comment_render($node, $cid = 0) // See comment above. Analysis reveals that this doesn't cost too // much. It scales much much better than having the whole comment // structure. - $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))'; + $query .= ' ORDER BY ' . db_substr() . '(c.thread, 1, (' . db_strlen() . '(c.thread) - 1))'; } $query = db_rewrite_sql($query, 'c', 'cid'); Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.221 diff -u -p -r1.221 locale.module --- modules/locale/locale.module 25 Aug 2008 07:54:36 -0000 1.221 +++ modules/locale/locale.module 28 Aug 2008 17:10:44 -0000 @@ -363,7 +363,7 @@ function locale($string = NULL, $langcod // Refresh database stored cache of translations for given language. // We only store short strings used in current version, to improve // performance and consume less memory. - $result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.textgroup = 'default' AND s.version = '%s' AND LENGTH(s.source) < 75", $langcode, VERSION); + $result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE s.textgroup = 'default' AND s.version = '%s' AND " . db_strlen() . "(s.source) < 75", $langcode, VERSION); while ($data = db_fetch_object($result)) { $locale_t[$langcode][$data->source] = (empty($data->translation) ? TRUE : $data->translation); } Index: modules/statistics/statistics.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.admin.inc,v retrieving revision 1.9 diff -u -p -r1.9 statistics.admin.inc --- modules/statistics/statistics.admin.inc 21 Aug 2008 19:36:38 -0000 1.9 +++ modules/statistics/statistics.admin.inc 28 Aug 2008 17:10:44 -0000 @@ -83,7 +83,7 @@ function statistics_top_visitors() { ); $sql = "SELECT COUNT(a.uid) AS hits, a.uid, u.name, a.hostname, SUM(a.timer) AS total, bl.iid FROM {accesslog} a LEFT JOIN {blocked_ips} bl ON a.hostname = bl.ip LEFT JOIN {users} u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name, bl.iid" . tablesort_sql($header); - $sql_cnt = "SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM {accesslog}"; + $sql_cnt = "SELECT COUNT(DISTINCT(" . db_strcat('uid', 'hostname') . ")) FROM {accesslog}"; $result = pager_query($sql, 30, 0, $sql_cnt); $rows = array();