Permalink
Browse files

moodle--eduforge--1.3.3--patch-207(partial) + moodle--eduforge--1.3.3…

…--patch-408 - added begin_sql() and commit_sql() (martinlanghoff)
  • Loading branch information...
1 parent dcb043d commit ad16b64f1afc6de86d69c610b3120ec46a02ec48 mjollnir_ committed Nov 17, 2004
Showing with 28 additions and 0 deletions.
  1. +2 −0 course/category.php
  2. +26 −0 lib/datalib.php
View
@@ -196,6 +196,7 @@
}
if ($swapcourse and $movecourse) { // Renumber everything for robustness
$count=0;
+ begin_sql();
foreach ($courses as $course) {
$count++;
if ($course->id == $swapcourse->id) {
@@ -207,6 +208,7 @@
notify("Could not update that course!");
}
}
+ commit_sql();
}
}
View
@@ -36,6 +36,32 @@ function execute_sql($command, $feedback=true) {
}
}
/**
+* 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
+* 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);
+ }
+ return true;
+}
+/**
+* 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
*
* Assumes that the input text (file or string) consists of

0 comments on commit ad16b64

Please sign in to comment.