diff options
author | spag <spag@golwen.net> | 2013-01-10 12:28:06 +0100 |
---|---|---|
committer | spag <spag@golwen.net> | 2013-01-10 12:28:06 +0100 |
commit | 7268fbc3b37ae35993a7379cc66221c5e24c2016 (patch) | |
tree | 37675d2e7d6c0c506ffa8d59b02c5669b52733eb /misc/freeswitch/scripts | |
parent | 171a2317964f54a9b743eaa77b02d1119bee070c (diff) |
freeswitch odbc database class added
Diffstat (limited to 'misc/freeswitch/scripts')
-rw-r--r-- | misc/freeswitch/scripts/common/database.lua | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/common/database.lua b/misc/freeswitch/scripts/common/database.lua new file mode 100644 index 0000000..1f39135 --- /dev/null +++ b/misc/freeswitch/scripts/common/database.lua @@ -0,0 +1,78 @@ +-- Gemeinschaft 5 module: database class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Database = {} + +DATABASE_DSN = 'gemeinschaft'; + +function Database.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'database'; + self.log = arg.log; + self.conn = nil; + return object; +end + + +function Database.connect(self) + self.dsn = DATABASE_DSN; + + require 'common.configuration_file' + local dsn = common.configuration_file.get('/var/lib/freeswitch/.odbc.ini', self.dsn); + + self.database_name = dsn.DATABASE; + self.user_name = dsn.USER; + self.password = dsn.PASSWORD; + self.host_name = dsn.HOST; + + self.conn = freeswitch.Dbh(self.dsn, self.user_name, self.password); + self.conn_id = tostring(self.conn); + + return self; +end + + +function Database.connected(self) + return self.conn:connected(); +end + + +function Database.query(self, sql_query, call_function) + if call_function then + return self.conn:query(sql_query, call_function); + else + return self.conn:query(sql_query); + end +end + + +function Database.query_return_value(self, sql_query) + local result = nil; + + self.conn:query(sql_query, function(row) + for key, value in pairs(row) do + result = value; + return result; + end + end) + + return result; +end + + +function Database.last_insert_id(self) + return self:query_return_value('SELECT LAST_INSERT_ID()'); +end + + +function Database.release(self) + if self.conn then + self.conn:release(); + end +end |