How to check if result of request to DB is empty?

Suliman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 11 23:44:40 PST 2015


>> string query_string = (`SELECT user, password FROM 
>> otest.myusers where
>> user LIKE ` ~ `'%` ~ request["username"].to!string ~ `%';`);
>
> Don't piece queries together without escaping the dynamic 
> parts. Imagine what happens when the user enters an apostrophe 
> in the username field.

Do you mean to wrap:
  request["username"].to!string
in quotes?


> Also, are you using LIKE when authenticating the user? O_O

Yes, my issue :)


>> How I can check if SQL request returned empty result?
>
> When the result is empty, then rs.next() returns false on the 
> first call, I presume.

SO I can wrap it in `if`? Like: `if(rs.next())` ?



More information about the Digitalmars-d-learn mailing list