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

The return value of query

Open Kherrisan opened this issue 9 years ago • 5 comments

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 :)

Kherrisan avatar Aug 03 '16 14:08 Kherrisan

@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.

agentzh avatar Aug 04 '16 05:08 agentzh

How do I know whether the result set is empty?

wowxunyl avatar Apr 10 '17 05:04 wowxunyl

@wowxunyl You'll get an empty table for that.

agentzh avatar Apr 10 '17 05:04 agentzh

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 avatar Apr 10 '17 06:04 wowxunyl

@wowxunyl Maybe you mysql client is trying to do something clever. Not sure. This library just outputs whatever from the mysqld server responses.

agentzh avatar Apr 10 '17 06:04 agentzh