Detection of SQL backend for random functions

This commit is contained in:
koldoa 2015-09-03 11:53:28 +02:00
parent 28e967f01c
commit b2cbcdfc97
1 changed files with 20 additions and 5 deletions

View File

@ -160,6 +160,16 @@
--forward the ring group
session:execute("transfer", ring_group_forward_destination.." XML "..context);
else
--first we check what version of SQL are we using
sql = "SELECT version() as version";
assert(dbh:query(sql, function(row)
if (string.find(row.version, "PostgreSQL")) then
sql_verion = 'postgresql'
else
sql_verion = 'mysql'
end
end));
--get the strategy of the ring group, if random, we use random() to order the destinations
sql = [[
SELECT
@ -172,16 +182,21 @@
AND r.domain_uuid = ']]..domain_uuid..[['
AND r.ring_group_enabled = 'true'
]];
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
assert(dbh:query(sql, function(row)
if (row.ring_group_strategy == "random") then
sql_order = 'random()'
if (sql_verion == "postgresql") then
sql_order = 'random()'
end
if (sql_verion == "mysql") then
sql_order = 'rand()'
end
else
sql_order='d.destination_delay, d.destination_number asc'
end
end));
--get the ring group destinations
sql = [[
SELECT
@ -196,7 +211,7 @@
AND r.domain_uuid = ']]..domain_uuid..[['
AND r.ring_group_enabled = 'true'
ORDER BY
]]..sql_order..[[
]]..sql_order..[[
]];
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
destinations = {};