As part of #1533096: Make includes directory, files starting with D-G pass Coder Review I've noticed:

database.inc

 * @code
 * INSERT INTO {example} (id, uid, path, name) VALUES (1, 2, 'home', 'Home path');
 * @endcode
 * one would instead write:
 * @code
 * $fields = array('nid' => 1, 'title' => 'my title', 'body' => 'my body');
 * db_insert('node')->fields($fields)->execute();
 * @endcode

The example code above doesn't make sense, in the first part of the example we put 4 values into the 'example' table, in the second part of the example we put 3 different fields into a different table.

I suggest changing the second part of the example to match the table and fields in the first part.

I'll post a patch for this in a moment

CommentFileSizeAuthor
#1 database.inc_example-2060037-1.patch949 bytessphism

Comments

sphism’s picture

Issue summary: View changes

added backlink to original issue

sphism’s picture

Status: Active » Needs review
StatusFileSize
new949 bytes

Here's the new example, which i think makes more sense and is formatted correctly:

@code
 * INSERT INTO {example} (id, uid, path, name) VALUES (1, 2, 'path', 'Name');
 * @endcode
 * one would instead write:
 * @code
 * $fields = array('id' => 1, 'uid' => 2, 'path' => 'path', 'name' => 'Name');
 * db_insert('example')
 *   ->fields($fields)
 *   ->execute();
 * @endcode
longwave’s picture

Status: Needs review » Reviewed & tested by the community

That makes much more sense now.

sphism’s picture

Great stuff, thanks for reviewing that so quickly @longwave

longwave’s picture

Checked to see if this needs backporting, but in D7 both examples use the node table. This was changed in D8 in #1498674: Refactor node properties to multilingual but the db_insert() example was missed.

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch, review, and check for D7 backport needs! Committed to 8.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

database.inc