lunarmodules / luasql

LuaSQL is a simple interface from Lua to a DBMS.
http://lunarmodules.github.io/luasql
539 stars 191 forks source link

Cant use variables in mySQL Query #23

Closed silverdeath200282 closed 9 years ago

silverdeath200282 commented 9 years ago

I'm trying to use a variable in the Where = field of the SQL Query. With the code below, it says expecting a ) near test. When I try to change it to: WHERE firstname = '"..test.."'"), I get "attempt to concatenate a nil value"

Can someone tell me if this is a bug or just the wrong syntax? Thanks


local test = Gyovo

local env = luasql.mysql() local con = env:connect("db_name","root","password","localhost","3306") cur = con:execute("SELECT name FROM characters WHERE firstname = '"test"'") row = cur:fetch ({}, "a") while row do print(string.format("%s", row.characters))

end cursor:close() conn:close() env:close()

hishamhm commented 9 years ago

It should say local test = "Gyovo"

Note the quotes!

silverdeath200282 commented 9 years ago

Yeah I've tried with or without the quotes. Same thing either way.

hishamhm commented 9 years ago

Your use of quotes seems off. Checking using an editor with syntax highlighting will help.

hishamhm commented 9 years ago

In any case, those are syntax errors in your program, and not a bug in LuaSQL. Closing this entry now, but feel free to ask for help through other channels! (Lua mailing list, IRC channel, etc. - see the Community page in lua.org for details.)