Log the value of "type(res)" to make sure you expect a null value or a string with 0 characters. I think the resulting variable "res", in case of error, is something in the lines of "ngx.null", but I'm not sure ("ngx.null" will have type "object"). This happens with Redis, because "ngx.null" can be a value in an array, whereas Lua's "nil" can't be.
zzhihua114@gmail.com wrote:
And I compare "#res" with zero instead to implement the same target.
在 2018年10月12日星期五 UTC+8上午11:51:30,zzhih...@gmail.com写道:
here is my table in mysql:
tmp.png
my query code:
||
||
--query
localquery_str ="select st
atus from buystatus where
uid='"..message["uid"].."'";
ngx.log(ngx.NOTICE,"query string: ",query_str);
localres,err,errno,sqlstate =db:query(query_str);
ifnotres then
insert_str ="insert into buystatus
values('"..message["uid"].."',"..message["status"]..")";
ngx.log(ngx.ERR,"insert string: ",insert_str);
&nb
sp; db:query(insert_str);
localmsg ={};
msg["code"]=200;
msg["msg"]="Insert a new record success.";
to_send=cjson.encode(msg);
ngx.say(to_send);
return
end
&nbs
p; update_str ="update buystatus set
status="..message["status"].." where uid='"..message["uid"].."'";
db:query(update_str)
when I search a record uid is u888, then my code will execute
UPDATE part rather than INSERT part..