]> git.mjollnir.org Git - moodle.git/commitdiff
New function execute_sql_arr() to execute arrays of
authorstronk7 <stronk7>
Sat, 2 Sep 2006 23:46:43 +0000 (23:46 +0000)
committerstronk7 <stronk7>
Sat, 2 Sep 2006 23:46:43 +0000 (23:46 +0000)
statements, Used by ddllib.php mainly.

lib/dmllib.php

index 8c1dd99fa026bf5da4524901da943e295c993f35..e647bd2331084640a7364213eaaab427152b2925 100644 (file)
@@ -1348,6 +1348,32 @@ function column_type($table, $column) {
     return $rs->MetaType($field->type);
 }
 
+/**
+ * This function will execute an array of SQL commands, returning
+ * true/false if any error is found and stopping/continue as desired.
+ * It's widely used by all the ddllib.php functions
+ *
+ * @param array sqlarr array of sql statements to execute
+ * @param boolean continue to specify if must continue on error (true) or stop (false
+ * @param boolean true if everything was ok, false if some error was found
+ */
+function execute_sql_arr($sqlarr, $continue=true) {
+
+    if (!is_array($sqlarr)) {
+        return false;
+    }
+
+    $status = true;
+    foreach($sqlarr as $sql) {
+        if (!execute_sql($sql)) {
+            $status = false;
+            if (!$continue) {
+                break;
+            }
+        }
+    }
+    return $status;
+}
 
 /**
  * This function, called from setup.php includes all the configuration