Fixed one bug on Oracle produced when we were inserting

records with returnid disabled and containing LOBs

Merged from MOODLE_17_STABLE
This commit is contained in:
stronk7 2006-10-30 22:59:49 +00:00
parent 695e03f00a
commit 18fcece954

View File

@ -1196,28 +1196,6 @@ 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) {
/// We need this here (move this function to dmlib?)
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)$db->GenID($seqname)) {
$dataobject->{$primarykey} = $nextval;
}
}
/// Begin DIRTY HACK
if ($CFG->dbtype == 'oci8po') {
oracle_dirty_hack($table, $dataobject); // Convert object to the correct "empty" values for Oracle DB
@ -1234,6 +1212,28 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
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);
$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)$db->GenID($seqname)) {
$dataobject->{$primarykey} = $nextval;
}
}
/// Get the correct SQL from adoDB
if (!$insertSQL = $db->GetInsertSQL($rs, (array)$dataobject, true)) {
return false;