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

View File

@ -12,7 +12,7 @@ A complete, lightweight ffi binding of the mysql client library.
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
**[Initialization]**
`mysql.config(['mysql'|'mariadb'|libname|clib]) -> mysql`
`mysql.bind(['mysql'|'mariadb'|libname|clib]) -> mysql`
**[Connections]**
`mysql.connect(host, [user], [pass], [db], [charset], [port]) -> 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
if not ... then require'mysql_test'; return end
local function ellipsis(s,n)
return #s > n and (s:sub(1,n-3) .. '...') or s
end
@ -132,8 +134,6 @@ local function print_statement(stmt, minsize, print)
print_table(fields, rows, aligns, minsize, print)
end
if not ... then require'mysql_test' end
return {
fit = fit,
format_cell = format_cell,

View File

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