Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The return value of query #48

Open
Kherrisan opened this issue Aug 3, 2016 · 5 comments
Open

The return value of query #48

Kherrisan opened this issue Aug 3, 2016 · 5 comments

Comments

@Kherrisan
Copy link

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

@agentzh
Copy link
Member

agentzh commented Aug 4, 2016

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

@wowxunyl
Copy link

How do I know whether the result set is empty?

@agentzh
Copy link
Member

agentzh commented Apr 10, 2017

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

@wowxunyl
Copy link

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' 

@agentzh
Copy link
Member

agentzh commented Apr 10, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants