From 78b46511068968d70f3f29b8d0fbeb7c7dfbf771 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Tue, 7 Feb 2023 22:50:05 -0700 Subject: [PATCH] Use additional conditions so sqlite will work or postgresql Also added trim to prevent a trailing space from breaking the dsn string for sqlite. Also added debug lines helpful for testing. --- .../resources/functions/database/native.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/scripts/resources/scripts/resources/functions/database/native.lua b/app/scripts/resources/scripts/resources/functions/database/native.lua index 854637f41c..35cf5a4b2b 100644 --- a/app/scripts/resources/scripts/resources/functions/database/native.lua +++ b/app/scripts/resources/scripts/resources/functions/database/native.lua @@ -9,6 +9,7 @@ assert(freeswitch, "Require FreeSWITCH environment") ----------------------------------------------------------- local FsDatabase = {} do +require "resources.functions.trim" require "resources.functions.file_exists" require "resources.functions.database_handle" @@ -17,8 +18,19 @@ FsDatabase._backend_name = 'native' function FsDatabase.new(name) local dbh = assert(name) - if type(name) == 'string' then - dbh = database_handle(name) + if (type(name) == 'string') then + --debug information + --freeswitch.consoleLog("notice","name " .. name .. "\n"); + --freeswitch.consoleLog("notice","database.type " .. database.type .. "\n"); + --freeswitch.consoleLog("notice","database.name " .. database.name .. "\n"); + --freeswitch.consoleLog("notice","database.path " .. database.path .. "\n"); + + --handle switch sqlite + if (name == 'switch' and database.type == 'sqlite' and database.path ~= nil and database.name ~= nil) then + dbh = freeswitch.Dbh("sqlite://"..trim(database.path).."/"..trim(database.name)) + else + dbh = database_handle(name) + end end assert(dbh:connected())