From b2cbcdfc97c01723f717a0d4892dfb34370bbaa7 Mon Sep 17 00:00:00 2001 From: koldoa Date: Thu, 3 Sep 2015 11:53:28 +0200 Subject: [PATCH] Detection of SQL backend for random functions --- .../install/scripts/app/ring_groups/index.lua | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index b122bc371a..dee8542206 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -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 = {};