unimportant

This commit is contained in:
Cosmin Apreutesei 2019-11-07 00:28:01 +02:00
parent f3bd1020b2
commit 1164e0fc20
4 changed files with 16 additions and 14 deletions

View File

@ -1,11 +1,11 @@
--mySQL client library ffi binding. --MySQL client library ffi binding.
--Written by Cosmin Apreutesei. Public domain. --Written by Cosmin Apreutesei. Public domain.
--Supports mysql Connector/C 6.1. --Supports MySQL Connector/C 6.1.
--Based on mySQL 5.7 manual. --Based on MySQL 5.7 manual.
if not ... then require'mysql_test' end if not ... then require'mysql_test'; return end
local ffi = require'ffi' local ffi = require'ffi'
local bit = require'bit' local bit = require'bit'
@ -15,12 +15,12 @@ local C
local M = {} local M = {}
--select a mysql client library implementation. --select a mysql client library implementation.
local function config(lib) local function bind(lib)
if not C then if not C then
if not lib or lib == 'mysql' then if not lib or lib == 'mysql' then
C = ffi.load(ffi.abi'win' and 'libmysql' or 'mysqlclient') C = ffi.load(ffi.abi'win' and 'libmysql' or 'mysqlclient')
elseif lib == 'mariadb' then elseif lib == 'mariadb' then
C = ffi.load(ffi.abi'win' and 'libmariadb' or 'mariadb') C = ffi.load'mariadb'
elseif type(lib) == 'string' then elseif type(lib) == 'string' then
C = ffi.load(lib) C = ffi.load(lib)
else else
@ -31,7 +31,7 @@ local function config(lib)
return M return M
end end
M.config = config M.bind = bind
--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.
local NULL = ffi.cast('void*', nil) local NULL = ffi.cast('void*', nil)
@ -72,17 +72,17 @@ end
--client library info --client library info
function M.thread_safe() function M.thread_safe()
config() bind()
return C.mysql_thread_safe() == 1 return C.mysql_thread_safe() == 1
end end
function M.client_info() function M.client_info()
config() bind()
return cstring(C.mysql_get_client_info()) return cstring(C.mysql_get_client_info())
end end
function M.client_version() function M.client_version()
config() bind()
return tonumber(C.mysql_get_client_version()) return tonumber(C.mysql_get_client_version())
end end
@ -126,7 +126,7 @@ local option_encoders = {
} }
function M.connect(t, ...) function M.connect(t, ...)
config() bind()
local host, user, pass, db, charset, port local host, user, pass, db, charset, port
local unix_socket, flags, options, attrs local unix_socket, flags, options, attrs
local key, cert, ca, capath, cipher local key, cert, ca, capath, cipher

View File

@ -12,7 +12,7 @@ A complete, lightweight ffi binding of the mysql client library.
-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------------------------------------
**[Initialization]** **[Initialization]**
`mysql.config(['mysql'|'mariadb'|libname|clib]) -> mysql` `mysql.bind(['mysql'|'mariadb'|libname|clib]) -> mysql`
**[Connections]** **[Connections]**
`mysql.connect(host, [user], [pass], [db], [charset], [port]) -> conn` connect to a mysql server `mysql.connect(host, [user], [pass], [db], [charset], [port]) -> conn` connect to a mysql server
`mysql.connect(options_t) -> conn` connect to a mysql server `mysql.connect(options_t) -> conn` connect to a mysql server

View File

@ -1,5 +1,7 @@
--mysql table pretty printing --mysql table pretty printing
if not ... then require'mysql_test'; return end
local function ellipsis(s,n) local function ellipsis(s,n)
return #s > n and (s:sub(1,n-3) .. '...') or s return #s > n and (s:sub(1,n-3) .. '...') or s
end end
@ -132,8 +134,6 @@ local function print_statement(stmt, minsize, print)
print_table(fields, rows, aligns, minsize, print) print_table(fields, rows, aligns, minsize, print)
end end
if not ... then require'mysql_test' end
return { return {
fit = fit, fit = fit,
format_cell = format_cell, format_cell = format_cell,

View File

@ -6,6 +6,8 @@ local pp = require'pp'
local myprint = require'mysql_print' local myprint = require'mysql_print'
local ffi = require'ffi' local ffi = require'ffi'
mysql.bind'mariadb'
--helpers --helpers
local print_table = myprint.table local print_table = myprint.table