MDL-19057 blobs now supported in pgsql's import_record()

This commit is contained in:
Petr Skoda
2010-09-13 18:31:21 +00:00
parent de77601b57
commit f3e317dceb
+26 -3
View File
@@ -522,13 +522,13 @@ class pgsql_native_moodle_database extends moodle_database {
if (is_bool($value)) { // Always, convert boolean to int
$value = (int)$value;
} else if ($column->meta_type == 'B') { // BLOB detected, we return 'blob' array instead of raw value to allow
} else if ($column->meta_type === 'B') { // BLOB detected, we return 'blob' array instead of raw value to allow
if (!is_null($value)) { // binding/executing code later to know about its nature
$value = array('blob' => $value);
}
} else if ($value === '') {
if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
if ($column->meta_type === 'I' or $column->meta_type === 'F' or $column->meta_type === 'N') {
$value = 0; // prevent '' problems in numeric fields
}
}
@@ -854,15 +854,38 @@ class pgsql_native_moodle_database extends moodle_database {
$columns = $this->get_columns($table);
$cleaned = array();
$blobs = array();
foreach ($dataobject as $field=>$value) {
if (!isset($columns[$field])) {
continue;
}
if ($columns[$field]->meta_type === 'B') {
if (!is_null($value)) {
$cleaned[$field] = '@#BLOB#@';
$blobs[$field] = $value;
continue;
}
}
$cleaned[$field] = $value;
}
return $this->insert_record_raw($table, $cleaned, false, true, true);
$id = $dataobject['id'];
$this->insert_record_raw($table, $cleaned, false, true, true);
foreach ($blobs as $key=>$value) {
$value = pg_escape_bytea($this->pgsql, $value);
$sql = "UPDATE {$this->prefix}$table SET $key = '$value'::bytea WHERE id = $id";
$this->query_start($sql, NULL, SQL_QUERY_UPDATE);
$result = pg_query($this->pgsql, $sql);
$this->query_end($result);
if ($result !== false) {
pg_free_result($result);
}
}
return true;
}
/**