You are here

function coder_upgrade_parse_query_string in Coder 7

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

Replaces D6 database API call with D7 equivalent.

@todo Fill in this with unhandled items.

Parameters

PGPNode $node: The node containing the function call object to be replaced. [@param PGPOperand $operand The query string to be parsed (first parameter to $item).]

string $sql: The query string to be parsed

integer $from: The first record from the result set to return.

integer $count: The number of records to return from the result set.

3 calls to coder_upgrade_parse_query_string()
coder_upgrade_upgrade_call_db_query_alter in coder_upgrade/conversions/db.inc
Implements hook_upgrade_call_db_query_alter().
coder_upgrade_upgrade_call_db_query_range_alter in coder_upgrade/conversions/db.inc
Implements hook_upgrade_call_db_query_range_alter().
coder_upgrade_upgrade_call_db_rewrite_sql_alter in coder_upgrade/conversions/db.inc
Implements hook_upgrade_call_db_rewrite_sql_alter().

File

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

Code

function coder_upgrade_parse_query_string(&$node, $sql, $from = 0, $count = 0) {
  global $_coder_upgrade_replacement_values_is_array, $_coder_upgrade_replacement_index;
  $_coder_upgrade_replacement_index = 0;

  // Create helper objects.
  //  $editor = PGPEditor::getInstance();
  // Get the function call object.
  $item =& $node->data;

  // TODO Parse the values - the other parameters
  // TODO The parameter could be an array variable or expression like array_merge($a, $b)
  // With the latter, add an assignment variable equal to the expression. Then
  // set replacement variables equal to variable[$index].
  // See http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/database_test.test?revision=1.80&view=markup
  $values = array();
  for ($i = 1; $i < $item
    ->parameterCount(); $i++) {
    $item
      ->setParameter($i, $item
      ->getParameter($i)
      ->stripComments());
    $values[] = $item
      ->printParameter($i);
  }
  cdp($values, '$values');

  /*
   * TODO Run the table names through a conversion routine.
   * Ex: taxonomy, block, etc.
   */
  $new = array();
  $delimiter = $sql[0];

  // Save this for SELECT queries.
  // Alter the string for these SQL types as we are making entirely new syntax.
  // Trim won't work here, since it'll trim off the last ' if the string ends in '%s'
  $sql = substr($sql, 1, -1);

  // $sql = substr($operand['value'], 1, -1);
  // Assume there is no literal string containing any new lines or commas.
  //  $sql = preg_replace("@\n@", ' ', $sql);
  if (strpos($sql, 'SELECT') === 0) {

    // @todo If $sql is defined outside of db_query(), then this approach will
    // replace the variable with the new string and leave the assignment alone.
    $new = coder_upgrade_parse_select_query_string($node, $sql, $values, $delimiter);

    //    coder_upgrade_insert_dbtng_statement($node, $new); // ???
  }

  // Assume there is no literal string containing any new lines or commas.
  $sql = preg_replace("@\n@", ' ', $sql);
  if (strpos($sql, 'INSERT') === 0) {
    $new = coder_upgrade_parse_insert_query_string($sql, $values);
    coder_upgrade_insert_dbtng_statement($node, $new);
  }
  elseif (strpos($sql, 'UPDATE') === 0) {
    $new = coder_upgrade_parse_update_query_string($sql, $values);
    coder_upgrade_insert_dbtng_statement($node, $new);
  }
  elseif (strpos($sql, 'DELETE') === 0) {
    $new = coder_upgrade_parse_delete_query_string($sql, $values);
    coder_upgrade_insert_dbtng_statement($node, $new);
  }
}