From: stronk7 Date: Sun, 8 Oct 2006 09:58:11 +0000 (+0000) Subject: Now Oracle uses the new find_sequence_name() function to find the X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5fbab6173ac934b460920771399d4f6d8fe21e29;p=moodle.git Now Oracle uses the new find_sequence_name() function to find the correct sequence name for each table on insert. Also, introduced initial hooks to support Oracle LOBs in insert_record() --- diff --git a/lib/dmllib.php b/lib/dmllib.php index 9644a1ee96..d8d06a41f7 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -1105,11 +1105,16 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') { /// get the next sequence value here and insert it manually. if ( $CFG->dbtype === 'oci8po' && $returnid == true) { /// We need this here (move this function to dmlib?) - include_once($CFG->libdir . '/xmldb/classes/generators/XMLDBGenerator.class.php'); - include_once($CFG->libdir . '/xmldb/classes/generators/oci8po/oci8po.class.php'); - $generator = new XMLDBoci8po(); - $generator->setPrefix($CFG->prefix); - $seqname = $generator->getNameForObject($table, $primarykey, 'seq'); + include_once($CFG->libdir . '/ddllib.php'); + $xmldb_table = new XMLDBTable($table); + $seqname = find_sequence_name($xmldb_table); + if (!$seqname) { + /// Fallback, seqname not found, something is wrong. Inform and use the alternative getNameForObject() method + debugging('Sequence name for table ' . $table->getName() . ' not found', DEBUG_DEVELOPER); + $generator = new XMLDBoci8po(); + $generator->setPrefix($CFG->prefix); + $seqname = $generator->getNameForObject($table, $primarykey, 'seq'); + } if ($nextval = (int)get_field_sql("SELECT $seqname.NEXTVAL from dual")) { $dataobject->{$primarykey} = $nextval; } @@ -1120,12 +1125,28 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') { 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 + if ($CFG->dbtype == 'oci8po' && !empty($dataobject->{$primarykey})) { + $foundclobs = array(); + $foundblobs = array(); + ///TODO + } /// Get the correct SQL from adoDB if (!$insertSQL = $db->GetInsertSQL($rs, (array)$dataobject, true)) { return false; } +/// Under Oracle, replace all the '@#CLOB#@' and '@#BLOB#@' ocurrences to empty_clob() and empty_blob() +/// if we know we have some of them in the query + if ($CFG->dbtype == 'oci8po' && !empty($dataobject->{$primarykey}) && + (!empty($foundclobs) || !empty($foundblobs))) { + ///TODO + } + /// Run the SQL statement if (!$rs = $db->Execute($insertSQL)) { debugging($db->ErrorMsg() .'

'.$insertSQL); @@ -1136,6 +1157,13 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') { return false; } +/// Under Oracle, finally, Update all the Clobs and Blobs present in the record +/// if we know we have some of them in the query + if ($CFG->dbtype == 'oci8po' && !empty($dataobject->{$primarykey}) && + (!empty($foundclobs) || !empty($foundblobs))) { + //TODO + } + /// If a return ID is not needed then just return true now if (!$returnid) { return true;