From: stronk7 Date: Fri, 1 May 2009 23:33:24 +0000 (+0000) Subject: MDL-18577 drop enums support - step3: fix native pgsql set_field_select() handling... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=762bd0df3ceb30ee38c88f86a0ce4a31f952e2ce;p=moodle.git MDL-18577 drop enums support - step3: fix native pgsql set_field_select() handling of BLOBs --- diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index 365f4e87a6..6fc7a064bb 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -958,6 +958,7 @@ class pgsql_native_moodle_database extends moodle_database { * @throws dml_exception if error */ public function set_field_select($table, $newfield, $newvalue, $select, array $params=null) { + if ($select) { $select = "WHERE $select"; } @@ -967,6 +968,21 @@ class pgsql_native_moodle_database extends moodle_database { list($select, $params, $type) = $this->fix_sql_params($select, $params); $i = count($params)+1; + /// Get column metadata + $columns = $this->get_columns($table); + $column = $columns[$newfield]; + + if ($column->meta_type == 'B') { /// If the column is a BLOB + /// Update BYTEA and return + $newvalue = pg_escape_bytea($this->pgsql, $newvalue); + $sql = "UPDATE {$this->prefix}$table SET $newfield = '$newvalue'::bytea $select"; + $this->query_start($sql, NULL, SQL_QUERY_UPDATE); + $result = pg_query_params($this->pgsql, $sql, $params); + $this->query_end($result); + pg_free_result($result); + return true; + } + if (is_bool($newvalue)) { $newvalue = (int)$newvalue; // prevent "false" problems }