unimportant

This commit is contained in:
Cosmin Apreutesei 2021-12-07 14:47:52 +02:00
parent fb5336213d
commit 1a27dad1a6
3 changed files with 18 additions and 32 deletions

View File

@ -999,8 +999,6 @@ local function get_err_packet(buf)
return message, errno, sqlstate return message, errno, sqlstate
end end
local get_collation --fw. decl.
function mysql.log(severity, ...) function mysql.log(severity, ...)
local logging = mysql.logging local logging = mysql.logging
if not logging then return end if not logging then return end
@ -1030,20 +1028,19 @@ 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 collation = 0 --default local collation
if opt.collation ~= 'server' then if opt.collation then
if opt.collation then collation = assert(collation_codes[opt.collation], 'invalid collation')
collation = assert(collation_codes[opt.collation], 'invalid collation') self.collation = opt.collation
self.collation = opt.collation self.charset = self.collation:match'^[^_]+'
self.charset = self.collation:match'^[^_]+' assert(not opt.charset or opt.charset == self.charset, 'supplied charset does not match collation')
elseif opt.charset then elseif opt.charset then
local collation_name = assert(default_collations[opt.charset], 'invalid charset') local collation_name = assert(default_collations[opt.charset], 'invalid charset')
collation = assert(collation_codes[collation_name]) collation = assert(collation_codes[collation_name])
self.charset = opt.charset self.charset = opt.charset
self.collation = collation_name self.collation = collation_name
end
assert(self.collation, 'charset and/or collation required')
end end
assert(self.collation, 'charset or collation required')
check_io(self, tcp:connect(host, port)) check_io(self, tcp:connect(host, port))
@ -1097,10 +1094,6 @@ function mysql.connect(opt)
self.to_lua = mysql.to_lua self.to_lua = mysql.to_lua
self.state = 'ready' self.state = 'ready'
if opt.collation == 'server' then
self.collation, self.charset = get_collation(self)
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.db = opt.db self.db = opt.db
self.user = opt.user self.user = opt.user
@ -1279,12 +1272,6 @@ local function query(self, sql, opt)
end end
conn.query = protect(query) conn.query = protect(query)
--[[local]] function get_collation(self)
local t = query(self, 'select @@collation_connection cl, @@character_set_connection cs')[1]
return t.cl, t.cs
end
conn.get_collation = protect(get_collation)
do do
local function pass(self, db, ret, ...) local function pass(self, db, ret, ...)
if not ret then return nil, ... end if not ret then return nil, ... end

View File

@ -51,10 +51,10 @@ The `options` argument is a Lua table holding the following keys:
* `user`: user name. * `user`: user name.
* `password`: password (optional). * `password`: password (optional).
* `db`: the database to set as current database (optional). * `db`: the database to set as current database (optional).
* `collation`: the collation used for the connection (`charset` is implied by this). * `charset`: the character set used for the connection (required, see below).
* use `'server'` to get the server's collation and charset for the connection. * `collation`: the collation used for the connection (required, see below).
* `charset`: the character set used for the connection. * if only `charset` is given, the default collation for the charset is set automatically.
* if `collation` not set, the default collation for the charset is selected. * if `collation` is given, `charset` is set automatically and must not be supplied.
* `max_packet_size`: the upper limit for the reply packets sent from the server (defaults to 16 MB). * `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 (defaults 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
@ -150,8 +150,7 @@ for which the charset is ASCII or an ASCII superset (ascii, utf8).
### `cn:esc(s) -> s` ### `cn:esc(s) -> s`
Escape string to be used inside SQL string literals. This only works Escape string to be used inside SQL string literals.
if the current collation is known (see `collation` arg on `connect()`).
### Multiple result set support ### Multiple result set support

View File

@ -12,7 +12,7 @@ sock.run(function()
user = 'root', user = 'root',
password = 'root', password = 'root',
db = 'sp', db = 'sp',
collation = 'server', charset = 'utf8mb4',
}) })
assert(conn:query[[ assert(conn:query[[