Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Oct 20, 2018 10:20 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Committing an SQL insert or update
PostPosted: Sun Apr 14, 2013 6:39 pm 
Offline

Joined: Fri Jun 02, 2006 1:43 pm
Posts: 209
Location: Santa Ynez, CA
Two questions:
1. I have noticed that when I use a prepared statement for RealSQLDatabase, I don't have to commit the transaction. In fact, if I do, I get an error message that there is nothing to commit. But if I execute a straight sql insert or update, I have to commit it or the changes are not stored. The database autocommit property is false in both cases. Is this a bug that may break my code if fixed in a future update? or just the way it works?

2. My app has a possibility that two users could try to write to the database at the same time so I check for errors after each write and loop back and try again if there is an error. Do I need to loop back after both the insert and the commit or is just one OK? In other words, is the database locked error raised on the insert or on the commit?


Top
 Profile  
Reply with quote  
 Post subject: Re: Committing an SQL insert or update
PostPosted: Mon Apr 15, 2013 6:33 am 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
You should get into the habit of doing all modifications from inside a transaction. Don't rely on auto commit. Begin a transaction, do your work, then commit. If you run into an error, rollback and stop processing.

The problem with auto commit - which you said is false anyway, good - is that we have no idea how many future commands are coming. So a transaction is started and committed for every command. For a single command, this is fine. But for multiple commands, this is very expensive. The begin/commit cycle is a powerful design, but costs extra CPU cycles. Commuting more frequently than necessary will make the commands slower.

What you're probably seeing is the lack of a "BEGIN TRANSACTION" statement. Without it, there is nothing to commit.

As for issue #2, I'm not sure I can advise. SQLite (and thus REALSQLDatabase) was not designed to be used by multiple users.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Committing an SQL insert or update
PostPosted: Mon Apr 15, 2013 10:13 am 
Offline

Joined: Fri Jun 02, 2006 1:43 pm
Posts: 209
Location: Santa Ynez, CA
Thank you for your answer Thom, but you did not really address the issue. Autocommit is true for prepared statements and false for normal (not prepared statements). This seems strange to me and I am asking if it is supposed to be this way? If it is, I will remove the db.commit statements. If not, I will leave them (without error checking) so the program doesn't break in the future if it get changed.


Top
 Profile  
Reply with quote  
 Post subject: Re: Committing an SQL insert or update
PostPosted: Mon Apr 15, 2013 10:15 am 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
What I suggested towards the end of my message is to be sure you insert matching "BEGIN TRANSACTION" statements, and turn autocommit off.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group