lua-resty-mysql
lua-resty-mysql copied to clipboard
The return value of query
When i tried the query method as the readme said:
res,err,errcode,sqlstate=db:query("select * from account where id="..id..";")The correct query was OK.
And to test the condition of bad result("empty set"),i use an id that does not exits in the MySQL table.However,unexpectedly,the if statement following the query:
if not res thennever excuted,which means res is not nil......
And i tried if not res[1] then,it works as i expected(Though err errcode sqlstate were all nil )
I want to know what's wrong with it :)
@ZouDikai An empty result set is a totally valid result set and no error should get returned. I think you misunderstand the outcome of your SQL query.
How do I know whether the result set is empty?
@wowxunyl You'll get an empty table for that.
The result of sql below is empty in mysql client, but the lua table res deed has key(new_visitor, return_visitor) whose value I print using ngx.log is NULL. I really can't figure out why this happens.
SELECT
sum(new_visitor) as new_visitor,
sum(return_visitor) as return_visitor
FROM analysis_visitor_dist
WHERE
date>='20170408'
AND
date<='20170407'
@wowxunyl Maybe you mysql client is trying to do something clever. Not sure. This library just outputs whatever from the mysqld server responses.