Index: coder_upgrade.db.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/coder/coder_upgrade/conversions/coder_upgrade.db.inc,v
retrieving revision 1.3
diff -u -p -r1.3 coder_upgrade.db.inc
--- coder_upgrade.db.inc	11 Mar 2010 18:42:06 -0000	1.3
+++ coder_upgrade.db.inc	18 Apr 2010 21:54:54 -0000
@@ -27,7 +27,6 @@
  */
 function coder_upgrade_upgrade_call_db_query_alter(&$item, &$reader) {
   // Disable this routine until it is improved.
-  return;
 
   // Create helper objects.
   $editor = PGPEditor::getInstance();
@@ -75,8 +74,39 @@ function coder_upgrade_parse_query_strin
    * Ex: taxonomy, block, etc.
    */
   $new = array();
+  // TODO trim won't work here, since it'll trim off the last ' if the string ends in '%s'
   $sql = trim($operand['value'], "'\"");
   if (strpos($sql, 'SELECT') === 0) {
+    $find = '@^(SELECT.*?WHERE\s+)(.*?)$@m';
+    preg_match($find, $sql, $matches);
+    cdp($matches);
+    // Convert conditions from field = '%s' to field = :field
+    // TODO handle more complex conditions
+    if ($matches[2]) {
+      preg_match_all('/
+        (\S*)\s+=\s+([\'"]?%[sdfb][\'"]?) # Match field = %d
+        |
+        (\S*)\s+IN\s?\(([\'"]%s[\'"]?)\) # Match field IN(%s)
+        /x', $matches[2], $conditions); 
+      foreach ($conditions[0] as $key => $condition) {
+        if ($conditions[1][$key]) {
+          $condition_keys[] = ':'. $conditions[1][$key];
+          $operand['value'] = str_replace($condition, $conditions[1][$key] . ' = :' . $conditions[1][$key], $operand['value']);
+        }
+        else if ($conditions[3][$key]) {
+          $condition_keys[] = ':'. $conditions[3][$key];
+          $operand['value'] = str_replace($condition, $conditions[3][$key] . ' IN (:' . $conditions[3][$key] . ')', $operand['value']);
+          // D6 convention was to use implode(",", $array).  Now we can just pass in the array.
+          $param = $item->getParameter($key + 1)->getElement()->getParameter(1);  
+          $item->setParameter($key + 1, $param);
+        }
+      }
+      $editor->setParameter($item, 0, $operand['value']);
+      $string = $editor->arrayitize($item, 1, $condition_keys, array_fill(0, count($condition_keys), "'XXX_YYY'"));
+      $temp = $editor->expressionToStatement($string);
+      $temp->getElement(0)->multiline = 0;
+      $item->setParameter(1, $temp);
+    }
     return;
   }
   elseif (strpos($sql, 'INSERT') === 0) {
