Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-08-2012, 01:07 AM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
BEGIN and COMMIT

Should BEGIN and COMMIT only be used when lots of data is written to a table or should it be used whenever a query is sent to the database? I'm not fully understanding it. If someone could give me some examples and explain when and when not to use it that would be awesome.

edit: I now understand that every time a you do a query that it begins a transaction and commits it automatically however I still do not understand the proper use of BEGIN and COMMIT if that's the case. The only thing I can think of is if you are adding a bunch of rows to a table and you would want to keep the transaction open so it doesnt have to BEGIN and COMMIT over and over. I still lack full understanding of it.
Reply With Quote
  #2  
Old 03-08-2012, 01:53 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
My understanding of it is:

BEGIN;
.. a bunch of statements, that should all fail if one doesn't go through ..
COMMIT;

After reading: http://sqlite.org/lang_transaction.html

It leads me to believe if u pass a formatted SQL query that contains 10 SQL statements it will automatically BEGIN and COMMIT for you. However if you do something like..

PHP Code:
sql("BEGIN");
sql("UPDATE stuff");
sql("UPDATE stuff");
sql("COMMIT"); 
You might have to use it, really depends how it's implemented behind-the-scenes.
__________________
Quote:

Last edited by fowlplay4; 03-08-2012 at 02:08 AM..
Reply With Quote
  #3  
Old 03-08-2012, 04:27 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by fowlplay4 View Post
My understanding of it is:

BEGIN;
.. a bunch of statements, that should all fail if one doesn't go through ..
COMMIT;
That's also my understanding of it. Note also that you can get greatly improved write speeds with INSERT/UPDATE if executing many queries if you do them in a transaction.
__________________
Reply With Quote
  #4  
Old 03-08-2012, 04:19 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
I never use begin/commits, it just adds more hassle. What can speed up stuff is to do several inserts with the same query. For optimization it's good to not store data which you don't need to store, e.g. don't store if the value is empty anyway and you don't have previous entries for this key (I've seen bad examples on several bigger servers), and you need to add indices to make the lookup fast. One thing that is often speeding up queries is to only update the columns which you want to update, because updating a key is much much slower because it needs to update the index too.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.