From d968c1f9a6933c3e5d2b2f16d38d656edb6fe152 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 11:08:00 +0100 Subject: configuration_table added --- .../scripts/common/configuration_table.lua | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 misc/freeswitch/scripts/common/configuration_table.lua diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua new file mode 100644 index 0000000..afb5b0e --- /dev/null +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -0,0 +1,39 @@ +-- Gemeinschaft 5 module: configuration table +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +-- retrieve configuration from database +function get(database, entity, section) + if not database or not entity then + return {}; + end + + require 'common.str' + + local sql_query = 'SELECT * FROM `gs_parameters` WHERE `entity` = "' .. entity .. '"'; + if section then + sql_query = sql_query .. ' AND `section` = "' .. section .. '"'; + end + + local root = {} + local parameter_class = ''; + + database:query(sql_query, function(parameters) + if not root[parameters.section] then + root[parameters.section] = {}; + end + parameter_class = tostring(parameters.class_type):lower(); + + if parameter_class == 'boolean' then + root[parameters.section][parameters.name] = common.str.to_b(parameters.value); + elseif parameter_class == 'integer' then + root[parameters.section][parameters.name] = common.str.to_i(parameters.value); + else + root[parameters.section][parameters.name] = tostring(parameters.value); + end + end) + + return root; +end -- cgit v1.2.3