Skip to content

Commit

Permalink
Now using ADOdb standard transactions. Some day, we should switch to
Browse files Browse the repository at this point in the history
Smart Transactions (http://phplens.com/adodb/tutorial.smart.transactions.html)
as they autodetect errors and are nestable and easier to write
  • Loading branch information
stronk7 committed Sep 22, 2006
1 parent a17c57b commit 2a2905f
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions lib/dmllib.php
Expand Up @@ -86,34 +86,57 @@ function execute_sql($command, $feedback=true) {
return false;
}
}

/**
* on DBs that support it, switch to transaction mode and begin a transaction
* you'll need to ensure you call commit_sql() or your changes *will* be lost
* you'll need to ensure you call commit_sql() or your changes *will* be lost.
*
* Now using ADOdb standard transactions. Some day, we should switch to
* Smart Transactions (http://phplens.com/adodb/tutorial.smart.transactions.html)
* as they autodetect errors and are nestable and easier to write
*
* this is _very_ useful for massive updates
*/
function begin_sql() {
/// Completely general function - it just runs some SQL and reports success.

global $CFG;
if ($CFG->dbtype === 'postgres7') {
return execute_sql('BEGIN', false);
}
global $db;

$db->BeginTrans();

return true;
}

/**
* on DBs that support it, commit the transaction
*
* Now using ADOdb standard transactions. Some day, we should switch to
* Smart Transactions (http://phplens.com/adodb/tutorial.smart.transactions.html)
* as they autodetect errors and are nestable and easier to write
*/
function rollback_sql() {
/// Completely general function - it just runs some SQL and reports success.
function commit_sql() {

global $db;

$db->CommitTrans();

global $CFG;
if ($CFG->dbtype === 'postgres7') {
return execute_sql('ROLLBACK', false);
}
return true;
}

/**
* on DBs that support it, rollback the transaction
*
* Now using ADOdb standard transactions. Some day, we should switch to
* Smart Transactions (http://phplens.com/adodb/tutorial.smart.transactions.html)
* as they autodetect errors and are nestable and easier to write
*/
function rollback_sql() {

global $db;

$db->RollbackTrans();

return true;
}

/**
* returns db specific uppercase function
Expand All @@ -131,18 +154,6 @@ function db_lowercase() {
return "lower";
}

/**
* on DBs that support it, commit the transaction
*/
function commit_sql() {
/// Completely general function - it just runs some SQL and reports success.

global $CFG;
if ($CFG->dbtype === 'postgres7') {
return execute_sql('COMMIT', false);
}
return true;
}

/**
* Run an arbitrary sequence of semicolon-delimited SQL commands
Expand Down

0 comments on commit 2a2905f

Please sign in to comment.