webmcp

changeset 553:a0c49529ab8b

Support for BYTEA data type in models
author jbe
date Mon Feb 10 20:17:19 2020 +0100 (7 weeks ago)
parents 7e874b5227b6
children 1e72fa29d3fb
files libraries/mondelefant/mondelefant.lua
line diff
     1.1 --- a/libraries/mondelefant/mondelefant.lua	Mon Dec 09 16:09:14 2019 +0100
     1.2 +++ b/libraries/mondelefant/mondelefant.lua	Mon Feb 10 20:17:19 2020 +0100
     1.3 @@ -967,6 +967,15 @@
     1.4  --//--
     1.5  
     1.6  --[[--
     1.7 +<db_class>.binary_columns
     1.8 +
     1.9 +If binary data (PostgreSQL type BYTEA) is stored, must be set to a table mapping all column names used with binary data to true, e.g. File.binary_columns = { data = true }.
    1.10 +
    1.11 +--]]--
    1.12 +class_prototype.binary_columns = nil
    1.13 +--//
    1.14 +
    1.15 +--[[--
    1.16  db_handle =               -- database connection handle used by this class
    1.17  <db_class>:get_db_conn()
    1.18  
    1.19 @@ -1144,7 +1153,11 @@
    1.20      local values = {sep = ", "}
    1.21      for key in pairs(self._dirty or {}) do
    1.22        add(fields, '"' .. key .. '"')
    1.23 -      add(values, {'?', self._col[key]})
    1.24 +      if self._class.binary_columns and self._class.binary_columns[key] then
    1.25 +        add(values, {'$', {self._connection:quote_binary(self._col[key])}})
    1.26 +      else
    1.27 +        add(values, {'?', self._col[key]})
    1.28 +      end
    1.29      end
    1.30      local returning = { sep = ", " }
    1.31      if primary_key.json_doc then
    1.32 @@ -1243,7 +1256,11 @@
    1.33            verify_mutability_state(self._col[key], mutability_state)
    1.34          )
    1.35        then
    1.36 -        add(update_sets, {'"$" = ?', {key}, self._col[key]})
    1.37 +        if self._class.binary_columns and self._class.binary_columns[key] then
    1.38 +          add(update_sets, {'"$" = $', {key}, {self._connection:quote_binary(self._col[key])}})
    1.39 +        else
    1.40 +          add(update_sets, {'"$" = ?', {key}, self._col[key]})
    1.41 +        end
    1.42          self._dirty[key] = true  -- always dirty in case of later error
    1.43        end
    1.44      end

Impressum / About Us