Solving two small database-related bugs
diff --git a/include/event-scheduler.h b/include/event-scheduler.h
index 4eb6d6c..5f2c7b2 100644
--- a/include/event-scheduler.h
+++ b/include/event-scheduler.h
@@ -246,8 +246,8 @@
   boost::uniform_real<> m_dist;
   boost::variate_generator<RNG_TYPE &, boost::uniform_real<> > m_random;
   Direction m_direction;
-  double m_interval;
   double m_percent;
+  double m_interval;
 
 };
 #endif // EVENT_SCHEDULER_H
diff --git a/src/db-helper.cc b/src/db-helper.cc
index 0e08612..01462c6 100644
--- a/src/db-helper.cc
+++ b/src/db-helper.cc
@@ -239,6 +239,8 @@
   const void *name    = sqlite3_value_blob  (argv[0]);
   sqlite3_int64 seqno = sqlite3_value_int64 (argv[1]);
 
+  std::cout << context << ": nameBytes " << nameBytes << " seqno " << seqno << std::endl;
+  
   EVP_DigestUpdate (*hash_context, name, nameBytes);
   EVP_DigestUpdate (*hash_context, &seqno, sizeof(sqlite3_int64));
 }
diff --git a/src/sync-log.cc b/src/sync-log.cc
index d5a8750..9911416 100644
--- a/src/sync-log.cc
+++ b/src/sync-log.cc
@@ -100,12 +100,12 @@
   int res = sqlite3_exec (m_db, "BEGIN TRANSACTION;", 0,0,0);
 
   res += sqlite3_exec (m_db, "\
-INSERT INTO SyncLog                                     \
-    (state_hash, last_update)                           \
-    SELECT                                              \
-       hash(device_name, seq_no), datetime('now')       \
-    FROM SyncNodes                                      \
-    ORDER BY device_name;                               \
+INSERT INTO SyncLog                                                \
+    (state_hash, last_update)                                      \
+    SELECT                                                         \
+       hash(device_name, seq_no), datetime('now')                  \
+    FROM (SELECT * FROM SyncNodes                                  \
+              ORDER BY device_name);                               \
 ", 0,0,0);
 
   if (res != SQLITE_OK)
@@ -263,6 +263,11 @@
   return locator;
 }
 
+// void xTrace (void*, const char* q)
+// {
+//   cout << q << endl;
+// }
+
 void
 SyncLog::UpdateLocator(const Name &deviceName, const Name &locator)
 {
@@ -270,8 +275,8 @@
   sqlite3_prepare_v2 (m_db, "UPDATE SyncNodes SET last_known_locator=? WHERE device_name=?;", -1, &stmt, 0);
   Ccnx::CcnxCharbufPtr nameBuf = deviceName;
   Ccnx::CcnxCharbufPtr locatorBuf = locator;
-  sqlite3_bind_blob (stmt, 1, nameBuf->buf(), nameBuf->length(), SQLITE_STATIC);
-  sqlite3_bind_blob (stmt, 2, locatorBuf->buf(), locatorBuf->length(), SQLITE_STATIC);
+  sqlite3_bind_blob (stmt, 1, locatorBuf->buf(), locatorBuf->length(), SQLITE_STATIC);
+  sqlite3_bind_blob (stmt, 2, nameBuf->buf(), nameBuf->length(),       SQLITE_STATIC);
   int res = sqlite3_step (stmt);
 
   if (res != SQLITE_OK && res != SQLITE_DONE)
@@ -288,11 +293,6 @@
   return FindStateDifferences (*Hash::FromString (oldHash), *Hash::FromString (newHash));
 }
 
-// void xTrace (void*, const char* q)
-// {
-//   cout << q << endl;
-// }
-
 SyncStateMsgPtr
 SyncLog::FindStateDifferences (const Hash &oldHash, const Hash &newHash)
 {
@@ -362,14 +362,16 @@
         state->set_locator (reinterpret_cast<const char*> (sqlite3_column_blob (stmt, 1)), sqlite3_column_bytes (stmt, 1));
       }
 
-      sqlite3_int64 newSeqNo = sqlite3_column_int64 (stmt, 3);
-      if (newSeqNo >= 0)
+      if (sqlite3_column_type (stmt, 3) == SQLITE_NULL)
         {
+        state->set_type (SyncState::DELETE);
+        }
+      else
+        {
+          sqlite3_int64 newSeqNo = sqlite3_column_int64 (stmt, 3);
           state->set_type (SyncState::UPDATE);
           state->set_seq (newSeqNo);
         }
-      else
-        state->set_type (SyncState::DELETE);
 
       // std::cout << sqlite3_column_text (stmt, 0) <<
       //   ": from "  << sqlite3_column_int64 (stmt, 1) <<