Index: userpoints.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/userpoints.module,v
retrieving revision 1.67.2.57
diff -u -p -r1.67.2.57 userpoints.module
--- userpoints.module	30 Apr 2010 15:55:09 -0000	1.67.2.57
+++ userpoints.module	30 Apr 2010 17:28:52 -0000
@@ -802,28 +802,20 @@ function _userpoints_update_cache(&$para
   }
 
   // insert or update the userpoints caching table with the user's current points
+  $record_params = array(
+    'points' => $current_points,
+    'max_points' => $max_points,
+    'last_update' => time(),
+    'uid' => $params['uid'],
+    'tid' => $params['tid'],
+  );
+  $update = array();
+  
   if (_userpoints_user_exists($params['uid'], $params['tid'])) {
-    db_query("UPDATE {userpoints}
-              SET points = %d, max_points = %d, last_update = %d 
-              WHERE uid = %d AND tid = %d",
-              $current_points,
-              $max_points,
-              time(),
-              $params['uid'],
-              $params['tid']
-            );
-  }
-  else {
-    $result = db_query("INSERT INTO {userpoints}
-     (uid, points, max_points, last_update, tid)
-      VALUES (%d, %d, %d, %d, %d )",
-      $params['uid'],
-      $current_points,
-      $max_points,
-      time(),
-      $params['tid']
-      );
+    $update = array('uid', 'tid');
   }
+  
+  drupal_write_record('userpoints', $record_params, $update);
   unset($params);
 }
 
Index: tests/userpoints_api.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/userpoints/tests/Attic/userpoints_api.test,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 userpoints_api.test
--- tests/userpoints_api.test	30 Apr 2010 15:55:09 -0000	1.1.2.10
+++ tests/userpoints_api.test	30 Apr 2010 17:28:52 -0000
@@ -48,8 +48,9 @@ class UserpointsTestCase extends DrupalW
 
     //Check the database to ensure the point were properly saved
     $sql = "SELECT points from {userpoints_txn} WHERE uid = %d AND points = %d";
+    $this->assertNotNull($points, t('Sanity check, Points is assigned something !points', array('!points' => $points)));
     $db_points = (int) db_result(db_query($sql, $user->uid, $points));
-    $this->assertTrue($db_points === $points, t('Successfully verified points in the txn table'));
+    $this->assertTrue($db_points === $points, t('Successfully verified points in the txn table !dbpoints !points', array('!dbpoints' => $db_points, '!points' => $points)));
 
     //Check that the transaction table and the summary table match
     $sql = "SELECT SUM(points) FROM {userpoints_txn} WHERE uid = %d";
