Closed (fixed)
Project:
Views (for Drupal 7)
Version:
8.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
23 Aug 2012 at 15:50 UTC
Updated:
4 Jan 2014 at 02:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
ACF commentedBelow is a documentation of all the uses of db_query in views outside of the TempStore.php. All instances follow the pattern: Filename - Line - Function - query
db_query
views.install - L14 - function views_install - db_query("UPDATE {system} SET weight = 10 WHERE name = 'views'");
views.module - L1750 - function views_load_display_records(&$views) - $result = db_query("SELECT * FROM {{$table_name}} WHERE vid IN (:vids) ORDER BY vid, position", array(':vids' => array_keys($names)));
api-default-views.html - L79 - db_query("UPDATE {system} SET weight = 11 WHERE name = 'mymodule'");
admin.inc - L4737 - function views_ui_get_roles() - $result = db_query("SELECT r.rid, r.name FROM {role} r ORDER BY r.name");
handlers.inc - L253 - function function views_get_timezone() - db_query("SET TIME ZONE INTERVAL '$offset' HOUR TO MINUTE");
handlers.inc - L256 - function function views_get_timezone() - db_query("SET @@session.time_zone = '$offset'");
View.php - L1797 - static function load_view() - $result = db_query("SELECT DISTINCT v.* FROM {views_view} v");
View.php - L1819 - static function load_view() - $result = db_query("SELECT * FROM {{$table_name}} WHERE vid IN (:vids) ORDER BY vid, position", array(':vids' => array_keys($names)));
View.php - L1853 - function save() - $vid = db_query("SELECT vid from {views_view} WHERE name = :name", array(':name' => $this->name))->fetchField();
Block.php - L253 - function save_block_cache - db_query("SELECT bid FROM {block} WHERE module = 'views' AND delta = :delta", array( ':delta' => $delta))->fetchField())
argument/CategoryCid.php - L31 - function title_query() - $result = db_query("SELECT c.title FROM {aggregator_category} c
WHERE c.cid IN (:cid)", array(':cid' => $this->value));
Fid.php - L31 - function title_query() - $result = db_query("SELECT f.title FROM {aggregator_feed} f WHERE f.fid IN (:fids)", array(':fids' => $this->value));
filter/CategoryCid.php - L32 - function get_value_options() - $result = db_query('SELECT * FROM {aggregator_category} ORDER BY title');
Rss.php - L61 - function render($row) - $result = db_query('SELECT * FROM {aggregator_category} ORDER BY title');
UserUid.php - L31 - function title() - $title = db_query('SELECT u.name FROM {users} u WHERE u.uid = :uid', array(':uid' => $this->argument))->fetchField();
NewNodeComments.php - L86 - function pre_render(&$values) - $result = db_query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comment} c ON n.nid = c.nid
LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN (:nids)
AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp), :timestamp) AND c.status = :status GROUP BY n.nid ", array(
':status' => COMMENT_PUBLISHED,
':h_uid' => $user->uid,
':nids' => $nids,
':timestamp' => NODE_NEW_LIMIT,
));
Version.php - L30 - function get_value_options() - $result = db_query('SELECT DISTINCT(version) FROM {locales_source} ORDER BY version');
Vid.php - L31 - function title_query() - $results = db_query("SELECT nr.vid, nr.nid, nr.title FROM {node_revision} nr WHERE nr.vid IN (:vids)", array(':vids' => $this->value))->fetchAllAssoc('vid', PDO::FETCH_ASSOC);
Type.php - L28 - function get_value_options() - $types = db_query('SELECT DISTINCT(type) FROM {system} ORDER BY type')->fetchAllKeyed(0, 0);
VocabularyMachineName.php - L23 - function title() - $title = db_query("SELECT v.name FROM {taxonomy_vocabulary} v WHERE v.machine_name = :machine_name", array(':machine_name' => $this->argument))->fetchField();
VocabularyVid.php - L29 - function title() - $title = db_query("SELECT v.name FROM {taxonomy_vocabulary} v WHERE v.vid = :vid", array(':vid' => $this->argument))->fetchField();
NodeTnid.php - L31 - function title_query() - $result = db_query("SELECT n.title FROM {node} n WHERE n.tnid IN (:tnids)", array(':tnids' => $this->value));
RolesRid - L28 - function title_query() - $result = db_query("SELECT name FROM {role} WHERE rid IN (:rids)", array(':rids' => $this->value));
User.php - L116 - function validate_argument($argument) - $query = "SELECT uid, name FROM {users} WHERE $where"; $account = db_query($query, array(':argument' => $argument))->fetchObject();
User.php - L128 - function validate_argument($argument) - $result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
Permission.php - L55 - function pre_render(&$values) - $result = db_query("SELECT u.uid, u.rid, rp.permission FROM {role_permission} rp INNER JOIN {users_roles} u ON u.rid = rp.rid WHERE u.uid IN (:uids) AND rp.module IN (:modules) ORDER BY rp.permission", array(':uids' => $uids, ':modules' => array_keys($modules)));
Roles.php - L44 - function pre_render(&$values) - $result = db_query("SELECT u.uid, u.rid, r.name FROM {role} r INNER JOIN {users_roles} u ON u.rid = r.rid WHERE u.uid IN (:uids) ORDER BY r.name", array(':uids' => $uids));
Name.php - L30 - function value_form(&$form, &$form_state) - $result = db_query("SELECT * FROM {users} u WHERE uid IN (:uids)", array(':uids' => $this->value));
Name.php - L134 - function validate_user_strings(&$form, $values) - $result = db_query("SELECT * FROM {users} WHERE name IN (:names)", array(':names' => $args));
Name.php - L159 - function admin_summary() - $result = db_query("SELECT * FROM {users} u WHERE uid IN (:uids)", array(':uids' => $this->value));
db_query_range
admin.inc - L87 - function views_ui_check_advanced_help() - $filename = db_query_range("SELECT filename FROM {system} WHERE type = 'module' AND name = 'advanced_help'", 0, 1)->fetchField();
RelationshipNodeTermDataTest.php - L36 - function createTerm($vocabulary) - 'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(),
Comment #2
ACF commentedAn initial patch to fix some of the db_query.
Comment #3
ACF commentedComment #5
ACF commentedAnother try.
Comment #7
tim.plunkett#5: 1748168-views_db_queryfix.patch queued for re-testing.
Comment #8
tim.plunkettThis should remain a db_query but with a comment explaining that it is not using db_select because it passes no variables and is static.
The "IN" is implied, you don't need it explicitly.
Same with "=", it can be left out.
Same as above.
This has a trailing comma where it shouldn't
When adding a single field, use addField
Same thing about the equals sign
Also use addField
No need for "IN"
addField
No "IN"
AWESOME.
No "IN"
Comment #9
ACF commentedThanks Tim, have fixed the errors.
Comment #11
ACF commented#9: 1748168-views_db_queryfix-9.patch queued for re-testing.
Comment #13
ACF commented#9: 1748168-views_db_queryfix-9.patch queued for re-testing.
Comment #14
tim.plunkettComment #16
ACF commented#9: 1748168-views_db_queryfix-9.patch queued for re-testing.
Comment #18
ACF commentedHopefully this fixes it.
Comment #19
dawehnerI would personally vote to keep this stuff, as it will create a merge conflict in the future, but yeah this is looking fine.
I just rechecked, it is adding all the fields from ai. Could we improve things by just loading the actual stuff?
It would be make the code a bit easier to read if we rename that to $condition, but i'm fine with that as well.
Awesome!!
Comment #20
ACF commentedHave made those changes, thanks.
Comment #21
ACF commentedHave made those changes, thanks.
Comment #22
xjmThanks Alasdair. One minor suggestion on the comment:
For these, I'd just say something like "Use db_query() rather than db_select() because the query is static and does not include any variables." (Function names should be followed by parens in code comments, and we generally don't want to refer to the past or future of the code in comments unless it's specifically a
@todo.)Comment #23
ACF commentedThis patch now deals with all the db_query instances, except the exceptions discussed. Ignore this I need to change the comments.
Comment #24
ACF commentedFixed the comments issue, thanks for the tips xjm.
Comment #25
ACF commented#24: 1748168-views_db_queryfix-24.patch queued for re-testing.
Comment #26
ACF commentedre-rolling the patch to work with the latest code base.
Comment #27
dawehnerThis should probably be addExpression here, but maybe PHP is forgiving us that.
This should be really the last thing todo before the comment.
Comment #28
ACF commentedFix for addExpression
Comment #29
ACF commentedComment #30
dawehnerNow it is definitively time to get this into views!