Transaction Processing

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
David_USA
Posts: 8
Joined: Sun Jun 29, 2008 6:30 pm
Contact:

Transaction Processing

Post by David_USA » Sun Dec 06, 2009 1:00 am

I have been unable to find code to do Transaction Processing with a database.

Could someone forward the code and testing for proper implementation of a multi user database.

Thank you in advance for your help.

David J. Lamp

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: Transaction Processing

Post by ale870 » Mon Dec 07, 2009 9:38 am

Generally speaking, transactions are managed by Database self (there are specific SQL commands to do that).
I think you need to check SQL commands and documentation about you DB.
Which database are you using?
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

David_USA
Posts: 8
Joined: Sun Jun 29, 2008 6:30 pm
Contact:

Re: Transaction Processing

Post by David_USA » Wed Dec 09, 2009 6:48 am

the transaction will be processed through runrev scripting.

I believe runrev will use the same format of scripting for sqlite, mysql or odbc calls.

The reason for transaction processing is to be able to effect a muti step write to one or more tables in a database. It is important that the state of the database cannot be changed outside of the completion of the muti step process before a commit or rollback which will unlock the database.

I can not find any documentation that establishes the "Begin" to lock the database and prevent potential updating by two processes out of order.

I was hoping to find a sample with the "Begin" and "Commit or Rollback" rev script.

I would think many people have the need for this requirement.

Best Regards,

David J. Lamp

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Transaction Processing

Post by sturgis » Wed Dec 09, 2009 7:16 am

Look at this thread, theres an example there that might get you started. http://forums.runrev.com/phpBB2/viewtop ... =12&t=2892

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: Transaction Processing

Post by ale870 » Wed Dec 09, 2009 9:39 am

Hello,

I didn'0t work with DB using RunREv, but if you can send SQL commands, you could start / end transaction using SQL server DB commands.
Cheers!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Transaction Processing

Post by bangkok » Mon Sep 06, 2010 12:50 pm

nikjerry wrote:I have read this all of the stuff and I just would like to say that I also have the same problem with me as well as I also using the SQL as a DB, but up till I didn't get any of the solution regarding to it.
I don't really understand the issue.

we have one command that executes a SQL query :

revExecuteSQL dbID, dbSQL

So why don't you create the query like :
BEGIN;
INSERT INTO MYTABLE (MYCOLUMN) VALUES('1'),('2'),('3'),('4');
END;

or
BEGIN;
UPDATE MYTABLE SET MYCOLUMN=1 WHERE BLABLA=2
END;

If I remember correctly, It was working fine with SQLlite.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Transaction Processing

Post by Mark » Tue Sep 07, 2010 7:02 pm

Bangkok,

You were deceived. The previous message is spam.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Transaction Processing

Post by bangkok » Tue Sep 07, 2010 8:50 pm

Mark wrote: You were deceived. The previous message is spam.
Sorry Mark, could you elaborate ???? :shock:

What do you mean ?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Transaction Processing

Post by Mark » Tue Sep 07, 2010 9:09 pm

Bangkok,

First of all, it is really unwise to reply to spam. By replying, you drag the attention of other forum members to the spam message and there's a chance they make the spam attack successful by clicking on the link in the signature. This could even be extremely dangerous, because such a link can lead to a fishing site, which steals your credit card data, twitter password, facebook password, login data for your bank account, and even the login name and password of your computer. Replying to spam is a mistake.

You can recognise spam when you are thinking "I really don't understand the issue" and see a link in the message or the signature. In 99.999% of cases, this indicates spam.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Re: Transaction Processing

Post by chris9610 » Wed Sep 29, 2010 2:55 am

Here is a real example I use in an import.

Code: Select all

revExecuteSQL gConID, "begin;"
   repeat for each line aLine in tAllRtnums
      put aline into tdata
      put char 1 to 9 of tdata into trtnum
      put char 10 of tdata into toffcd
     
       -- Insert the data into the table
       revExecuteSQL gConID, tSQL, "trtnum", "toffcd"
       end repeat

revexecuteSQL gConID, "commit;"
Developing with Windows XP & Revolution 4.5

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Re: Transaction Processing

Post by Janschenkel » Thu Sep 30, 2010 11:45 am

You can also use the revCommitDatabase command at an appropriate spot, to commit all the INSERT, UPDATE and DELETE commands since the last commit.

Code: Select all

   repeat for each line aLine in tAllRtnums
      put aline into tdata
      put char 1 to 9 of tdata into trtnum
      put char 10 of tdata into toffcd
     
       -- Insert the data into the table
       revExecuteSQL gConID, tSQL, "trtnum", "toffcd"
   end repeat
   revCommitDatabase gConID
Similarly, you can use this strategy to rollback if there is an error in the middle of the transaction, using the revRollbackDatabase command.

Code: Select all

   local tError, tLineNumber
   repeat for each line aLine in tAllRtnums
      add 1 to tLineNumber
      put aline into tdata
      put char 1 to 9 of tdata into trtnum
      put char 10 of tdata into toffcd
      -- let's assume there is a business rule here concerning toffcd
      if toffcd is not among the items of "a,b,c,d,e,f" then
         put "Invalid toffcd:" && toffcd && "on line:" && tLineNumber into tError
         exit repeat
      end if
      -- Insert the data into the table
      revExecuteSQL gConID, tSQL, "trtnum", "toffcd"
   end repeat
   if tError is empty then
      revCommitDatabase gConID
   else
      revRollbackDatabase gConID
      answer error tError
   end if
The revCommitDatabase and revRollbackDatabase commands will simply be ignored on databases that do not support transactions (yes, there are still some DBMS engines that are not ACID compliant) so if you ever switch the DBMS, the commands will still work; whereas running your own

Code: Select all

revExecuteSql gConID, "begin;"
and

Code: Select all

revExecuteSql gConID, "commit;"
pairs may cause an error.

HTH,

Jan Schenkel.
Last edited by Janschenkel on Sun Oct 03, 2010 7:32 pm, edited 1 time in total.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Re: Transaction Processing

Post by chris9610 » Sat Oct 02, 2010 2:39 am

Jan:

That is a very good point. I just learned something new again.

Thanks again.
Developing with Windows XP & Revolution 4.5

Post Reply