From: stronk7 Date: Mon, 30 Oct 2006 22:59:49 +0000 (+0000) Subject: Fixed one bug on Oracle produced when we were inserting X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=18fcece954b785a6dc55cdce12bb864ddbd806ce;p=moodle.git Fixed one bug on Oracle produced when we were inserting records with returnid disabled and containing LOBs Merged from MOODLE_17_STABLE --- diff --git a/lib/dmllib.php b/lib/dmllib.php index 484b576ac2..1b71a6ada0 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -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;