From: http://www.firstsql.com/tutor5.htm
"In SQL92, there is no BEGIN TRANSACTION statement. A transaction begins with the execution of a SQL-Data statement when there is no current transaction. All subsequent SQL-Data statements until COMMIT or ROLLBACK become part of the transaction. Execution of a COMMIT Statement or ROLLBACK Statement completes the current transaction. A subsequent SQL-Data statement starts a new transaction." On Dec 29, 9:31 pm, toomim <[email protected]> wrote: > Thank you. So you are saying that each request basically does: > > sql BEGIN > ... > call appropriate controller function > ... > sql COMMIT if success > > What I do not understand is: > > 1) When called from cron, there is no automatic begin transaction, > so where does the begin come from? > 2) When my controller function calls commit, how do I get another > begin to make a new transaction? > > On Dec 29, 7:18 pm, mdipierro <[email protected]> wrote: > > > A transaction starts when a request arrive and it is committed when a > > request returns. If there is an error that it not caught the > > transaction is rolledback. > > > You can insert db.commit() (and db.rollback()) everywhere to break the > > transaction in smaller parts. > > > Massimo > > > On Dec 29, 8:54 pm, toomim <[email protected]> wrote: > > > > Mossimo, unfortunately this proposal does not solve the multi- > > > threading problem. > > > > Can you tell me what the semantics of the "implicit begin" is? The > > > problem is that I do not know where begin is inserted. I thought it > > > happened at the beginning of every controller function call. That > > > would make it impossible to do multiple transactions (with multiple > > > begins) inside a single function. Is that assumption incorrect? > > > > On Dec 29, 1:14 pm, mdipierro <[email protected]> wrote: > > > > > Attention. There is no db.begin(). it is implicit. You can commit > > > > automatically but why not: > > > > > while queue is not empty: > > > > task = db(~status.belongs(('done','failed'))).select(limitby= > > > > (0,1))[0] > > > > success = do_long_thing(task) > > > > if success: > > > > task.update(status = 'done') > > > > else: > > > > task.update(status = 'failed') > > > > > On Dec 29, 2:10 pm, toomim <[email protected]> wrote: > > > > > > Very clever, thank you! If it crashes, these items will be lost > > > > > though. Is there a way to use transactions, to pull a single item at > > > > > a time from the table, process and delete it, within a single > > > > > transaction? Something like this: > > > > > > while queue is not empty: > > > > > db.begin() > > > > > task = db(status != 'done').select(limitby=(0,1))[0] > > > > > task.update(status = 'done') > > > > > success = do_long_thing(task) > > > > > if success: > > > > > db.commit() > > > > > else: > > > > > db.rollback() > > > > > > This way if the code fires an exception, or the computer crashes, the > > > > > database will roll back to its prior state automatically. The problem > > > > > is there is no begin statement in web2py. All begin statements seem > > > > > to be automatic. Is it possible to do one manually? Can I turn off > > > > > the automatic one? > > > > > > On Dec 29, 12:04 am, Thadeus Burgess <[email protected]> wrote: > > > > > > > Ah yes, so back to my original thought > > > > > > > db(status == 'pending').update(status = 'pending-' + request.now) > > > > > > > for db(status == 'pending-' + request.now).select(): > > > > > > task.update_record(status = 'processing-' + request.now > > > > > > success = do_the_long_thing(task) > > > > > > fail > > > > > > if success: > > > > > > task.update_record(status = 'done') > > > > > > > -Thadeus > > > > > > > On Tue, Dec 29, 2009 at 1:52 AM, toomim <[email protected]> wrote: > > > > > > > sk.update_record(status == 'proce > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.

