webmcp

view framework/env/param/update.lua @ 569:5b19007574de

New argument active_link_attr for env.ui.paginate{...}
author jbe
date Wed Oct 13 17:21:44 2021 +0200 (2021-10-13)
parents 9fdfb27f8e67
children
line source
1 --[[--
2 param.update(
3 record, -- database record to be updated
4 key_and_field_name1, -- name of CGI parameter and record field
5 key_and_field_name2, -- another name of a CGI parameter and record field
6 {
7 key3, -- name of CGI parameter
8 field_name3 -- name of record field
9 }
10 )
12 This function can update several fields of a database record using GET/POST request parameters (or internal/exchanged parameters). The type of each parameter is automatically determined by the class of the record (_class:get_colums()[field].type).
13 --]]--
15 function param.update(record, mapping_info, ...)
16 if not mapping_info then
17 return
18 end
19 assert(record, "No record given for param.update(...).")
20 assert(record._class, "Record passed to param.update(...) has no _class attribute.")
21 local key, field_name
22 if type(mapping_info) == "string" then
23 key = mapping_info
24 field_name = mapping_info
25 else
26 key = mapping_info[1]
27 field_name = mapping_info[2]
28 end
29 assert(key, "No key given in parameter of param.update(...).")
30 assert(field_name, "No field name given in parameter of param.update(...).")
31 local column_info = record._class:get_columns()[field_name]
32 if not column_info then
33 error('Type of column "' .. field_name .. '" is unknown.')
34 end
35 local new_value = param.get(key, column_info.type)
36 if new_value ~= record[field_name] then
37 record[field_name] = new_value
38 end
39 return param.update(record, ...) -- recursivly process following arguments
40 end

Impressum / About Us