diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-01-22 15:33:06 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-01-22 15:33:06 +0100 |
commit | 39aa7132ceed3d4beab3a9b828e571bbfc67c07e (patch) | |
tree | 6c88289c9f99be0af8635636fcdf64102090e5ec /misc/freeswitch/scripts/common/configuration_table.lua | |
parent | 5ad8203ce4f1bfea997960d0b52c626dea24b944 (diff) | |
parent | 6f69c1a85055ec7c2515719d79d2a7a4e60cec50 (diff) |
Merge branch 'develop'5.1-beta1
Diffstat (limited to 'misc/freeswitch/scripts/common/configuration_table.lua')
-rw-r--r-- | misc/freeswitch/scripts/common/configuration_table.lua | 46 |
1 files changed, 46 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..85bc014 --- /dev/null +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -0,0 +1,46 @@ +-- 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) + local p_section = common.str.strip(parameters.section):lower(); + local p_class_type = common.str.strip(parameters.class_type):lower(); + local p_name = common.str.strip(parameters.name); + + if not root[p_section] then + root[p_section] = {}; + end + + if p_class_type == 'boolean' then + root[p_section][p_name] = common.str.to_b(parameters.value); + elseif p_class_type == 'integer' then + root[p_section][p_name] = common.str.to_i(parameters.value); + else + root[p_section][p_name] = tostring(parameters.value); + end + end) + + if section then + return root[section]; + end + + return root; +end |