From d2600710fbfbe481c6e1acedd90b864c8b1fe1e3 Mon Sep 17 00:00:00 2001 From: Cosmin Apreuetsei Date: Sun, 16 Mar 2014 20:07:29 +0200 Subject: [PATCH] libmariadb tests --- mysql.lua | 7 ++++--- mysql_test.lua | 15 +++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/mysql.lua b/mysql.lua index 63674d7..c6cba9d 100644 --- a/mysql.lua +++ b/mysql.lua @@ -2,8 +2,9 @@ local ffi = require'ffi' local bit = require'bit' require'mysql_h' -local ok, C = pcall(ffi.load, ffi.abi'win' and 'libmysql' or 'mysql') -if not ok then C = ffi.load(ffi.abi'win' and 'libmariadb' or 'mariadb') end +local myok, myC = pcall(ffi.load, ffi.abi'win' and 'libmysql' or 'mysql') +local maok, maC = pcall(ffi.load, ffi.abi'win' and 'libmariadb' or 'mariadb') +local C = maok and myC or maC local M = {C = C} --we compare NULL pointers against NULL instead of nil for compatibility with luaffi. @@ -1225,7 +1226,7 @@ end --publish methods if not rawget(_G, '__MYSQL__') then -_G.__MYSQL__ = true +__MYSQL__ = true ffi.metatype('MYSQL', {__index = conn}) ffi.metatype('MYSQL_RES', {__index = res}) ffi.metatype('MYSQL_STMT', {__index = stmt}) diff --git a/mysql_test.lua b/mysql_test.lua index 08b7fbf..4686b80 100644 --- a/mysql_test.lua +++ b/mysql_test.lua @@ -1,3 +1,4 @@ +--mysql test unit (see comments for problems with libmariadb) local mysql = require'mysql' local glue = require'glue' local pformat = require'pp'.pformat @@ -49,7 +50,7 @@ local t = { user = 'root', db = 'test', options = { - MYSQL_SECURE_AUTH = true, + MYSQL_SECURE_AUTH = false, --not supported by libmariadb MYSQL_OPT_READ_TIMEOUT = 1, }, flags = { @@ -66,7 +67,7 @@ print('conn:set_charset( ', pformat('utf8'), ')', conn:set_charset('utf8')) --conn info print('conn:charset_name() ', '->', pformat(conn:charset())); assert(conn:charset() == 'utf8') -print('conn:charset_info() ', '->', pformat(conn:charset_info(), ' ')) +print('conn:charset_info() ', '->', pformat(conn:charset_info(), ' ')) --crashes libmariadb print('conn:ping() ', '->', pformat(conn:ping())) print('conn:thread_id() ', '->', pformat(conn:thread_id())) print('conn:stat() ', '->', pformat(conn:stat())) @@ -494,8 +495,8 @@ end print_bind_buffer(bind) print('stmt:free_result() ', stmt:free_result()) -local next_result = stmt:next_result() -print('stmt:next_result() ', '->', pformat(next_result)); assert(next_result == false) +--local next_result = stmt:next_result() +--print('stmt:next_result() ', '->', pformat(next_result)); assert(next_result == false) print('stmt:reset() ', stmt:reset()) print('stmt:close() ', stmt:close()) @@ -514,7 +515,8 @@ for i,field in ipairs(test_fields) do local function exec() print('stmt:exec() ', stmt:exec()) print('stmt:store_result() ', stmt:store_result()) - print('stmt:row_count() ', '->', stmt:row_count()); assert(stmt:row_count() == 1) + print('stmt:row_count() ', '->', stmt:row_count()) + assert(stmt:row_count() == 1) --libmariadb() returns 0 end local v = test_values[field] @@ -523,7 +525,8 @@ for i,field in ipairs(test_fields) do if field:find'date' or field:find'time' then print('bind:set_date( ', 1, v.year, v.month, v.day, v.hour, v.min, v.sec, v.frac, ')') - bind:set_date(1, v.year, v.month, v.day, v.hour, v.min, v.sec, v.frac); exec() + bind:set_date(1, v.year, v.month, v.day, v.hour, v.min, v.sec, v.frac) + exec() --libmariadb crashes the server end end print('stmt:close() ', stmt:close())