? modules/trigger/tests
? modules/trigger/trigger.rar
Index: modules/trigger/trigger.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/trigger.admin.inc,v
retrieving revision 1.10
diff -u -p -r1.10 trigger.admin.inc
--- modules/trigger/trigger.admin.inc	12 May 2009 08:37:45 -0000	1.10
+++ modules/trigger/trigger.admin.inc	27 May 2009 17:24:29 -0000
@@ -79,7 +79,11 @@ function trigger_unassign_submit($form, 
   $form_values = $form_state['values'];
   if ($form_values['confirm'] == 1) {
     $aid = actions_function_lookup($form_values['aid']);
-    db_query("DELETE FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $form_values['hook'], $form_values['operation'], $aid);
+    db_delete('trigger_assignments')
+      ->condition('hook', $form_values['hook'])
+      ->condition('op', $form_values['operation'])
+      ->condition('aid', $aid)
+      ->execute();
     $actions = actions_get_all_actions();
     watchdog('actions', 'Action %action has been unassigned.',  array('%action' => check_plain($actions[$aid]['description'])));
     drupal_set_message(t('Action %action has been unassigned.', array('%action' => $actions[$aid]['description'])));
@@ -185,7 +189,13 @@ function trigger_assign_form_validate($f
   $form_values = $form_state['values'];
   if (!empty($form_values['aid'])) {
     $aid = actions_function_lookup($form_values['aid']);
-    if (db_result(db_query("SELECT aid FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $form_values['hook'], $form_values['operation'], $aid))) {
+    $aid_exists = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND op = :op AND aid = :aid", array(
+      ':hook' => $form_values['hook'],
+      ':op' => $form_values['operation'],
+      ':aid' => $aid,
+    ))
+    ->fetchField();
+    if ($aid_exists) {
       form_set_error($form_values['operation'], t('The action you chose is already assigned to that trigger.'));
     }
   }
@@ -199,18 +209,47 @@ function trigger_assign_form_submit($for
 
   if (!empty($form_values['aid'])) {
     $aid = actions_function_lookup($form_values['aid']);
-    $weight = db_result(db_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s'", $form_values['hook'], $form_values['operation']));
-    db_query("INSERT INTO {trigger_assignments} values ('%s', '%s', '%s', %d)", $form_values['hook'], $form_values['operation'], $aid, $weight + 1);
+    $weight = db_query("SELECT MAX(weight) FROM {trigger_assignments} WHERE hook = :hook AND op = :op", array(
+      ':hook' => $form_values['hook'],
+      ':op' => $form_values['operation'],
+    ))
+    ->fetchField();
+
+    db_insert('trigger_assignments')
+      ->fields(array(
+        'hook' => $form_values['hook'], 
+        'op' => $form_values['operation'], 
+        'aid' => $aid, 
+        'weight' => $weight + 1,
+      ))
+      ->execute();
     // If this action changes a node property, we need to save the node
     // so the change will persist.
     $actions = actions_list();
     if (isset($actions[$aid]['behavior']) && in_array('changes_node_property', $actions[$aid]['behavior']) && ($form_values['operation'] != 'presave')) {
       // Delete previous node_save_action if it exists, and re-add a new one at a higher weight.
-      $save_post_action_assigned = db_result(db_query("SELECT aid FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s' AND aid = 'node_save_action'", $form_values['hook'], $form_values['operation']));
+      $save_post_action_assigned = db_query("SELECT aid FROM {trigger_assignments} WHERE hook = :hook AND op = :op AND aid = :aid", array(
+        ':hook' => $form_values['hook'],
+        ':op' => $form_values['operation'],
+        ':aid' => 'node_save_action',
+      ))
+      ->fetchField();
+
       if ($save_post_action_assigned) {
-        db_query("DELETE FROM {trigger_assignments} WHERE hook = '%s' AND op = '%s' AND aid = 'node_save_action'", $form_values['hook'], $form_values['operation']);
+        db_delete('trigger_assignments')
+          ->condition('hook', $form_values['hook'])
+          ->condition('op', $form_values['operation'])
+          ->condition('aid', 'node_save_action')
+          ->execute();
       }
-      db_query("INSERT INTO {trigger_assignments} VALUES ('%s', '%s', '%s', %d)", $form_values['hook'], $form_values['operation'], 'node_save_action', $weight + 2);
+      db_insert('trigger_assignments')
+        ->fields(array(
+          'hook' => $form_values['hook'], 
+          'op' => $form_values['operation'], 
+          'aid' => 'node_save_action', 
+          'weight' => $weight + 2,
+        ))
+        ->execute();
       if (!$save_post_action_assigned) {
         drupal_set_message(t('You have added an action that changes a the property of a post. A Save post action has been added so that the property change will be saved.'));
       }
@@ -270,12 +309,19 @@ function theme_trigger_display($element)
 function _trigger_get_hook_actions($hook, $op, $type = NULL) {
   $actions = array();
   if ($type) {
-    $result = db_query("SELECT h.aid, a.description FROM {trigger_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE a.type = '%s' AND h.hook = '%s' AND h.op = '%s' ORDER BY h.weight", $type, $hook, $op);
+    $result = db_query("SELECT h.aid, a.description FROM {trigger_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE a.type = :type AND h.hook = :hook AND h.op = :op ORDER BY h.weight", array(
+      ':type' => $type,
+      ':hook' => $hook,
+      ':op' => $op,
+    ));
   }
   else {
-    $result = db_query("SELECT h.aid, a.description FROM {trigger_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE h.hook = '%s' AND h.op = '%s' ORDER BY h.weight", $hook, $op);
+    $result = db_query("SELECT h.aid, a.description FROM {trigger_assignments} h LEFT JOIN {actions} a on a.aid = h.aid WHERE h.hook = :hook AND h.op = :op ORDER BY h.weight", array(
+      ':hook' => $hook,
+      ':op' => $op,
+    ));
   }
-  while ($action = db_fetch_object($result)) {
+  foreach ($result as $action) {
     $actions[$action->aid] = $action->description;
   }
   return $actions;
Index: modules/trigger/trigger.api.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/trigger.api.php,v
retrieving revision 1.3
diff -u -p -r1.3 trigger.api.php
--- modules/trigger/trigger.api.php	8 Mar 2009 04:25:07 -0000	1.3
+++ modules/trigger/trigger.api.php	27 May 2009 17:24:29 -0000
@@ -88,7 +88,9 @@ function hook_action_info() {
  *   The action ID.
  */
 function hook_actions_delete($aid) {
-  db_query("DELETE FROM {actions_assignments} WHERE aid = '%s'", $aid);
+  db_delete('actions_assignments')
+    ->condition('aid', $aid)
+    ->execute();  
 }
 
 /**
Index: modules/trigger/trigger.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/trigger/trigger.module,v
retrieving revision 1.35
diff -u -p -r1.35 trigger.module
--- modules/trigger/trigger.module	27 May 2009 16:29:05 -0000	1.35
+++ modules/trigger/trigger.module	27 May 2009 17:24:29 -0000
@@ -92,7 +92,10 @@ function trigger_menu() {
     if (in_array($module, array('node', 'comment', 'user', 'system', 'taxonomy'))) {
       continue;
     }
-    $info = db_result(db_query("SELECT info FROM {system} WHERE name = '%s'", $module));
+    $info = db_select('system')
+      ->condition('name', $module)
+      ->execute()
+      ->fetchField();
     $info = unserialize($info);
     $nice_name = $info['name'];
     $items["admin/build/trigger/$module"] = array(
@@ -135,8 +138,11 @@ function trigger_access_check($module) {
  */
 function _trigger_get_hook_aids($hook, $op = '') {
   $aids = array();
-  $result = db_query("SELECT aa.aid, a.type FROM {trigger_assignments} aa LEFT JOIN {actions} a ON aa.aid = a.aid WHERE aa.hook = '%s' AND aa.op = '%s' ORDER BY weight", $hook, $op);
-  while ($action = db_fetch_object($result)) {
+  $result = db_query("SELECT aa.aid, a.type FROM {trigger_assignments} aa LEFT JOIN {actions} a ON aa.aid = a.aid WHERE aa.hook = :hook AND aa.op = :op ORDER BY weight", array(
+    ':hook' => $hook,
+    ':op' => $op,
+  ));
+  foreach ($result as $action) {
     $aids[$action->aid]['type'] = $action->type;
   }
   return $aids;
@@ -534,5 +540,7 @@ function trigger_options($type = 'all') 
  * Remove all trigger entries for the given action, when deleted.
  */
 function trigger_actions_delete($aid) {
-  db_query("DELETE FROM {trigger_assignments} WHERE aid = '%s'", $aid);
+  db_delete('trigger_assignments')
+    ->condition('aid', $aid)
+    ->execute();
 }
