mirror of
https://github.com/luapower/mysql.git
synced 2025-02-08 08:10:32 +01:00
unimportant
This commit is contained in:
parent
9353aba013
commit
b6fce28d11
@ -3,7 +3,7 @@
|
||||
--Written by Cosmin Apreutesei. Public domain.
|
||||
--Original code by Yichun Zhang (agentzh). BSD license.
|
||||
|
||||
if not ... then require'mysql_client_test'; return end
|
||||
if not ... then require'mysql_test'; return end
|
||||
|
||||
local ffi = require'ffi'
|
||||
local bit = require'bit'
|
||||
@ -973,7 +973,7 @@ local function recv_field_packets(self, field_count, field_attrs, opt)
|
||||
local typ, buf = recv_packet(self)
|
||||
checkp(self, typ == 'DATA', 'bad packet type')
|
||||
local field = get_field_packet(buf)
|
||||
field.to_lua = to_lua or (field.type == 'number' and tonum or nil)
|
||||
field.mysql_to_lua = to_lua or (field.type == 'number' and tonum or nil)
|
||||
field.index = i
|
||||
fields[i] = field
|
||||
fields[field.name] = field
|
||||
@ -1023,10 +1023,10 @@ function mysql.connect(opt)
|
||||
return opt
|
||||
end
|
||||
|
||||
local host = opt.host
|
||||
local host = opt.host or '127.0.0.1'
|
||||
local port = opt.port or 3306
|
||||
|
||||
mysql.note('connect', 'host=%s:%s user=%s db=%s',
|
||||
mysql.note('connect', '%s:%s user=%s db=%s',
|
||||
host, port, opt.user or '', opt.db or '')
|
||||
|
||||
local tcp = opt and opt.tcp or require'sock'.tcp
|
||||
@ -1113,7 +1113,7 @@ conn.connect = protect(conn.connect)
|
||||
|
||||
function conn:close()
|
||||
if self.state then
|
||||
mysql.note('close', 'host=%s:%s', self.host, self.port)
|
||||
mysql.note('close', '%s:%s', self.host, self.port)
|
||||
local buf = send_buffer(1)
|
||||
set_u8(buf, COM_QUIT)
|
||||
send_packet(self, buf)
|
||||
@ -1230,7 +1230,7 @@ local function read_result(self, opt)
|
||||
else
|
||||
checkp(self, false, 'unsupported param type %s', bt)
|
||||
end
|
||||
local to_lua = col.to_lua
|
||||
local to_lua = col.mysql_to_lua
|
||||
if to_lua then
|
||||
v = to_lua(v, col)
|
||||
end
|
||||
@ -1249,7 +1249,7 @@ local function read_result(self, opt)
|
||||
for i, col in ipairs(cols) do
|
||||
local v = get_str(buf)
|
||||
if v ~= nil then
|
||||
local to_lua = col.to_lua
|
||||
local to_lua = col.mysql_to_lua
|
||||
if to_lua then
|
||||
v = to_lua(v, col)
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
|
||||
## `local mysql = require'mysql_client'`
|
||||
## `local mysql = require'mysql'`
|
||||
|
||||
MySQL client protocol in Lua. Ripped from OpenResty, modified to work with
|
||||
[sock], added prepared statements, better interpretation of field metadata
|
||||
@ -9,7 +9,7 @@ changes.
|
||||
## Example
|
||||
|
||||
```lua
|
||||
local mysql = require'mysql_client'
|
||||
local mysql = require'mysql'
|
||||
|
||||
assert(mysql.connect{
|
||||
host = '127.0.0.1',
|
||||
@ -93,7 +93,7 @@ The `options` arg can contain:
|
||||
* `field_attrs = {name -> attr}` -- extra field attributes. It can also be
|
||||
a function which will be called as `field_attrs(cn, fields, opt)`
|
||||
as soon as field metadata is received but before rows are received
|
||||
(so you can even set a custom `to_lua` for particular fields).
|
||||
(so you can even set a custom `mysql_to_lua` for particular fields).
|
||||
|
||||
For queries that return a result set, it returns an array of rows.
|
||||
For other queries it returns a Lua table with information such as
|
||||
@ -115,8 +115,9 @@ if MySQL does not return them.
|
||||
__NOTE:__ Decimals with up to 15 digits of precision and 64 bit integers
|
||||
are converted to Lua numbers by default. That limits the useful range of
|
||||
integer types to 15 significant digits. If you have other needs, provide
|
||||
your own `to_lua` (which you can set at module or connection level, and even
|
||||
per query with `field_attrs`).
|
||||
your own `to_lua` (which you can set at module or connection level,
|
||||
per query in `field_attrs`, or in a [schema] column definition with
|
||||
the `mysql_to_lua` attribute).
|
||||
|
||||
### `cn:query(query, [options]) -> res,nil,cols | nil,err,errcode,sqlstate`
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
local mysql = require'mysql_client'
|
||||
local mysql = require'mysql'
|
||||
local sock = require'sock'
|
||||
local pp = require'pp'
|
||||
require'$'
|
Loading…
Reference in New Issue
Block a user