diff options
author | spag <spag@golwen.net> | 2013-01-09 11:08:00 +0100 |
---|---|---|
committer | spag <spag@golwen.net> | 2013-01-09 11:08:00 +0100 |
commit | d968c1f9a6933c3e5d2b2f16d38d656edb6fe152 (patch) | |
tree | 346e2dec3240901dcc0436d6f9d4c12067d34dd4 | |
parent | 7b749f8b5f4e01852a25a7cd0a65a9c00476b60d (diff) |
configuration_table added
-rw-r--r-- | misc/freeswitch/scripts/common/configuration_table.lua | 39 |
1 files changed, 39 insertions, 0 deletions
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 |