]> git.mjollnir.org Git - moodle.git/commitdiff
Added support to SQL generation of install INSERTs
authorstronk7 <stronk7>
Sun, 27 Aug 2006 21:59:04 +0000 (21:59 +0000)
committerstronk7 <stronk7>
Sun, 27 Aug 2006 21:59:04 +0000 (21:59 +0000)
lib/xmldb/classes/XMLDBStatement.class.php

index 7592803a79d861738f0e367048030283ec2c3795..4a254d441b0fddc658a25418dbd3c183a882d236 100644 (file)
@@ -348,7 +348,7 @@ class XMLDBStatement extends XMLDBObject {
         $values = array();
 
     /// Get second part from the sentence (after VALUES)
-        preg_match('/VALUES\s+\((.*)\)$/is', $sentence, $matches);
+        preg_match('/VALUES\s*\((.*)\)$/is', $sentence, $matches);
         if (isset($matches[1])) {
             $part = $matches[1];
         /// Convert the comma separated string to an array
@@ -360,6 +360,55 @@ class XMLDBStatement extends XMLDBObject {
 
         return $values;
     }
+
+    /**
+     * This function will return the code needed to execute a collection
+     * of sentences present inside one statement for the specified BD
+     * and prefix. 
+     * For now it only supports INSERT statements
+     */
+    function getExecuteStatementSQL ($dbtype, $prefix, $statement_end=true) {
+
+        $results = array();
+
+    /// Based on statement type
+        switch ($this->type) {
+            case XMLDB_STATEMENT_INSERT:
+                $results = $this->getExecuteInsertSQL($dbtype, $prefix, $statement_end);
+                break;
+            case XMLDB_STATEMENT_UPDATE:
+                break;
+            case XMLDB_STATEMENT_DELETE:
+                break;
+            case XMLDB_STATEMENT_CUSTOM:
+                break;
+        }
+
+        if ($statement_end) {
+            $results = $generator->getEndedStatements($results);
+        }
+
+        return $results;
+    }
+
+    /**
+     * This function will return the code needed to execute a collection
+     * of insert sentences present inside the statement for the specified BD
+     * and prefix. Just one simple wrapper over generators.
+     */
+    function getExecuteInsertSQL ($dbtype, $prefix, $statement_end=true) {
+
+        $results = array();
+
+        $classname = 'XMLDB' . $dbtype;
+        $generator = new $classname();
+        $generator->setPrefix($prefix);
+
+        $results = $generator->getExecuteInsertSQL($this);
+
+        return $results;
+    }
+
 }
 
 ?>