Link | inline_transaction |
Author | Jason Huck |
Category | Utility |
Version | 8.x |
License | http://opensource.org/licenses/artistic-license.php |
Posted | 26 Oct 2005 |
Updated | 16 Jan 2006 |
More by this author... |
Executes the supplied SQL queries as a single transaction. Accepts an array of SQL queries to execute and a pair array containing the connection parameters for the inlines. If any single SQL query fails, the entire transaction will be rolled back.
Requires MySQL 4.x or higher and tables that support transactions, i.e., InnoDB.
var('dbConn') = array( -username='foo', -password='bar', -database='test', -maxrecords='all' ); var('sql' = array); $sql->insert('INSERT INTO t1 (col1, col2) VALUES (1,2);'); $sql->insert('SET @newID = LAST_INSERT_ID();'); $sql->insert('INSERT INTO t2 (col3, col4) VALUES (@newID, 3);'); inline_transaction( -connection=$dbConn, -sql=$sql );
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_tag( 'transaction', -namespace='inline_', -required='connection', -type='array', -required='sql', -type='array', -priority='replace', -description=' Executes the supplied SQL queries as a single transaction. Requires MySQL 4.x. and tables that support transactions, i.e., InnoDB. ' ); local('error' = false); inline( #connection, -sql='START TRANSACTION;' ); iterate(#sql, local('qry')); inline( -sql=#qry); if(error_code != 0); inline( -sql='ROLLBACK;');/inline; #error = true; loop_abort; /if; /inline; /iterate; if(!#error); inline( -sql='COMMIT;');/inline; else; fail(-1, 'Transaction failed.'); /if; /inline; /define_tag;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft