The table created by salesforcewebform has a column named use which is a reserved word in MySQL. This is against the SQL coding conventions in Drupal.

As I understand it, the column names in the SQL queries performed by this module are quoted to avoid this problem. Unfortunately the quoting style used (`...`) is not standard SQL and cause this module to fail with other databases (such as PostgreSQL).

The code with the incompatible quoting is:

<?php
function salesforcewebform_nodeapi(&$node, $op, $form = NULL, $page = NULL) {
     if ( $node->type == 'webform') {

          switch ($op) {
          case 'insert':
          case 'update':
               if ( isset($node->use_salesforce) ) {
                    // store the SalesForce fields
                    $result = db_query("DELETE FROM {salesforcewebform} where `vid` = %d", $node->vid);
                    $result = db_query("INSERT INTO {salesforcewebform} (`vid`, `use`) " .
                                       "VALUES (%d, %d)", $node->vid, $node->use_salesforce);
               }
          break;
          case 'validate':

               break;
          case 'load':
               $result = db_query("SELECT `use` from {salesforcewebform} ".
                                  "WHERE `vid` = %d", $node->vid);
               // either $result has 0 or 1 rows, if we have one then add it to the node
               $row = db_fetch_array($result);

               if ( $row['use'] == '1' ) {
                    $node->use_salesforce = TRUE;
               }
               else {
                    $node->use_salesforce = FALSE;
               }
               break;
          }
     }
}
?>

As a side note the SQL doesn't use UPPERCASE for all reserved words (WHERE and FROM) as required by the conventions.

CommentFileSizeAuthor
#1 salesforcewebform_823874.patch3.13 KBobsidiandesign

Comments

obsidiandesign’s picture

Assigned: Unassigned » obsidiandesign
Status: Active » Needs review
StatusFileSize
new3.13 KB

Thanks for posting about this. In fact, both 'use' and 'object' are reserved SQL words. I've updated them to 'active' and 'objecttype' which are not reserved words according to http://developer.mimer.com/validator/sql-reserved-words.tml.

I've also removed all of the quoting using `, and fixed the lowercase FROM and WHERE in the two statements. I've tested this patch already, but I always like someone to confirm that it really works under 'normal' conditions before I commit it. If anyone could test & report back, I'll get this committed.

Thanks again,
Bryan O'Shea
Obsidian Design

obsidiandesign’s picture

Version: 6.x-1.2 » 6.x-1.x-dev
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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