You are here

function coder_upgrade_count_sql_conditions in Coder 7.2

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

Returns count of sql conditions that need a replacement value.

Parameters

string $string: String of sql conditions.

Return value

integer Count of conditions.

2 calls to coder_upgrade_count_sql_conditions()
coder_upgrade_parse_delete_query_string in coder_upgrade/conversions/db.inc
Replaces D6 database API call with D7 equivalent.
coder_upgrade_parse_update_query_string in coder_upgrade/conversions/db.inc
Replaces D6 database API call with D7 equivalent.

File

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

Code

function coder_upgrade_count_sql_conditions($string) {

  // Check for inner conditionals or function calls.  For now, we'll just use
  // where() instead of conditionals, given the complexity of inner conditionals.
  if (preg_match("/\\((.*)\\)/", $string, $matches)) {
    return 1;

    // return "\t\t->where('$string', " . var_dump($values) . ")";
  }
  $count = 0;

  // TODO Handle other conjunctions besides AND.
  $conditions = preg_split('/AND|OR|XOR|&&|\\|\\|/', $string);
  if (!is_array($conditions)) {
    $conditions = array(
      $string,
    );
  }
  foreach ($conditions as $condition) {

    // TODO Handle other functions like IN, BETWEEN
    list($condition, $operator, $value) = preg_split('/([!=><]+|LIKE|IN|BETWEEN)/', $condition, -1, PREG_SPLIT_DELIM_CAPTURE);
    if (preg_match('/%[sbdf]/', trim($value))) {
      $count++;
    }
  }
  return $count;
}