db_create_table correctly escapes field names when creating a table. But drupal_write_record does not. This creates a situation where tables can be created, but records cannot be added. The following patch to includes/common.inc resolves the issue by adding back ticks around the field names, just as the create functionality does.

CommentFileSizeAuthor
#1 issue-1288268.patch795 bytesmattconnolly

Comments

mattconnolly’s picture

StatusFileSize
new795 bytes

Now there's an issue number, I can attach the patch correctly named.

mattconnolly’s picture

Why was the status of the patch "Ignored" i wonder?

mattconnolly’s picture

Status: Active » Needs review

Go Testbot!

joachim’s picture

Version: 6.22 » 6.x-dev
Status: Needs review » Needs work

I've been bitten by this one a few times... good idea!

+++ b/includes/common.inc
@@ -3510,6 +3510,11 @@ function drupal_write_record($table, &$object, $update = array()) {
+  // add backticks to field names

Comments should be a sentence with a capital letter and full stop.

I think it would be good to say 'escape' here, as that is the meaning of what is being done. Eg:

// Add backticks to escape field names.

+++ b/includes/common.inc
@@ -3510,6 +3510,11 @@ function drupal_write_record($table, &$object, $update = array()) {
+    $fields[$field_index] = '`'. $field .'`';

The dot operator needs a space each side of it.

4 days to next Drupal core point release.

damien tournoud’s picture

Status: Needs work » Closed (works as designed)
joachim’s picture

Version: 6.x-dev » 8.x-dev
Status: Closed (works as designed) » Active

> db_create_table correctly escapes field names when creating a table. But drupal_write_record does not

Then isn't this an inconsistency? You can create tables with the DB API that you then can't write to!

At the least we have a documentation bug -- drupal_write_record() should mention this.

valthebald’s picture

I think this issue was made irrelevant by DBTNG?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

daffie’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Drupal 8 no longer has a drupal_write_record() function.