Skip to content

Commit eb81a99

Browse files
author
Richard Jones
committed
fix RDBMS clear() so it resets all class itemid counters
1 parent 200d233 commit eb81a99

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Fixed:
1313
- hack to fix some anydbm export problems (sf bug 1081454)
1414
- ignore AutoReply messages (sf patch 1085051)
1515
- fix ZRoundup syntax error (sf bug 1122335)
16+
- fix RDBMS clear() so it resets all class itemid counters
1617

1718

1819
2005-01-06 0.7.11

roundup/backends/back_postgresql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,15 @@ def drop_class_table(self, cn):
211211
def newid(self, classname):
212212
sql = "select nextval('_%s_ids') from dual"%classname
213213
if __debug__:
214-
print >>hyperdb.DEBUG, 'setid', (self, sql)
214+
print >>hyperdb.DEBUG, 'newid', (self, sql)
215215
self.cursor.execute(sql)
216216
return self.cursor.fetchone()[0]
217217

218218
def setid(self, classname, setid):
219219
sql = "select setval('_%s_ids', %s) from dual"%(classname, int(setid))
220220
if __debug__:
221221
print >>hyperdb.DEBUG, 'setid', (self, sql)
222+
print 'setid', (self, sql)
222223
self.cursor.execute(sql)
223224

224225

roundup/backends/back_sqlite.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_sqlite.py,v 1.27.2.3 2005-01-04 01:38:12 richard Exp $
1+
# $Id: back_sqlite.py,v 1.27.2.4 2005-05-02 01:03:40 richard Exp $
22
'''Implements a backend for SQLite.
33
44
See https://pysqlite.sourceforge.net/ for pysqlite info
@@ -320,14 +320,26 @@ def newid(self, classname):
320320
def setid(self, classname, setid):
321321
''' Set the id counter: used during import of database
322322
323-
We add one to make it behave like the seqeunces in postgres.
323+
We add one to make it behave like the sequences in postgres.
324324
'''
325325
sql = 'update ids set num=%s where name=%s'%(self.arg, self.arg)
326326
vals = (int(setid)+1, classname)
327327
if __debug__:
328328
print >>hyperdb.DEBUG, 'setid', (self, sql, vals)
329329
self.cursor.execute(sql, vals)
330330

331+
def clear(self):
332+
'''Delete all database contents.
333+
334+
Note: I don't commit here, which is different behaviour to the
335+
"nuke from orbit" behaviour in the dbs.
336+
'''
337+
rdbms_common.Database.clear(self)
338+
339+
# set the id counters to 0 (setid adds one) so we start at 1
340+
for cn in self.classes.keys():
341+
self.setid(cn, 0)
342+
331343
def create_class(self, spec):
332344
rdbms_common.Database.create_class(self, spec)
333345
sql = 'insert into ids (name, num) values (%s, %s)'

roundup/backends/rdbms_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.98.2.30 2005-01-04 03:29:07 richard Exp $
1+
# $Id: rdbms_common.py,v 1.98.2.31 2005-05-02 01:03:40 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -694,7 +694,7 @@ def clear(self):
694694
if __debug__:
695695
print >>hyperdb.DEBUG, 'clear', (self, sql)
696696
self.cursor.execute(sql)
697-
self.setid(cn, 1)
697+
self.setid(cn, 1)
698698

699699
#
700700
# Nodes

test/db_test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.27.2.15 2005-01-04 01:38:12 richard Exp $
18+
# $Id: db_test_base.py,v 1.27.2.16 2005-05-02 01:03:41 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -1381,7 +1381,7 @@ def testCreation(self):
13811381
f.write(self.extra_config)
13821382
finally:
13831383
f.close()
1384-
1384+
13851385
init.initialise(self.dirname, 'sekrit')
13861386

13871387
# check we can load the package

0 commit comments

Comments
 (0)