From 48da56ff19b6581d8a631c1d3e989f2f591a1923 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 30 Mar 2021 16:06:21 +0300 Subject: [PATCH 37/38] Use os.time() in database.lua It replaces dirty database access to get the time. See osdn #41879 Signed-off-by: Marko Lindqvist --- lua/database.lua | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/lua/database.lua b/lua/database.lua index d2be6f7b5a..9ce3da896d 100644 --- a/lua/database.lua +++ b/lua/database.lua @@ -88,22 +88,6 @@ local function sqlite_connect() dbh = assert(sql:connect(database)) end --- DIRTY: return a string to put in a database query which gets the --- current time (in seconds since the epoch, UTC). --- (This should be replaced with Lua os.time() once the script has access --- to this, see .) -function sql_time() - local backend = get_option("backend") - if backend == 'mysql' then - return 'UNIX_TIMESTAMP()' - elseif backend == 'sqlite' then - return 'strftime(\'%s\',\'now\')' - else - log.error('Don\'t know how to do timestamps for database backend \'%s\'', backend) - return 'ERROR' - end -end - -- Set up tables for an SQLite database. -- (Since there`s no concept of user rights, we can do this directly from Lua, -- without needing a separate script like MySQL. The server operator can do @@ -257,11 +241,11 @@ function user_save(conn, password) local ipaddr = auth.get_ipaddr(conn) -- insert the user - --local now = os.time() + local now = os.time() local query = string.format([[INSERT INTO %s VALUES (NULL, '%s', '%s', NULL, %s, %s, '%s', '%s', 0)]], table_user, username, md5sum(password), - sql_time(), sql_time(), + now, now, ipaddr, ipaddr) assert(dbh:execute(query)) @@ -287,14 +271,14 @@ function user_log(conn, success) --local now = os.time() query = string.format([[UPDATE %s SET accesstime = %s, address = '%s', logincount = logincount + 1 - WHERE name = '%s']], table_user, sql_time(), + WHERE name = '%s']], table_user, os.time(), ipaddr, username) assert(dbh:execute(query)) -- insert the log row for this user query = string.format([[INSERT INTO %s (name, logintime, address, succeed) VALUES ('%s', %s, '%s', '%s')]], - table_log, username, sql_time(), ipaddr, success_str) + table_log, username, os.time(), ipaddr, success_str) assert(dbh:execute(query)) end -- 2.30.2