-- query
local query_str = "select status from buystatus where uid='"..message["uid"].."'"; ngx.log(ngx.NOTICE, "query string: ", query_str); local res, err, errno, sqlstate = db:query(query_str); if not res then insert_str = "insert into buystatus values('"..message["uid"].."',"..message["status"]..")"; ngx.log(ngx.ERR, "insert string: ", insert_str); db:query(insert_str); local msg = {}; msg["code"]=200; msg["msg"]="Insert a new record success."; to_send=cjson.encode(msg); ngx.say(to_send); return end
update_str = "update buystatus set status="..message["status"].." where uid='"..message["uid"].."'"; db:query(update_str)
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.
--
You received this message because you are subscribed to the Google
Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to openresty-en...@googlegroups.com
<mailto:openresty-en...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.
<mailto:openresty-en+unsub...@googlegroups.com>.