unimportant

This commit is contained in:
Cosmin Apreutesei 2021-09-06 12:28:55 +03:00
parent 5dcd2cadf2
commit c2cae4c1e9
2 changed files with 26 additions and 25 deletions

View File

@ -772,7 +772,7 @@ local function set_str(buf, s)
end end
local function set_token(buf, password, scramble) local function set_token(buf, password, scramble)
if password == '' then if not password or password == '' then
return '' return ''
end end
local stage1 = sha1(password) local stage1 = sha1(password)
@ -931,9 +931,6 @@ function mysql.connect(opt)
self.max_packet_size = opt.max_packet_size or 16 * 1024 * 1024 --16 MB self.max_packet_size = opt.max_packet_size or 16 * 1024 * 1024 --16 MB
local ok, err local ok, err
local database = opt.database or ''
local user = opt.user or ''
local collation = 0 --default local collation = 0 --default
if opt.collation ~= 'server' then if opt.collation ~= 'server' then
if opt.collation then if opt.collation then
@ -988,9 +985,9 @@ function mysql.connect(opt)
set_u32(buf, self.max_packet_size) set_u32(buf, self.max_packet_size)
set_u8(buf, collation) set_u8(buf, collation)
buf(23) buf(23)
set_cstring(buf, user) set_cstring(buf, opt.user or '')
set_token(buf, opt.password or '', scramble) set_token(buf, opt.password, scramble)
set_cstring(buf, database) set_cstring(buf, opt.schema or '')
send_packet(self, buf) send_packet(self, buf)
local typ, buf = recv_packet(self) local typ, buf = recv_packet(self)
@ -1008,6 +1005,8 @@ function mysql.connect(opt)
end end
self.charset_is_ascii_superset = self.charset and not mb_charsets[self.charset] self.charset_is_ascii_superset = self.charset and not mb_charsets[self.charset]
self.schema = opt.schema
self.user = opt.user
return self return self
end end
@ -1336,14 +1335,14 @@ if not ... then --demo
local sock = require'sock' local sock = require'sock'
local pp = require'pp' local pp = require'pp'
sock.run(function() sock.run(function()
local conn = mysql.connect{ local conn = assert(mysql.connect{
host = '127.0.0.1', host = '127.0.0.1',
port = 3307, port = 3307,
user = 'root', user = 'root',
password = 'abcd12', password = 'abcd12',
database = 'sp', schema = 'sp',
collation = 'server', collation = 'server',
} })
print(conn.charset, conn.collation) print(conn.charset, conn.collation)
pp(conn:query'select * from val where val = 1') pp(conn:query'select * from val where val = 1')
local stmt = conn:prepare('select * from val where val = ?') local stmt = conn:prepare('select * from val where val = ?')

View File

@ -12,9 +12,9 @@ local mysql = require'mysql_client'
assert(mysql.connect{ assert(mysql.connect{
host = '127.0.0.1', host = '127.0.0.1',
port = 3306, port = 3306,
database = 'foo',
user = 'bar', user = 'bar',
password = 'baz', password = 'baz',
schema = 'foo',
charset = 'utf8mb4', charset = 'utf8mb4',
max_packet_size = 1024 * 1024, max_packet_size = 1024 * 1024,
}) })
@ -44,20 +44,21 @@ Connect to a MySQL server.
The `options` argument is a Lua table holding the following keys: The `options` argument is a Lua table holding the following keys:
* `host`: the host name for the MySQL server. * `host`: server's IP address (required).
* `port`: the port that the MySQL server is listening on. Default to 3306. * `port`: server's port (optional, defaults to 3306).
* `path`: the path of the unix socket file listened by the MySQL server. * `user`: user name.
* `database`: the MySQL database name. * `password`: password (optional).
* `user`: MySQL account name for login. * `schema`: the schema to set as current schema (optional).
* `password`: MySQL account password for login (in clear text). * `collation`: the collation used for the connection (`charset` is implied by this).
* `collation`: the collation used for the connection (`charset` is implied with this). * use `'server'` to get the server's collation and charset for the connection.
* required if `charset` not given: use `'server'` to get the server's default for the connection. * `charset`: the character set used for the connection.
* `charset`: the character set used for the connection (the default collation for the charset is selected). * if `collation` not set, the default collation for the charset is selected.
* `max_packet_size`: the upper limit for the reply packets sent from the server (default to 1MB). * `max_packet_size`: the upper limit for the reply packets sent from the server (defaults to 16 MB).
* `ssl`: if `true`, then uses SSL to connect to MySQL (default to `false`). * `ssl`: if `true`, then uses SSL to connect to MySQL (defaults to `false`).
If the server does not have SSL support (or just disabled), the error string If the server does not have SSL support (or just disabled), the error string
"ssl disabled on server" will be returned. "ssl disabled on server" is returned.
* `ssl_verify`: if `true`, then verifies the validity of the server SSL certificate (default to `false`). * `ssl_verify`: if `true`, then verifies the validity of the server SSL
certificate (default is `false`).
### `cn:close() -> 1 | nil,err` ### `cn:close() -> 1 | nil,err`
@ -140,7 +141,8 @@ The MySQL server version string.
### `cn:quote(s) -> s` ### `cn:quote(s) -> s`
Quote literal string to be used in queries. Quote literal string to be used in queries. Quoting only works if current
collation is known (ses `collation` arg on `connect()`).
### Multiple result set support ### Multiple result set support