From 1ed5abc877dbecdb632783e4617d6b435c88a487 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Wed, 17 Nov 2004 05:31:21 +0000 Subject: [PATCH] Merge from MOODLE_14_STABLE: moodle--eduforge--1.3.3--patch-207(partial) + moodle--eduforge--1.3.3--patch-408 - added begin_sql() and commit_sql() (martinlanghoff) --- course/category.php | 2 ++ lib/datalib.php | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/course/category.php b/course/category.php index 4f1c13b006..70f93fa119 100644 --- a/course/category.php +++ b/course/category.php @@ -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(); } } diff --git a/lib/datalib.php b/lib/datalib.php index 70d96479f2..10951a6c54 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -58,6 +58,32 @@ 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 +* 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 -- 2.39.5