changeset 3305:e074c641cb5e maint-0.7

fix RDBMS clear() so it resets all class itemid counters
author Richard Jones <richard@users.sourceforge.net>
date Mon, 02 May 2005 01:03:41 +0000
parents 1d024a7fb67e
children 5392c7e182b3
files CHANGES.txt roundup/backends/back_postgresql.py roundup/backends/back_sqlite.py roundup/backends/rdbms_common.py test/db_test_base.py
diffstat 5 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Mon May 02 00:36:04 2005 +0000
+++ b/CHANGES.txt	Mon May 02 01:03:41 2005 +0000
@@ -13,6 +13,7 @@
 - hack to fix some anydbm export problems (sf bug 1081454)
 - ignore AutoReply messages (sf patch 1085051)
 - fix ZRoundup syntax error (sf bug 1122335)
+- fix RDBMS clear() so it resets all class itemid counters
 
 
 2005-01-06 0.7.11
--- a/roundup/backends/back_postgresql.py	Mon May 02 00:36:04 2005 +0000
+++ b/roundup/backends/back_postgresql.py	Mon May 02 01:03:41 2005 +0000
@@ -211,7 +211,7 @@
     def newid(self, classname):
         sql = "select nextval('_%s_ids') from dual"%classname
         if __debug__:
-            print >>hyperdb.DEBUG, 'setid', (self, sql)
+            print >>hyperdb.DEBUG, 'newid', (self, sql)
         self.cursor.execute(sql)
         return self.cursor.fetchone()[0]
 
@@ -219,6 +219,7 @@
         sql = "select setval('_%s_ids', %s) from dual"%(classname, int(setid))
         if __debug__:
             print >>hyperdb.DEBUG, 'setid', (self, sql)
+        print 'setid', (self, sql)
         self.cursor.execute(sql)
 
 
--- a/roundup/backends/back_sqlite.py	Mon May 02 00:36:04 2005 +0000
+++ b/roundup/backends/back_sqlite.py	Mon May 02 01:03:41 2005 +0000
@@ -1,4 +1,4 @@
-# $Id: back_sqlite.py,v 1.27.2.3 2005-01-04 01:38:12 richard Exp $
+# $Id: back_sqlite.py,v 1.27.2.4 2005-05-02 01:03:40 richard Exp $
 '''Implements a backend for SQLite.
 
 See https://pysqlite.sourceforge.net/ for pysqlite info
@@ -320,7 +320,7 @@
     def setid(self, classname, setid):
         ''' Set the id counter: used during import of database
 
-        We add one to make it behave like the seqeunces in postgres.
+        We add one to make it behave like the sequences in postgres.
         '''
         sql = 'update ids set num=%s where name=%s'%(self.arg, self.arg)
         vals = (int(setid)+1, classname)
@@ -328,6 +328,18 @@
             print >>hyperdb.DEBUG, 'setid', (self, sql, vals)
         self.cursor.execute(sql, vals)
 
+    def clear(self):
+        '''Delete all database contents.
+
+        Note: I don't commit here, which is different behaviour to the
+              "nuke from orbit" behaviour in the dbs.
+        '''
+        rdbms_common.Database.clear(self)
+
+        # set the id counters to 0 (setid adds one) so we start at 1
+        for cn in self.classes.keys():
+            self.setid(cn, 0)
+
     def create_class(self, spec):
         rdbms_common.Database.create_class(self, spec)
         sql = 'insert into ids (name, num) values (%s, %s)'
--- a/roundup/backends/rdbms_common.py	Mon May 02 00:36:04 2005 +0000
+++ b/roundup/backends/rdbms_common.py	Mon May 02 01:03:41 2005 +0000
@@ -1,4 +1,4 @@
-# $Id: rdbms_common.py,v 1.98.2.30 2005-01-04 03:29:07 richard Exp $
+# $Id: rdbms_common.py,v 1.98.2.31 2005-05-02 01:03:40 richard Exp $
 ''' Relational database (SQL) backend common code.
 
 Basics:
@@ -694,7 +694,7 @@
             if __debug__:
                 print >>hyperdb.DEBUG, 'clear', (self, sql)
             self.cursor.execute(sql)
-        self.setid(cn, 1)
+            self.setid(cn, 1)
 
     #
     # Nodes
--- a/test/db_test_base.py	Mon May 02 00:36:04 2005 +0000
+++ b/test/db_test_base.py	Mon May 02 01:03:41 2005 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: db_test_base.py,v 1.27.2.15 2005-01-04 01:38:12 richard Exp $ 
+# $Id: db_test_base.py,v 1.27.2.16 2005-05-02 01:03:41 richard Exp $ 
 
 import unittest, os, shutil, errno, imp, sys, time, pprint
 
@@ -1381,7 +1381,7 @@
                 f.write(self.extra_config)
             finally:
                 f.close()
-        
+
         init.initialise(self.dirname, 'sekrit')
 
         # check we can load the package

Roundup Issue Tracker: http://roundup-tracker.org/