]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed one bug on Oracle produced when we were inserting
authorstronk7 <stronk7>
Mon, 30 Oct 2006 22:59:49 +0000 (22:59 +0000)
committerstronk7 <stronk7>
Mon, 30 Oct 2006 22:59:49 +0000 (22:59 +0000)
records with returnid disabled and containing LOBs

Merged from MOODLE_17_STABLE

lib/dmllib.php

index 484b576ac20a7b7b41651d41e6586f0be9e5aef4..1b71a6ada0c0b630ca3ce02b0c1f59f73e102fad 100644 (file)
@@ -1196,12 +1196,28 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
         }
     }
 
-/// First basic support of insert for Oracle. As it doesn't
-/// support autogenerated fields, we rely on the corresponding
-/// sequence. It will work automatically, unless we need to
-/// return the primary from the function, in this case we
-/// get the next sequence value here and insert it manually.
-    if ( $CFG->dbtype === 'oci8po' && $returnid == true) {
+/// Begin DIRTY HACK
+    if ($CFG->dbtype == 'oci8po') {
+        oracle_dirty_hack($table, $dataobject); // Convert object to the correct "empty" values for Oracle DB
+    }
+/// End DIRTY HACK
+
+/// Under Oracle we have our own insert record process
+/// detect all the clob/blob fields and change their contents to @#CLOB#@ and @#BLOB#@
+/// saving them into $foundclobs and $foundblobs [$fieldname]->contents
+/// Same for mssql (only processing blobs - image fields)
+    if (($CFG->dbtype == 'oci8po' || $CFG->dbtype == 'mssql' || $CFG->dbtype == 'odbc_mssql' || $CFG->dbtype == 'mssql_n')) {
+        $foundclobs = array();
+        $foundblobs = array();
+        db_detect_lobs($table, $dataobject, $foundclobs, $foundblobs);
+    }
+
+/// Under Oracle, if the primary key inserted has been requested OR
+/// if there are LOBs to insert, we calculate the next value via
+/// explicit query to the sequence.
+/// Else, the pre-insert trigger will do the job, because the primary
+/// key isn't needed at all by the rest of PHP code
+    if ( $CFG->dbtype === 'oci8po' && ($returnid == true || !empty($foundclobs) || !empty($foundblobs))) {
     /// We need this here (move this function to dmlib?)
         include_once($CFG->libdir . '/ddllib.php');
         $xmldb_table = new XMLDBTable($table);
@@ -1218,22 +1234,6 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
         }
     }
 
-/// Begin DIRTY HACK
-    if ($CFG->dbtype == 'oci8po') {
-        oracle_dirty_hack($table, $dataobject); // Convert object to the correct "empty" values for Oracle DB
-    }
-/// End DIRTY HACK
-
-/// Under Oracle we have our own insert record process
-/// detect all the clob/blob fields and change their contents to @#CLOB#@ and @#BLOB#@
-/// saving them into $foundclobs and $foundblobs [$fieldname]->contents
-/// Same for mssql (only processing blobs - image fields)
-    if (($CFG->dbtype == 'oci8po' || $CFG->dbtype == 'mssql' || $CFG->dbtype == 'odbc_mssql' || $CFG->dbtype == 'mssql_n')) {
-        $foundclobs = array();
-        $foundblobs = array();
-        db_detect_lobs($table, $dataobject, $foundclobs, $foundblobs);
-    }
-    
 /// Get the correct SQL from adoDB
     if (!$insertSQL = $db->GetInsertSQL($rs, (array)$dataobject, true)) {
         return false;