@@ -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 )
@@ -280,10 +286,13 @@ def add_new_columns_v2(self):
280286
281287 # Intervals store the seconds value too
282288 if isinstance (prop , Interval ):
289+ if first :
290+ cols .append ('__' + name + '_int__' )
283291 if v is not None :
284292 l .append (v .as_seconds ())
285293 else :
286294 l .append (e )
295+ first = False
287296
288297 self .drop_class_table_indexes (cn , old_spec [0 ])
289298
@@ -294,8 +303,9 @@ def add_new_columns_v2(self):
294303 self .create_class_table (klass )
295304
296305 # do the insert of the old data
297- args = ',' .join ([self .arg for x in fetch ])
298- sql = 'insert into _%s (%s) values (%s)' % (cn , fetchcols , args )
306+ args = ',' .join ([self .arg for x in cols ])
307+ cols = ',' .join (cols )
308+ sql = 'insert into _%s (%s) values (%s)' % (cn , cols , args )
299309 if __debug__ :
300310 print >> hyperdb .DEBUG , 'migration' , (self , sql )
301311 for entry in olddata :
@@ -491,6 +501,20 @@ def create_class(self, spec):
491501 print >> hyperdb .DEBUG , 'create_class' , (self , sql , vals )
492502 self .cursor .execute (sql , vals )
493503
504+ def sql_commit (self ):
505+ ''' Actually commit to the database.
506+ '''
507+ if __debug__ :
508+ print >> hyperdb .DEBUG , '+++ commit database connection +++'
509+ self .conn .commit ()
510+
511+ # open a new cursor for subsequent work
512+ self .cursor = self .conn .cursor ()
513+
514+ # make sure we're in a new transaction and not autocommitting
515+ self .cursor .execute ("SET AUTOCOMMIT=OFF" )
516+ self .cursor .execute ("START TRANSACTION" )
517+
494518class MysqlClass :
495519 # we're overriding this method for ONE missing bit of functionality.
496520 # look for "I can't believe it's not a toy RDBMS" below
0 commit comments