db_select is not (the default) mentioned function for selecting.

Maybe this would be nice to place next to db_query.

And please remove the comments :)

Comments

chx’s picture

Title: Documentation problem with Database abstraction layer » Better db_query docs
Component: documentation » database system
Status: Active » Needs review
StatusFileSize
new872 bytes

Here we go.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community
dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

clemens.tolboom’s picture

Status: Fixed » Needs review
StatusFileSize
new1.1 KB

I meant on http://api.drupal.org/api/group/database/7 there is no mention of db_select.

See the patch containing a db_select example.

chx’s picture

Status: Needs review » Needs work

Huh, really? The example is wrong as it does not use node access. Please change your patch to use node access and use a non-node example for the static string.

clemens.tolboom’s picture

Ehm ... what is wrong in not using 'node access'?

#4 shows a different approach for all "SELECT ... FROM node" on http://api.drupal.org/api/group/database/7

[ In short 'I don't copy' :( ]

chx’s picture

->addTag('node_access') http://api.drupal.org/api/drupal/developer--examples--node_access_exampl...

Edit: node listing queries must use the node_access tag same as db_rewirte_sql of old.

berdir’s picture

+++ includes/database/database.inc	18 Sep 2010 08:04:34 -0000
@@ -101,6 +101,16 @@
+ * Note that the above SELECT statements could also be implemented using db_select() like the following fetching 10 node:

Should be wrapped at 80 chars, nodes instead of node.

+++ includes/database/database.inc	18 Sep 2010 08:04:34 -0000
@@ -101,6 +101,16 @@
+ * $query->addField('node', 'nid');
+ * $query->addField('node', 'title');
+ * $query->addField('node', 'created');

You can write this in a single line, ->fields('node', array('nid', 'title', 'created'))

Also, you should be using chained method calls.

When adding an example, it should be done correctly.

Powered by Dreditor.

  • Dries committed 80d21ff on 8.3.x
    - Patch #909230 by chx: better db_query() docs.
    
    

  • Dries committed 80d21ff on 8.3.x
    - Patch #909230 by chx: better db_query() docs.
    
    

  • Dries committed 80d21ff on 8.4.x
    - Patch #909230 by chx: better db_query() docs.
    
    

  • Dries committed 80d21ff on 8.4.x
    - Patch #909230 by chx: better db_query() docs.
    
    

  • Dries committed 80d21ff on 9.1.x
    - Patch #909230 by chx: better db_query() docs.
    
    
daffie’s picture

Issue summary: View changes
Status: Needs work » Fixed
daffie’s picture

Status: Fixed » Closed (fixed)