This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Add a text as variable in a SQL query
#4
(18.06.2024, 12:16)admin Wrote: Try this:
Code:
nameparam = dbcon:escape('NameX')
valueparam = 1000

dbcon:execute("INSERT INTO test (name, value) VALUES ('" .. nameparam .. "', " .. valueparam .. ")")

Hi again, I'm sorry for bothering again, but I dont understand how the " and single ' works formating the text.

I need to add more text fields, and I tried to copy or understand the format but the query responds with:

-----------------------------------
string: LuaSQL: error executing query. MySQL: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'kWh Calor', kike', 1000)
-----------------------------------


and the script:


-------------------------------------------------------------------------
require('luasql.mysql')
require('json')
http = require('socket.http')
env = luasql.mysql()

dbcon, err = env:connect('knx', 'root','123123', '192.168.6.19', '3306')
log(dbcon, err)


dbcon:execute('SET NAMES utf8')


instalacion_param = dbcon:escape('Building_1')
medida_param = dbcon:escape('P1_2A kWh Calor')
usuario_param = dbcon:escape('kike')
valor_param = 1000

log(dbcon:execute("INSERT INTO test2 (instalacion, medida, usuario, valor) VALUES ('" .. instalacion_param .. "', " .. medida_param .. "', " .. usuario_param .. "', " .. valor_param .. ")"))
-------------------------------------------------------------------------

What's the difference beetween " and ' dealing with test format in this case? Is there any manual or tip abouts this issue?

Thanks in advance!!
Reply


Messages In This Thread
RE: Add a text as variable in a SQL query - by kike - 19.06.2024, 10:54

Forum Jump: