1
0
mirror of https://github.com/luapower/mysql.git synced 2024-12-28 20:00:33 +01:00

libmariadb tests

This commit is contained in:
Cosmin Apreuetsei 2014-03-16 20:07:29 +02:00
parent 176c33d47a
commit d2600710fb
2 changed files with 13 additions and 9 deletions

View File

@ -2,8 +2,9 @@
local ffi = require'ffi' local ffi = require'ffi'
local bit = require'bit' local bit = require'bit'
require'mysql_h' require'mysql_h'
local ok, C = pcall(ffi.load, ffi.abi'win' and 'libmysql' or 'mysql') local myok, myC = 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 maok, maC = pcall(ffi.load, ffi.abi'win' and 'libmariadb' or 'mariadb')
local C = maok and myC or maC
local M = {C = C} local M = {C = C}
--we compare NULL pointers against NULL instead of nil for compatibility with luaffi. --we compare NULL pointers against NULL instead of nil for compatibility with luaffi.
@ -1225,7 +1226,7 @@ end
--publish methods --publish methods
if not rawget(_G, '__MYSQL__') then if not rawget(_G, '__MYSQL__') then
_G.__MYSQL__ = true __MYSQL__ = true
ffi.metatype('MYSQL', {__index = conn}) ffi.metatype('MYSQL', {__index = conn})
ffi.metatype('MYSQL_RES', {__index = res}) ffi.metatype('MYSQL_RES', {__index = res})
ffi.metatype('MYSQL_STMT', {__index = stmt}) ffi.metatype('MYSQL_STMT', {__index = stmt})

View File

@ -1,3 +1,4 @@
--mysql test unit (see comments for problems with libmariadb)
local mysql = require'mysql' local mysql = require'mysql'
local glue = require'glue' local glue = require'glue'
local pformat = require'pp'.pformat local pformat = require'pp'.pformat
@ -49,7 +50,7 @@ local t = {
user = 'root', user = 'root',
db = 'test', db = 'test',
options = { options = {
MYSQL_SECURE_AUTH = true, MYSQL_SECURE_AUTH = false, --not supported by libmariadb
MYSQL_OPT_READ_TIMEOUT = 1, MYSQL_OPT_READ_TIMEOUT = 1,
}, },
flags = { flags = {
@ -66,7 +67,7 @@ print('conn:set_charset( ', pformat('utf8'), ')', conn:set_charset('utf8'))
--conn info --conn info
print('conn:charset_name() ', '->', pformat(conn:charset())); assert(conn:charset() == 'utf8') 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:ping() ', '->', pformat(conn:ping()))
print('conn:thread_id() ', '->', pformat(conn:thread_id())) print('conn:thread_id() ', '->', pformat(conn:thread_id()))
print('conn:stat() ', '->', pformat(conn:stat())) print('conn:stat() ', '->', pformat(conn:stat()))
@ -494,8 +495,8 @@ end
print_bind_buffer(bind) print_bind_buffer(bind)
print('stmt:free_result() ', stmt:free_result()) print('stmt:free_result() ', stmt:free_result())
local next_result = stmt:next_result() --local next_result = stmt:next_result()
print('stmt:next_result() ', '->', pformat(next_result)); assert(next_result == false) --print('stmt:next_result() ', '->', pformat(next_result)); assert(next_result == false)
print('stmt:reset() ', stmt:reset()) print('stmt:reset() ', stmt:reset())
print('stmt:close() ', stmt:close()) print('stmt:close() ', stmt:close())
@ -514,7 +515,8 @@ for i,field in ipairs(test_fields) do
local function exec() local function exec()
print('stmt:exec() ', stmt:exec()) print('stmt:exec() ', stmt:exec())
print('stmt:store_result() ', stmt:store_result()) 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 end
local v = test_values[field] 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 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, ')') 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
end end
print('stmt:close() ', stmt:close()) print('stmt:close() ', stmt:close())