]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18577 drop enums support - step3: fix native pgsql set_field_select() handling...
authorstronk7 <stronk7>
Fri, 1 May 2009 23:33:24 +0000 (23:33 +0000)
committerstronk7 <stronk7>
Fri, 1 May 2009 23:33:24 +0000 (23:33 +0000)
lib/dml/pgsql_native_moodle_database.php

index 365f4e87a65db51ad80cdbbb43ed28da1347c520..6fc7a064bbaf42c62d31ea6dab5a47e2ba1fb5a7 100644 (file)
@@ -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
         }