@@ -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+
496520class 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
0 commit comments