Detection of SQL backend for random functions
This commit is contained in:
parent
28e967f01c
commit
b2cbcdfc97
|
|
@ -160,6 +160,16 @@
|
||||||
--forward the ring group
|
--forward the ring group
|
||||||
session:execute("transfer", ring_group_forward_destination.." XML "..context);
|
session:execute("transfer", ring_group_forward_destination.." XML "..context);
|
||||||
else
|
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
|
--get the strategy of the ring group, if random, we use random() to order the destinations
|
||||||
sql = [[
|
sql = [[
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -172,16 +182,21 @@
|
||||||
AND r.domain_uuid = ']]..domain_uuid..[['
|
AND r.domain_uuid = ']]..domain_uuid..[['
|
||||||
AND r.ring_group_enabled = 'true'
|
AND r.ring_group_enabled = 'true'
|
||||||
]];
|
]];
|
||||||
|
|
||||||
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
|
|
||||||
assert(dbh:query(sql, function(row)
|
assert(dbh:query(sql, function(row)
|
||||||
if (row.ring_group_strategy == "random") then
|
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
|
else
|
||||||
sql_order='d.destination_delay, d.destination_number asc'
|
sql_order='d.destination_delay, d.destination_number asc'
|
||||||
end
|
end
|
||||||
end));
|
end));
|
||||||
|
|
||||||
--get the ring group destinations
|
--get the ring group destinations
|
||||||
sql = [[
|
sql = [[
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -196,7 +211,7 @@
|
||||||
AND r.domain_uuid = ']]..domain_uuid..[['
|
AND r.domain_uuid = ']]..domain_uuid..[['
|
||||||
AND r.ring_group_enabled = 'true'
|
AND r.ring_group_enabled = 'true'
|
||||||
ORDER BY
|
ORDER BY
|
||||||
]]..sql_order..[[
|
]]..sql_order..[[
|
||||||
]];
|
]];
|
||||||
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
|
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
|
||||||
destinations = {};
|
destinations = {};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue