$dataobject = new StdClass;
$dataobject->{$newfield} = $newvalue;
- // Oracle DIRTY HACK -
+ // Oracle DIRTY HACK -
if ($CFG->dbfamily == 'oracle') {
oracle_dirty_hack($table, $dataobject); // Convert object to the correct "empty" values for Oracle DB
$newvalue = $dataobject->{$newfield};
}
// End DIRTY HACK
-/// Under Oracle and MSSQL we have our own set field process
+/// Under Oracle, MSSQL and PostgreSQL we have our own set field process
/// If the field being updated is clob/blob, we use our alternate update here
/// They will be updated later
- if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') && !empty($select)) {
+ if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres') && !empty($select)) {
/// Detect lobs
$foundclobs = array();
$foundblobs = array();
db_detect_lobs($table, $dataobject, $foundclobs, $foundblobs);
}
-/// Under Oracle and MSSQL, finally, Update all the Clobs and Blobs present in the record
+/// Under Oracle, MSSQL and PostgreSQL, finally, update all the Clobs and Blobs present in the record
/// if we know we have some of them in the query
- if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') && !empty($select) &&
+ if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres') && !empty($select) &&
(!empty($foundclobs) || !empty($foundblobs))) {
if (!db_update_lobs($table, $select, $foundclobs, $foundblobs)) {
return false; //Some error happened while updating LOBs
}
/// End DIRTY HACK
-/// Under Oracle and MSSQL we have our own insert record process
+/// Under Oracle, MSSQL and PostgreSQL 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->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
+ if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres') {
$foundclobs = array();
$foundblobs = array();
db_detect_lobs($table, $dataobject, $foundclobs, $foundblobs);
return false;
}
-/// Under Oracle and MSSQL, replace all the '@#CLOB#@' and '@#BLOB#@' ocurrences to proper default values
+/// Under Oracle, MSSQL and PostgreSQL, replace all the '@#CLOB#@' and '@#BLOB#@' ocurrences to proper default values
/// if we know we have some of them in the query
- if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') &&
+ if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres') &&
(!empty($foundclobs) || !empty($foundblobs))) {
/// Initial configuration, based on DB
switch ($CFG->dbfamily) {
$blobdefault = 'empty_blob()'; //Value of empty default blobs for this DB
break;
case 'mssql':
+ case 'postgres':
$clobdefault = 'null'; //Value of empty default clobs for this DB (under mssql this won't be executed
$blobdefault = 'null'; //Value of empty default blobs for this DB
break;
return false;
}
-/// Under Oracle, finally, Update all the Clobs and Blobs present in the record
+/// Under Oracle and PostgreSQL, finally, update all the Clobs and Blobs present in the record
/// if we know we have some of them in the query
- if ($CFG->dbfamily == 'oracle' &&
+ if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'postgres') &&
!empty($dataobject->{$primarykey}) &&
(!empty($foundclobs) || !empty($foundblobs))) {
if (!db_update_lobs($table, $dataobject->{$primarykey}, $foundclobs, $foundblobs)) {
}
/// End DIRTY HACK
-/// Under Oracle and MSSQL we have our own update record process
+/// Under Oracle, MSSQL and PostgreSQL we have our own update record process
/// detect all the clob/blob fields and delete them from the record being updated
/// saving them into $foundclobs and $foundblobs [$fieldname]->contents
/// They will be updated later
- if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql')
+ if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres')
&& !empty($dataobject->id)) {
/// Detect lobs
$foundclobs = array();
foreach ($columns as $column) {
if ($column->name <> 'id' and array_key_exists($column->name, $data)) {
$ddd[$column->name] = $data[$column->name];
- // PostgreSQL bytea support
- if ($CFG->dbfamily == 'postgres' && $column->type == 'bytea') {
- $ddd[$column->name] = $db->BlobEncode($ddd[$column->name]);
- }
}
}
}
}
-/// Under Oracle AND MSSQL, finally, Update all the Clobs and Blobs present in the record
+/// Under Oracle, MSSQL and PostgreSQL, finally, update all the Clobs and Blobs present in the record
/// if we know we have some of them in the query
- if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') &&
+ if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres') &&
!empty($dataobject->id) &&
(!empty($foundclobs) || !empty($foundblobs))) {
if (!db_update_lobs($table, $dataobject->id, $foundclobs, $foundblobs)) {
$clobdbtype = 'NOTPROCESSES'; //Name of clobs for this DB (under mssql flavours we don't process CLOBS)
$blobdbtype = 'IMAGE'; //Name of blobs for this DB
break;
+ case 'postgres':
+ $clobdbtype = 'NOTPROCESSES'; //Name of clobs for this DB (under postgres flavours we don't process CLOBS)
+ $blobdbtype = 'BYTEA'; //Name of blobs for this DB
+ break;
default:
return; //Other DB doesn't need this two step to happen, prevent continue
}
continue;
}
- /// If the field is BLOB OR IMAGE, update its value to '@#BLOB#@' and store it in the $blobs array
+ /// If the field is BLOB OR IMAGE OR BYTEA, update its value to '@#BLOB#@' and store it in the $blobs array
if (strtoupper($columns[strtolower($fieldname)]->type) == $blobdbtype) {
$blobs[$fieldname] = $dataobject->$fieldname;
if ($unset) {
$clobdbtype = 'NOTPROCESSES'; //Name of clobs for this DB (under mssql flavours we don't process CLOBS)
$blobdbtype = 'IMAGE'; //Name of blobs for this DB
break;
+ case 'postgres':
+ $clobdbtype = 'NOTPROCESSES'; //Name of clobs for this DB (under postgres flavours we don't process CLOBS)
+ $blobdbtype = 'BYTEA'; //Name of blobs for this DB
+ break;
default:
return; //Other DB doesn't need this two step to happen, prevent continue
}
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; }; /// Count the extra updates in PERF
- /// Oracle and MSSQL BLOBs doesn't like quoted strings (are inserted via prepared statemets)
- if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
+ /// Oracle, MSSQL and PostgreSQL BLOBs doesn't like quoted strings (are inserted via prepared statemets)
+ if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres') {
$value = stripslashes_safe($value);
}