lua-resty-mysql icon indicating copy to clipboard operation
lua-resty-mysql copied to clipboard

The document of *query* is misleading

Open FrancisHe opened this issue 9 years ago • 2 comments

bytes, err = db:send_query(query)
res, err, errcode, sqlstate = db:read_result()
res, err, errcode, sqlstate = db:read_result(nrows)

res, err, errcode, sqlstate = db:query(query)
res, err, errcode, sqlstate = db:query(query, nrows)

db:query() may return 2 values, if we access the 3rd return value, we may get nil, but we expect errcode.

FrancisHe avatar Jul 22 '16 13:07 FrancisHe

@FrancisHe The errcode is the error code returned by the MySQL server, so when there is a lower level failure on the wire (like timeout or connection aborts), then there surely is no error code returned. There's no guarantee that an error code is always returned upon any kind of failures.

agentzh avatar Jul 22 '16 17:07 agentzh

@agentzh I mean that it's better to point that there query() may return only 2 values(not always 4) in the document. The document of read_result() is much better:

Note that, the errcode and sqlstate might be nil if MySQL does not return them.

FrancisHe avatar Jul 23 '16 05:07 FrancisHe