Index: type_local_nids.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/type_local_nids/type_local_nids.module,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 type_local_nids.module
--- type_local_nids.module	19 Jan 2010 00:58:59 -0000	1.1.2.9
+++ type_local_nids.module	23 Jul 2010 05:45:14 -0000
@@ -31,13 +31,15 @@ function _type_local_nids_get_lnid(&$nod
 
   if ($node->lnid) {
   
-    db_query("
-      UPDATE {node_lnid_next}
-      SET next_lnid = next_lnid + 1
-      WHERE type = '%s'
-    ",
-      $node->type
-    );
+    if (isset($node->nid)) {
+      db_query("
+        UPDATE {node_lnid_next}
+        SET next_lnid = next_lnid + 1
+        WHERE type = '%s'
+      ",
+        $node->type
+      );
+    }
   }
   else {
     $node_lnid_next = array(
@@ -50,7 +52,9 @@ function _type_local_nids_get_lnid(&$nod
     $node->lnid = 1;
   }
 
-  drupal_write_record('node_lnid', $node);
+  if (isset($node->nid)) {
+    drupal_write_record('node_lnid', $node);
+  }
 }
 
 
@@ -124,6 +128,9 @@ function type_local_nids_token_values($t
 
   if ($type == 'node') {
   
+    if (!isset($object->lnid)) {
+      _type_local_nids_get_lnid($object);
+    }
     $tokens['lnid'] = $object->lnid;
     return $tokens;
   }
