Lua 插入语句。

我正在遇到我的插入语句的问题:

Create = function (LN,FN,Add,Tel,Cell)
    LastName = tostring(LN);
    FirstName = tostring(FN);
    Address = tostring(Add);
    Telephone =tostring(Tel);
    Cellphone = tostring(Cell);

--问题的源头

conn:execute([[INSERT INTO book(LastName, FirstName, Address, Telephone, Cellphone) VALUES ("]]"'"LastName"','"FirstName"','" Address"','" Telephone"','" Cellphone")]]'")

 print ("\ n 创建帐户成功")
 end
点赞
用户1190388
用户1190388

我建议使用 string.format 来放置数据:

创建 = function (姓氏,名字,地址,电话,手机)
    local 姓, 名, 地址, 电话号码, 手机号码 = tostring(姓氏), tostring(名字), tostring(地址), =tostring(电话), tostring(手机)
    local sQuery = [[INSERT INTO book(LastName, FirstName, Address, Telephone, Cellphone) VALUES ('%s', '%s', '%s', '%s', '%s')]]
    conn:execute( sQuery:format(姓, 名, 地址, 电话号码, 手机号码) )
2014-04-18 09:58:06