Testing if db insert was successful

45 views
Skip to first unread message

Jordan Ladora

unread,
Aug 10, 2013, 11:07:17 AM8/10/13
to web...@googlegroups.com
Hi,

I'm unable to figure out how to check when a simple db insert() was successful. In my code below, regardless of whether the db insert is successful or not, the code after 'if new_record:' always executes..


new_record = db.abc.insert(a='this', b='that', c='theotherthing')

    if new_record:



How can I code "if db insert was successful:" ?

Thanks,
-J

Jordan Ladora

unread,
Aug 10, 2013, 1:05:20 PM8/10/13
to web...@googlegroups.com
Oops my bad - unrelated problem caused this - please disregard.

o:

Thanks.

Massimo Di Pierro

unread,
Aug 10, 2013, 4:39:47 PM8/10/13
to web...@googlegroups.com
If it does not raise an exception it is successfull. The issue is that unless you are in a controller action you have to db.commit() or the insert will be un-committed.

Jordan Ladora

unread,
Aug 11, 2013, 12:25:49 PM8/11/13
to web...@googlegroups.com
I see, thanks!


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/QABiqKdKmlg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages