IMPORTANT! CRUCIAL CHANGE TO MAJOR FUNCTION!

Petri Asikainen rewrote insert_record to use ADOdb functions.  It might
be very slightly slower but it gets rid of all the horrible not-quite-working
PostgreSQL workarounds the old one contained.

It worked for him on PostgreSQL 7.4 and for me on MySQL 3.23 and 4.0.15,
so I'm checking it in.

Please test it thoroughly on your test systems.

Since it writes data it has the potential to stuff things up, so be
careful on production systems for a few days.
This commit is contained in:
moodler
2004-01-29 15:27:21 +00:00
parent 66e7920caf
commit 0892f7bd01
+42
View File
@@ -746,6 +746,48 @@ function delete_records_select($table, $select="") {
* @param type description
*/
function insert_record($table, $dataobject, $returnid=true) {
global $db, $CFG;
// Get empty record from table
$infosql = "SELECT * FROM $CFG->prefix$table WHERE id ='-1'";
// Execute the query and get the empty recordset
$rs = $db->Execute($infosql);
// Convert data to array to hold the record data to insert
$record = (array)$dataobject;
//Get insertsql from adodb
$insertSQL = $db->GetInsertSQL($rs, $record);
if (! $rs = $db->Execute($insertSQL)) {
return false;
}
if (!$returnid) { // Return ID is not needed so just finish here.
return true;
}
switch ($CFG->dbtype) {
case "postgres7":
$oid = $db->Insert_ID();
if ($rs = $db->Execute("SELECT id FROM $CFG->prefix$table WHERE oid = $oid")) {
// every table needs to have a primary field named 'id' for this to work
if ($rs->RecordCount() == 1) {
return $rs->fields[0];
}
}
return false;
default:
return $db->Insert_ID(); // Should work on most databases, but not all!
}
}
function insert_record_old($table, $dataobject, $returnid=true) {
// Will be deleted soon if there are no problems with the new one
global $db, $CFG;