diff options
Diffstat (limited to 'modules')
26 files changed, 189 insertions, 273 deletions
diff --git a/modules/block/block.module b/modules/block/block.module index a7f46ef1f..46b6f13be 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -290,7 +290,7 @@ function _block_rehash() { } function block_box_get($bid) { - return db_fetch_array(db_query("SELECT bx.*, bl.title FROM {boxes} bx INNER JOIN {blocks} bl ON bx.bid = bl.delta WHERE bl.module = 'block' AND bx.bid = %d", $bid)); + return db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid)); } /** diff --git a/modules/comment/comment.module b/modules/comment/comment.module index f7bfb9a04..75d7f0088 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -693,7 +693,7 @@ function comment_save($edit) { // Strip the "/" from the end of the parent thread. $parent->thread = (string) rtrim((string) $parent->thread, '/'); // Get the max value in *this* thread. - $max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE '%s.%%' AND nid = %d", $parent->thread, $edit['nid'])); + $max = db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE :thread AND nid = :nid", array(':thread' => $parent->thread .'%', ':nid' => $edit['nid']))->fetchField(); if ($max == '') { // First child of this parent. diff --git a/modules/dblog/dblog.install b/modules/dblog/dblog.install index 8c1b6af64..ca9107c8f 100644 --- a/modules/dblog/dblog.install +++ b/modules/dblog/dblog.install @@ -65,7 +65,7 @@ function dblog_schema() { 'link' => array( 'type' => 'varchar', 'length' => 255, - 'not null' => TRUE, + 'not null' => FALSE, 'default' => '', 'description' => t('Link to view the result of the event.'), ), @@ -77,7 +77,7 @@ function dblog_schema() { 'referer' => array( 'type' => 'varchar', 'length' => 128, - 'not null' => TRUE, + 'not null' => FALSE, 'default' => '', 'description' => t('URL of referring page.'), ), @@ -103,3 +103,13 @@ function dblog_schema() { return $schema; } + +/** + * Allow NULL values for links. + */ +function dblog_update_7001() { + $ret = array(); + db_change_field($ret, 'watchdog', 'link', 'link', array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'default' => '')); + db_change_field($ret, 'watchdog', 'referer', 'referer', array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'default' => '')); + return $ret; +} diff --git a/modules/dblog/dblog.module b/modules/dblog/dblog.module index d4791b5a8..4fb41b0f5 100644 --- a/modules/dblog/dblog.module +++ b/modules/dblog/dblog.module @@ -135,7 +135,8 @@ function dblog_watchdog($log = array()) { $log['request_uri'], $log['referer'], $log['ip'], - $log['timestamp']); + $log['timestamp'] + ); if ($current_db) { db_set_active($current_db); diff --git a/modules/dblog/dblog.test b/modules/dblog/dblog.test index 8fa75e4da..258e46601 100644 --- a/modules/dblog/dblog.test +++ b/modules/dblog/dblog.test @@ -210,11 +210,18 @@ class DBLogTestCase extends DrupalWebTestCase { // Count rows that have uids for the user. $count = db_result(db_query('SELECT COUNT(wid) FROM {watchdog} WHERE uid = %d', $user->uid)); $this->assertTrue($count == 0, t('DBLog contains @count records for @name', array('@count' => $count, '@name' => $user->name))); + // Fetch row ids in watchdog that previously related to the deleted user. - $result = db_query('SELECT wid FROM {watchdog} WHERE uid = 0 AND wid IN (%s)', implode(', ', $ids)); + $select = db_select('watchdog'); + $select->addField('watchdog', 'wid'); + $select->condition('uid', 0); + if ($ids) { + $select->condition('wid', $ids, 'IN'); + } + $result = $select->execute(); unset($ids); - while ($row = db_fetch_array($result)) { - $ids[] = $row['wid']; + foreach ($result as $row) { + $ids[] = $row->wid; } $count_after = (isset($ids)) ? count($ids) : 0; $this->assertTrue($count_after == $count_before, t('DBLog contains @count records for @name that now have uid = 0', array('@count' => $count_before, '@name' => $user->name))); diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 4c9c0ee45..e397e6ba7 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -292,24 +292,24 @@ function filter_formats($index = NULL) { if (!isset($formats)) { $formats = array(); - $query = 'SELECT * FROM {filter_formats}'; + $query = db_select('filter_formats', 'f'); + $query->addField('f', 'format', 'format'); + $query->addField('f', 'name', 'name'); + $query->addField('f', 'roles', 'roles'); + $query->addField('f', 'cache', 'cache'); + $query->addField('f', 'weight', 'weight'); + $query->orderBy('weight'); // Build query for selecting the format(s) based on the user's roles. - $args = array(); if (!$all) { - $where = array(); + $or = db_or()->condition('format', variable_get('filter_default_format', 1)); foreach ($user->roles as $rid => $role) { - $where[] = "roles LIKE '%%,%d,%%'"; - $args[] = $rid; + $or->condition('roles', '%'. (int)$rid .'%', 'LIKE'); } - $query .= ' WHERE ' . implode(' OR ', $where) . ' OR format = %d'; - $args[] = variable_get('filter_default_format', 1); + $query->condition($or); } - $result = db_query($query . ' ORDER by weight', $args); - while ($format = db_fetch_object($result)) { - $formats[$format->format] = $format; - } + $formats = $query->execute()->fetchAllAssoc('format'); } if (isset($index)) { return isset($formats[$index]) ? $formats[$index] : FALSE; diff --git a/modules/menu/menu.module b/modules/menu/menu.module index f542ad5d7..3996acbc2 100644 --- a/modules/menu/menu.module +++ b/modules/menu/menu.module @@ -302,7 +302,7 @@ function menu_nodeapi(&$node, $op) { break; case 'delete': // Delete all menu module links that point to this node. - $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = 'node/%d' AND module = 'menu'", $node->nid); + $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu'", array(':path' => 'node/'. $node->nid)); while ($m = db_fetch_array($result)) { menu_link_delete($m['mlid']); } @@ -314,10 +314,15 @@ function menu_nodeapi(&$node, $op) { $item = array(); if (isset($node->nid)) { // Give priority to the default menu - $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = 'node/%d' AND menu_name = '%s' AND module = 'menu' ORDER BY mlid ASC", $node->nid, $menu_name, 0, 1)); + $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", array( + ':path' => 'node/'. $node->nid, + ':menu_name' => $menu_name, + ), 0, 1)); // Check all menus if a link does not exist in the default menu. if (!$mlid) { - $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = 'node/%d' AND module = 'menu' ORDER BY mlid ASC", $node->nid, 0, 1)); + $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", array( + ':path' => 'node/'. $node->nid, + ), 0, 1)); } if ($mlid) { $item = menu_link_load($mlid); @@ -428,15 +433,13 @@ function menu_node_form_submit($form, &$form_state) { */ function menu_get_menus($all = TRUE) { $system_menus = menu_list_system_menus(); - $sql = 'SELECT * FROM {menu_custom}'; + $query = db_select('menu_custom'); + $query->addField('menu_custom', 'menu_name', 'menu_name'); + $query->addField('menu_custom', 'title', 'title'); if (!$all) { - $sql .= ' WHERE menu_name NOT IN (' . implode(',', array_fill(0, count($system_menus), "'%s'")) . ')'; + $query->condition('menu_name', $system_menus, 'NOT IN'); } - $sql .= ' ORDER BY title'; - $result = db_query($sql, $system_menus); - $rows = array(); - while ($r = db_fetch_array($result)) { - $rows[$r['menu_name']] = $r['title']; - } - return $rows; + $query->orderBy('title'); + + return $query->execute()->fetchAllKeyed(); } diff --git a/modules/node/node.module b/modules/node/node.module index 49cc7aa75..471b5c8ab 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -511,12 +511,18 @@ function node_type_save($info) { if (!isset($info->help)) { $info->help = ''; } - if (!isset($info->min_word_count)) { + if (empty($info->min_word_count)) { $info->min_word_count = 0; } if (!isset($info->body_label)) { $info->body_label = ''; } + if (empty($info->custom)) { + $info->custom = 0; + } + if (empty($info->locked)) { + $info->locked = 0; + } if ($is_existing) { db_query("UPDATE {node_type} SET type = '%s', name = '%s', module = '%s', has_title = %d, title_label = '%s', has_body = %d, body_label = '%s', description = '%s', help = '%s', min_word_count = %d, custom = %d, modified = %d, locked = %d WHERE type = '%s'", $info->type, $info->name, $info->module, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->custom, $info->modified, $info->locked, $existing_type); @@ -2236,6 +2242,37 @@ function node_db_rewrite_sql($query, $primary_table, $primary_field) { } } + +/** + * Implementation of hook_query_alter(). + * @todo This doesn't quite work yet. + */ +function DISABLED_node_query_alter(Query $query) { + if ($query->hasTag('node_access')) { + if (! user_access('administer nodes')) { + $query->distinct(); + $access_alias = $query->join('node_access', 'na', 'na.nid = n.nid'); + dsm('hello'); + _node_query_alter_where($query, 'view', $access_alias); + } + } +} + +function _node_query_alter_where($query, $op = 'view', $node_access_alias = 'na', $account = NULL) { + $or = db_or(); + foreach (node_access_grants($op, $account) as $realm => $gids) { + foreach ($gids as $gid) { + $or->condition("{$node_access_alias}.gid = :gid AND {$node_access_alias}.realm = :realm", array(':gid' => $gid, ':realm' => $realm)); + } + } + + if (count($or->conditions())) { + $query->condition($or); + } + + $query->condition("$node_access_alias.grant_$op", '>=', 1); +} + /** * This function will call module invoke to get a list of grants and then * write them to the database. It is called at node save, and should be @@ -2290,11 +2327,11 @@ function node_access_acquire_grants($node) { */ function node_access_write_grants($node, $grants, $realm = NULL, $delete = TRUE) { if ($delete) { - $query = 'DELETE FROM {node_access} WHERE nid = %d'; + $query = db_delete('node_access')->condition('nid', $node->nid); if ($realm) { - $query .= " AND realm in ('%s', 'all')"; + $query->condition('realm', array($realm, 'all'), 'IN'); } - db_query($query, $node->nid, $realm); + $query->execute(); } // Only perform work when node_access modules are active. diff --git a/modules/path/path.admin.inc b/modules/path/path.admin.inc index 4d74c14b4..dc03ad4fc 100644 --- a/modules/path/path.admin.inc +++ b/modules/path/path.admin.inc @@ -19,12 +19,14 @@ function path_admin_overview($keys = NULL) { $multilanguage = (module_exists('locale') || $count); if ($keys) { - // Replace wildcards with MySQL/PostgreSQL wildcards. + // Replace wildcards with PDO wildcards. $keys = preg_replace('!\*+!', '%', $keys); - $sql = "SELECT * FROM {url_alias} WHERE dst LIKE '%%%s%%'"; + $sql = "SELECT * FROM {url_alias} WHERE dst LIKE :keys"; + $args = array(':keys' => '%'. $keys .'%'); } else { $sql = 'SELECT * FROM {url_alias}'; + $args = array(); } $header = array( array('data' => t('Alias'), 'field' => 'dst', 'sort' => 'asc'), @@ -36,7 +38,7 @@ function path_admin_overview($keys = NULL) { $header[2] = array('data' => t('Language'), 'field' => 'language'); } $sql .= tablesort_sql($header); - $result = pager_query($sql, 50, 0 , NULL, $keys); + $result = pager_query($sql, 50, 0 , NULL, $args); $rows = array(); $destination = drupal_get_destination(); diff --git a/modules/path/path.test b/modules/path/path.test index 1cdd72692..48ff0eee8 100644 --- a/modules/path/path.test +++ b/modules/path/path.test @@ -132,6 +132,7 @@ class PathTestCase extends DrupalWebTestCase { // Check to make sure the node was created. $node = node_load(array('title' => $edit['title'])); + $this->assertNotNull(($node === FALSE ? NULL : $node), 'Node found in database. %s'); return $node; diff --git a/modules/profile/profile.admin.inc b/modules/profile/profile.admin.inc index f082256c1..bcc3e5e77 100644 --- a/modules/profile/profile.admin.inc +++ b/modules/profile/profile.admin.inc @@ -396,7 +396,7 @@ function profile_field_delete_submit($form, &$form_state) { */ function profile_admin_settings_autocomplete($string) { $matches = array(); - $result = db_query_range("SELECT category FROM {profile_fields} WHERE LOWER(category) LIKE LOWER('%s%%')", $string, 0, 10); + $result = db_query_range("SELECT category FROM {profile_fields} WHERE LOWER(category) LIKE LOWER(:category)", array(':category' => $string .'%'), 0, 10); while ($data = db_fetch_object($result)) { $matches[$data->category] = check_plain($data->category); } diff --git a/modules/profile/profile.pages.inc b/modules/profile/profile.pages.inc index ef1392343..56344503c 100644 --- a/modules/profile/profile.pages.inc +++ b/modules/profile/profile.pages.inc @@ -110,7 +110,10 @@ function profile_browse() { function profile_autocomplete($field, $string) { $matches = array(); if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) { - $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10); + $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC", array( + ':fid' => $field, + ':value' => $string .'%', + ), 0, 10); while ($data = db_fetch_object($result)) { $matches[$data->value] = check_plain($data->value); } diff --git a/modules/search/search.module b/modules/search/search.module index 5b659364a..92b7ee2c6 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -284,10 +284,7 @@ function search_update_totals() { $total = db_result(db_query("SELECT SUM(score) FROM {search_index} WHERE word = '%s'", $word)); // Apply Zipf's law to equalize the probability distribution $total = log10(1 + 1/(max(1, $total))); - db_query("UPDATE {search_total} SET count = %f WHERE word = '%s'", $total, $word); - if (!db_affected_rows()) { - db_query("INSERT INTO {search_total} (word, count) VALUES ('%s', %f)", $word, $total); - } + db_merge('search_total')->key(array('word' => $word))->fields(array('count' => $total))->execute(); } // Find words that were deleted from search_index, but are still in // search_total. We use a LEFT JOIN between the two tables and keep only the @@ -573,13 +570,15 @@ function search_index($sid, $type, $text) { // Insert results into search index foreach ($results[0] as $word => $score) { - // Try inserting first because this will succeed most times, but because - // the database collates similar words (accented and non-accented), the - // insert can fail, in which case we need to add the word scores together. - @db_query("INSERT INTO {search_index} (word, sid, type, score) VALUES ('%s', %d, '%s', %f)", $word, $sid, $type, $score); - if (!db_affected_rows()) { - db_query("UPDATE {search_index} SET score = score + %f WHERE word = '%s' AND sid = %d AND type = '%s'", $score, $word, $sid, $type); - } + // If a word already exists in the database, its score gets increased + // appropriately. If not, we create a new record with the appropriate + // starting score. + db_merge('search_index')->key(array( + 'word' => $word, + 'sid' => $sid, + 'type' => $type, + ))->fields(array('score' => $score))->expression('score', 'score + :score', array(':score' => $score)) + ->execute(); search_dirty($word); } unset($results[0]); @@ -790,7 +789,7 @@ function search_parse_query($text) { $any |= $num_new_scores; if ($q) { $queryor[] = $q; - $arguments[] = $or; + $arguments[] = "% $or %"; } } if (count($queryor)) { @@ -805,7 +804,7 @@ function search_parse_query($text) { list($q, $num_new_scores, $num_valid_words) = _search_parse_query($key, $arguments2); if ($q) { $query[] = $q; - $arguments[] = $key; + $arguments[] = "% $key %"; if (!$num_valid_words) { $simple = FALSE; } @@ -822,7 +821,7 @@ function search_parse_query($text) { list($q) = _search_parse_query($key, $arguments2, TRUE); if ($q) { $query[] = $q; - $arguments[] = $key; + $arguments[] = "% $key %"; $simple = FALSE; } } @@ -856,7 +855,7 @@ function _search_parse_query(&$word, &$scores, $not = FALSE) { } } // Return matching snippet and number of added words - return array("d.data " . ($not ? 'NOT ' : '') . "LIKE '%% %s %%'", $num_new_scores, $num_valid_words); + return array("d.data " . ($not ? 'NOT ' : '') . "LIKE '%s'", $num_new_scores, $num_valid_words); } /** diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 1e4a950ce..6279d59b4 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -70,7 +70,16 @@ class DrupalWebTestCase { } $current_db_prefix = $db_prefix; $db_prefix = $this->db_prefix_original; - db_query("INSERT INTO {simpletest} (test_id, test_class, status, message, message_group, caller, line, file) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $this->test_id, get_class($this), $status, $message, $group, $function['function'], $function['line'], $function['file']); + db_insert('simpletest')->fields(array( + 'test_id' => $this->test_id, + 'test_class' => get_class($this), + 'status' => $status, + 'message' => substr($message, 0, 255), // Some messages are too long for the database. + 'message_group' => $group, + 'caller' => $function['function'], + 'line' => $function['line'], + 'file' => $function['file'], + ))->execute(); $this->_assertions[] = array( 'status' => $status, 'message' => $message, @@ -631,6 +640,7 @@ class DrupalWebTestCase { // Generate temporary prefixed database to ensure that tests have a clean starting point. $db_prefix = 'simpletest' . mt_rand(1000, 1000000); + include_once './includes/install.inc'; drupal_install_system(); @@ -639,6 +649,12 @@ class DrupalWebTestCase { $modules = array_unique(array_merge(drupal_verify_profile('default', 'en'), $args)); drupal_install_modules($modules); + // Because the schema is static cached, we need to flush + // it between each run. If we don't, then it will contain + // stale data for the previous run's database prefix and all + // calls to it will fail. + drupal_get_schema(NULL, TRUE); + // Run default profile tasks. $task = 'profile'; default_profile_tasks($task, ''); diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index 05907d454..3decbfe76 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -312,8 +312,7 @@ function simpletest_test_form_submit($form, &$form_state) { function simpletest_run_tests($test_list, $reporter = 'drupal', $batch_mode = FALSE) { global $db_prefix, $db_prefix_original; cache_clear_all(); - db_query('INSERT INTO {simpletest_test_id} VALUES (default)'); - $test_id = db_last_insert_id('simpletest_test_id', 'test_id'); + $test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute(); if ($batch_mode) { $batch = array( @@ -501,11 +500,14 @@ function simpletest_clean_database() { * @return mixed Array of matching tables or count of tables. */ function simpletest_get_like_tables($base_table = 'simpletest', $count = FALSE) { - global $db_url, $db_prefix; - $url = parse_url($db_url); - $database = substr($url['path'], 1); + global $db_prefix, $database; + $connection_info = Database::getConnectionInfo(); + $database_name = $connection_info['default']['database']; $select = $count ? 'COUNT(table_name)' : 'table_name'; - $result = db_query("SELECT $select FROM information_schema.tables WHERE table_schema = '$database' AND table_name LIKE '$db_prefix$base_table%'"); + $result = db_query("SELECT $select FROM information_schema.tables WHERE table_schema = :database AND table_name LIKE :table_name", array( + ':database' => $database_name, + ':table_name' => $db_prefix . $base_table . '%', + )); $schema = drupal_get_schema_unprocessed('simpletest'); if ($count) { diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index dc76829e5..d9c6ceaa1 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -130,17 +130,10 @@ class DrupalHTTPRequestTestCase extends DrupalWebTestCase { } function testDrupalHTTPRequest() { - // Parse URL schema. $missing_scheme = drupal_http_request('example.com/path'); $this->assertEqual($missing_scheme->error, 'missing schema', t('Returned with missing scheme error.')); $unable_to_parse = drupal_http_request('http:///path'); $this->assertEqual($unable_to_parse->error, 'unable to parse URL', t('Returned with unable to parse URL error.')); - - // Fetch page. - $result = drupal_http_request(url('node', array('absolute' => TRUE))); - $this->assertEqual($result->code, 200, t('Fetched page successfully.')); - $this->drupalSetContent($result->data); - $this->assertTitle(variable_get('site_name', 'Drupal'), t('Site title matches.')); } } diff --git a/modules/simpletest/tests/database.test b/modules/simpletest/tests/database.test deleted file mode 100644 index 83bb3a123..000000000 --- a/modules/simpletest/tests/database.test +++ /dev/null @@ -1,182 +0,0 @@ -<?php -// $Id$ - -class DatabaseSecurityTestCase extends DrupalWebTestCase { - - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Database placeholders'), - 'description' => t('Make sure that invalid values do not get passed through the %n, %d, or %f placeholders.'), - 'group' => t('System') - ); - } - - function testPlaceholders() { - // First test the numeric type - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543.21, - '123.456' => 123.46, - '+0.1e3' => 0.1e3, - ); - $not_valid = array( - '1x' => 0, - '4.4 OR 1=1' => 0, - '9 9' => 0, - '0xff' => 0, - 'XXX' => 0, - '0Xaa' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 0, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'numeric', - 'precision' => 5, - 'scale' => 2, - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_numeric', $schema); - $insert_query = 'INSERT INTO {test_numeric} (n) VALUES (' . db_type_placeholder('numeric') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_numeric}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_numeric}')); - $this->assertEqual(1, $count, "[numeric] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_numeric}')); - $this->assertEqual($select, $test, "[numeric] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_numeric}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_numeric}')); - $this->assertEqual(1, $count, "[numeric] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_numeric}')); - $this->assertEqual(0, $test, "[numeric] Got $select ($test) after inserting invalid value $insert"); - } - - // Test ints - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543, - '123.456' => 123, - '22' => 22, - ); - $not_valid = array( - '+0.1e3' => 0, - '0xff' => 0, - '0Xaa' => 0, - '1x' => 1, - '4.4 OR 1=1' => 4, - '9 9' => 9, - 'XXX' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 44, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'int', - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_int', $schema); - $insert_query = 'INSERT INTO {test_int} (n) VALUES (' . db_type_placeholder('int') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_int}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_int}')); - $this->assertEqual(1, $count, "[int] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_int}')); - $this->assertEqual($select, $test, "[int] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_int}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_int}')); - $this->assertEqual(1, $count, "[int] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_int}')); - $this->assertEqual($select, $test, "[int] Got $select ($test) after inserting invalid value $insert"); - } - - // Test floats - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543.21, - '123.456' => 123.456, - '22' => 22, - '+0.1e3' => 100, - ); - $not_valid = array( - '0xff' => 0, - '0Xaa' => 0, - '1x' => 1, - '4.4 OR 1=1' => 4.4, - '9 9' => 9, - 'XXX' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 44, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'float', - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_float', $schema); - $insert_query = 'INSERT INTO {test_float} (n) VALUES (' . db_type_placeholder('float') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_float}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_float}')); - $this->assertEqual(1, $count, "[float] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_float}')); - $this->assertEqual($select, $test, "[float] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_float}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_float}')); - $this->assertEqual(1, $count, "[float] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_float}')); - $this->assertEqual($select, $test, "[float] Got $select ($test) after inserting invalid value $insert"); - } - - } -} diff --git a/modules/statistics/statistics.admin.inc b/modules/statistics/statistics.admin.inc index bc2e539e5..891abe81e 100644 --- a/modules/statistics/statistics.admin.inc +++ b/modules/statistics/statistics.admin.inc @@ -107,8 +107,8 @@ function statistics_top_visitors() { * Menu callback; presents the "referrer" page. */ function statistics_top_referrers() { - $query = "SELECT url, COUNT(url) AS hits, MAX(timestamp) AS last FROM {accesslog} WHERE url NOT LIKE '%%%s%%' AND url <> '' GROUP BY url"; - $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%%%s%%'"; + $query = "SELECT url, COUNT(url) AS hits, MAX(timestamp) AS last FROM {accesslog} WHERE url NOT LIKE :host AND url <> '' GROUP BY url"; + $query_cnt = "SELECT COUNT(DISTINCT(url)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE :host"; drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))))); $header = array( @@ -118,7 +118,7 @@ function statistics_top_referrers() { ); $query .= tablesort_sql($header); - $result = pager_query($query, 30, 0, $query_cnt, $_SERVER['HTTP_HOST']); + $result = pager_query($query, 30, 0, $query_cnt, array(':host' => '%'. $_SERVER['HTTP_HOST'] .'%')); $rows = array(); while ($referrer = db_fetch_object($result)) { diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 06bfef5c3..4242aec5b 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -51,17 +51,31 @@ function statistics_exit() { // We are counting content views. if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') { // A node has been viewed, so update the node's counters. - db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1)); - // If we affected 0 rows, this is the first time viewing the node. - if (!db_affected_rows()) { - // We must create a new row to store counters for the new node. - db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time()); - } + $fields = array( + 'daycount' => 1, + 'totalcount' => 1, + 'nid' => arg(1), + 'timestamp' => time(), + ); + db_merge('node_counter') + ->fields($fields) + ->expression('daycount', 'daycount + 1') + ->expression('totalcount', 'totalcount + 1') + ->execute(); } } if (variable_get('statistics_enable_access_log', 0)) { // Log this page access. - db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), ip_address(), $user->uid, session_id(), timer_read('page'), time()); + db_insert('accesslog')->fields(array( + 'title' => strip_tags(drupal_get_title()), + 'path' => $_GET['q'], + 'url' => referer_uri(), + 'hostname' => ip_address(), + 'uid' => $user->uid, + 'sid' => session_id(), + 'timer' => timer_read('page'), + 'timestamp' => time(), + ))->execute(); } } diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 7c1bf0519..d4e110801 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -606,11 +606,11 @@ function _system_is_incompatible(&$incompatible, $files, $file) { */ function system_modules($form_state = array()) { // Clear all caches. + registry_rebuild(); drupal_theme_rebuild(); node_types_rebuild(); menu_rebuild(); cache_clear_all('schema', 'cache'); - // Get current list of modules. $files = module_rebuild_cache(); @@ -677,6 +677,9 @@ function system_modules($form_state = array()) { $extra['dependents'][] = $files[$dependent]->info['name'] . t(' (<span class="admin-disabled">disabled</span>)'); } } + if (!isset($module->info['package'])) { + $module->info['package'] = 'Other'; + } $form['modules'][$module->info['package']][$filename] = _system_modules_build_row($module->info, $extra); } // Add basic information to the fieldsets. @@ -2245,4 +2248,4 @@ function theme_system_themes_form($form) { $output = theme('table', $header, $rows); $output .= drupal_render($form); return $output; -}
\ No newline at end of file +} diff --git a/modules/system/system.install b/modules/system/system.install index 91a1c23f1..fc28922ed 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -303,7 +303,7 @@ function system_requirements($phase) { * Implementation of hook_install(). */ function system_install() { - if ($GLOBALS['db_type'] == 'pgsql') { + if (db_driver() == 'pgsql') { // We create some custom types and functions using global names instead of // prefixing them like we do with table names. If this function is ever // called again (for example, by the test framework when creating prefixed diff --git a/modules/system/system.module b/modules/system/system.module index 9b79eb9e5..e375201db 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -1123,7 +1123,7 @@ function system_region_list($theme_key) { static $list = array(); if (!array_key_exists($theme_key, $list)) { - $info = unserialize(db_result(db_query("SELECT info FROM {system} WHERE type = 'theme' AND name = '%s'", $theme_key))); + $info = unserialize(db_result(db_query("SELECT info FROM {system} WHERE type = :type AND name = :name", array(':type' => 'theme', ':name' => $theme_key)))); $list[$theme_key] = array_map('t', $info['regions']); } diff --git a/modules/taxonomy/taxonomy.pages.inc b/modules/taxonomy/taxonomy.pages.inc index d0557dc59..3ee0b9743 100644 --- a/modules/taxonomy/taxonomy.pages.inc +++ b/modules/taxonomy/taxonomy.pages.inc @@ -119,7 +119,10 @@ function taxonomy_autocomplete($vid, $string = '') { $last_string = trim(array_pop($array)); $matches = array(); if ($last_string != '') { - $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = %d AND LOWER(t.name) LIKE LOWER('%%%s%%')", 't', 'tid'), $vid, $last_string, 0, 10); + $result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t WHERE t.vid = :vid AND LOWER(t.name) LIKE LOWER(:last_string)", 't', 'tid'), array( + ':vid' => $vid, + ':last_string' => '%'. $last_string .'%', + ), 0, 10); $prefix = count($array) ? implode(', ', $array) . ', ' : ''; diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index d3d900fad..91416f5dc 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -295,7 +295,8 @@ function trigger_comment($a1, $op) { actions_do($aid, $objects[$action_info['type']], $context); } else { - actions_do($aid, (object) $a1, $context); + $a1 = (object) $a1; + actions_do($aid, $a1, $context); } } } @@ -387,8 +388,9 @@ function trigger_taxonomy($op, $type, $array) { 'hook' => 'taxonomy', 'op' => $op ); + $_array = (object) $array; foreach ($aids as $aid => $action_info) { - actions_do($aid, (object) $array, $context); + actions_do($aid, $_array, $context); } } diff --git a/modules/user/user.module b/modules/user/user.module index ab5b2a48e..5f8b629bd 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1192,10 +1192,12 @@ function user_set_authmaps($account, $authmaps) { foreach ($authmaps as $key => $value) { $module = explode('_', $key, 2); if ($value) { - db_query("UPDATE {authmap} SET authname = '%s' WHERE uid = %d AND module = '%s'", $value, $account->uid, $module[1]); - if (!db_affected_rows()) { - db_query("INSERT INTO {authmap} (authname, uid, module) VALUES ('%s', %d, '%s')", $value, $account->uid, $module[1]); - } + db_insert('authmap')->key(array( + 'uid' => $account->uid, + 'module' => $module[1], + ))->fields(array( + 'authname' => $value, + ))->execute(); } else { db_query("DELETE FROM {authmap} WHERE uid = %d AND module = '%s'", $account->uid, $module[1]); diff --git a/modules/user/user.pages.inc b/modules/user/user.pages.inc index 3213208a2..df0c37fcc 100644 --- a/modules/user/user.pages.inc +++ b/modules/user/user.pages.inc @@ -12,7 +12,7 @@ function user_autocomplete($string = '') { $matches = array(); if ($string) { - $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10); + $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER(:name)", array(':name' => $string .'%'), 0, 10); while ($user = db_fetch_object($result)) { $matches[$user->name] = check_plain($user->name); } |