You are here

function coder_upgrade_parse_delete_query_string in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_upgrade/conversions/db.inc \coder_upgrade_parse_delete_query_string()

Replaces D6 database API call with D7 equivalent.

@todo Fill in this with unhandled items.

Parameters

string $sql: The SQL query string to parse.

array $values: List of replacement values passed to db_query().

1 call to coder_upgrade_parse_delete_query_string()
coder_upgrade_parse_query_string in coder_upgrade/conversions/db.inc
Replaces D6 database API call with D7 equivalent.

File

coder_upgrade/conversions/db.inc, line 483
Provides conversion routines applied to database API function calls and hooks.

Code

function coder_upgrade_parse_delete_query_string($sql, $values) {
  global $_coder_upgrade_replacement_values_is_array;
  $new = array();

  // Look for query with a WHERE clause.
  // DELETE FROM {node} WHERE uid=%d AND created < %d
  $find = '@^DELETE\\s+FROM\\s+{(\\w+)}\\s+WHERE\\s+(.*?)$@s';
  preg_match($find, $sql, $matches);
  cdp($matches);
  if (empty($matches)) {

    // Look for query without a WHERE clause.
    $find = '@^DELETE\\s+FROM\\s+{(\\w+)}$@s';
    preg_match($find, $sql, $matches);
    cdp($matches, '$matches');
    if (empty($matches)) {
      cdp($sql, '$sql');
      clp('ERROR: could not parse sql DELETE statement.');
      return array(
        'NULL',
      );

      // $new;
    }
  }

  // Parse condition for rows to be deleted.
  $condition_count = isset($matches[2]) && $matches[2] ? coder_upgrade_count_sql_conditions($matches[2]) : 0;
  $replacement_count = $condition_count;
  cdp($replacement_count, '$replacement_count');
  if (count($values) != $replacement_count) {
    clp('ERROR: number of replacement values to db_query does not equal number of items needing replacement.');
    clp($sql);
  }
  $_coder_upgrade_replacement_values_is_array = count($values) == 1 && $replacement_count > 1;

  // Build DBTNG syntax string.
  $new[] = "db_delete('{$matches[1]}')";
  if (isset($matches[2]) && $matches[2]) {
    $new[] = coder_upgrade_parse_sql_conditions($matches[2], $values);
  }
  $new[] = "\t->execute();";
  cdp($new, '$new');
  return $new;
}