Skip to content

Commit 3040313

Browse files
author
Richard Jones
committed
fixed some more mysql 0.6->0.7 upgrade bugs [SF#950410]
1 parent acb8ef2 commit 3040313

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Fixed:
1717
- fixed lookup of "missing" Link values for new props in anydbm backend
1818
- allow list of values for id, Number and Boolean filtering in anydbm
1919
backend
20+
- fixed some more mysql 0.6->0.7 upgrade bugs (sf bug 950410)
2021

2122

2223
2004-06-10 0.7.4

roundup/backends/back_mysql.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def sql_open_connection(self):
140140
except MySQLdb.OperationalError, message:
141141
raise DatabaseError, message
142142
cursor = conn.cursor()
143-
cursor.execute("SET AUTOCOMMIT=0")
144-
cursor.execute("BEGIN")
143+
cursor.execute("SET AUTOCOMMIT=OFF")
144+
cursor.execute("START TRANSACTION")
145145
return (conn, cursor)
146146

147147
def open_connection(self):
@@ -251,6 +251,8 @@ def add_new_columns_v2(self):
251251
# unserialise the old data
252252
olddata = []
253253
propnames = propnames + ['id', '__retired__']
254+
cols = []
255+
first = True
254256
for entry in self.cursor.fetchall():
255257
l = []
256258
olddata.append(l)
@@ -259,8 +261,12 @@ def add_new_columns_v2(self):
259261
v = entry[i]
260262

261263
if name in ('id', '__retired__'):
264+
if first:
265+
cols.append(name)
262266
l.append(int(v))
263267
continue
268+
if first:
269+
cols.append('_' + name)
264270
prop = properties[name]
265271
if isinstance(prop, Date) and v is not None:
266272
v = date.Date(v)
@@ -282,10 +288,13 @@ def add_new_columns_v2(self):
282288

283289
# Intervals store the seconds value too
284290
if isinstance(prop, Interval):
291+
if first:
292+
cols.append('__' + name + '_int__')
285293
if v is not None:
286294
l.append(v.as_seconds())
287295
else:
288296
l.append(e)
297+
first = False
289298

290299
self.drop_class_table_indexes(cn, old_spec[0])
291300

@@ -296,8 +305,9 @@ def add_new_columns_v2(self):
296305
self.create_class_table(klass)
297306

298307
# do the insert of the old data
299-
args = ','.join([self.arg for x in fetch])
300-
sql = 'insert into _%s (%s) values (%s)'%(cn, fetchcols, args)
308+
args = ','.join([self.arg for x in cols])
309+
cols = ','.join(cols)
310+
sql = 'insert into _%s (%s) values (%s)'%(cn, cols, args)
301311
if __debug__:
302312
print >>hyperdb.DEBUG, 'migration', (self, sql)
303313
for entry in olddata:
@@ -493,6 +503,20 @@ def create_class(self, spec):
493503
print >>hyperdb.DEBUG, 'create_class', (self, sql, vals)
494504
self.cursor.execute(sql, vals)
495505

506+
def sql_commit(self):
507+
''' Actually commit to the database.
508+
'''
509+
if __debug__:
510+
print >>hyperdb.DEBUG, '+++ commit database connection +++'
511+
self.conn.commit()
512+
513+
# open a new cursor for subsequent work
514+
self.cursor = self.conn.cursor()
515+
516+
# make sure we're in a new transaction and not autocommitting
517+
self.cursor.execute("SET AUTOCOMMIT=OFF")
518+
self.cursor.execute("START TRANSACTION")
519+
496520
class MysqlClass:
497521
# we're overriding this method for ONE missing bit of functionality.
498522
# look for "I can't believe it's not a toy RDBMS" below

roundup/backends/rdbms_common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.108 2004-06-09 09:49:27 richard Exp $
1+
# $Id: rdbms_common.py,v 1.109 2004-06-14 03:36:11 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -202,6 +202,8 @@ def upgrade_db(self):
202202
return 0
203203

204204
if version < 2:
205+
if __debug__:
206+
print >>hyperdb.DEBUG, 'upgrade to version 2'
205207
# change the schema structure
206208
self.database_schema = {'tables': self.database_schema}
207209

@@ -214,6 +216,8 @@ def upgrade_db(self):
214216
self.create_version_2_tables()
215217

216218
if version < 3:
219+
if __debug__:
220+
print >>hyperdb.DEBUG, 'upgrade to version 3'
217221
self.fix_version_2_tables()
218222

219223
self.database_schema['version'] = self.current_db_version

0 commit comments

Comments
 (0)