• Sql problem
    14 replies, posted
Hi guys, I have a problem in general created a table and decided to make her anything but any attempt returned false, here's an example of my code [CODE]sql.Query("CREATE TABLE IF NOT EXISTS autoulxz('id' INTEGER NOT NULL, 'idsteam' TEXT NOT NULL , 'nickname' TEXT NOT NULL , 'time' TEXT NOT NULL, 'group' TEXT NOT NULL, PRIMARY KEY('id'));") sql.Query("INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES(NULL, ".. sql.SQLStr(newuser:SteamID()) ..", ".. sql.SQLStr(newuser:Nick()) ..", ".. sql.SQLStr(args[2]) ..", ".. sql.SQLStr(args[3]) ..");") [/CODE] Tell me what to do?
How about giving us the error it gives you
Nope nothing at all errors as if everything runs but nothing appears
print( sql.LastError() )
near "group":syntax error
Which of the queries gave that error?
last which group [CODE]near "group": syntax error near "group": syntax error near "group": syntax error near "group": syntax error sql.Query("INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES(NULL, ".. sql.SQLStr(newuser:SteamID()) ..", ".. sql.SQLStr(newuser:Nick()) ..", ".. sql.SQLStr(args[2]) ..", ".. sql.SQLStr(args[3]) ..");") [U]".. sql.SQLStr(args[3]) .."[/U] [/CODE]
I need you to give me the exact string of the query [lua]local query = "INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES(NULL, ".. sql.SQLStr(newuser:SteamID()) ..", ".. sql.SQLStr(newuser:Nick()) ..", ".. sql.SQLStr(args[2]) ..", ".. sql.SQLStr(args[3]) ..");" print( query )[/lua]
Output:[CODE]INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES(NULL, "STEAM_0:1: 19744995", "LostOne", "12", "superadmin");[/CODE]
Well first of all you're inserting NULL into a 'NOT NULL' primary key field. Second, you're using double quotes instead of single quotes.
Right now, try The problem remains [CODE] Code:_ sql.Query('INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES('..newuser:UniqueID()..', '.. sql.SQLStr(newuser:SteamID()) ..', '.. sql.SQLStr(newuser:Nick()) ..', '.. sql.SQLStr(args[2]) ..', '.. sql.SQLStr(args[3]) ..');') local query = 'INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES('..newuser:UniqueID()..', '.. sql.SQLStr(newuser:SteamID()) ..', '.. sql.SQLStr(newuser:Nick()) ..', '.. sql.SQLStr(args[2]) ..', '.. sql.SQLStr(args[3]) ..');' print( query ) print( sql.LastError() ) OutPut: INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES(3560436323, "STEA M_0:1:19744995", "LostOne", "12", "superadmin"); near "group": syntax error [/CODE]
You changed the Lua quotes into single-quotes, that's not what I meant. The output [code]INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES(3560436323, "STEA M_0:1:19744995", "LostOne", "12", "superadmin");[/code] Should be [code]INSERT INTO autoulxz (id, idsteam, nickname,time,group) VALUES(3560436323, 'STEA M_0:1:19744995', 'LostOne', '12', 'superadmin')[/code]
I do not know how?
[lua]local search = { "\\x00", "\n", "\r", "\\", "'", "\\x1a" } local replace = { "\\\\x00", "\\n", "\\r", "\\\\", "''", "\\\\x1a" } function sql.Escape( str ) if not str then return "" end for k, v in pairs( search ) do str = string.gsub( str, v, replace[k] ) end return str end sql.Query( "CREATE TABLE IF NOT EXISTS autoulxz ( id INT NOT NULL PRIMARY KEY, idsteam VARCHAR(32) NOT NULL, nickname VARCHAR(64) NOT NULL, time VARCHAR(32) NOT NULL, group VARCHAR(64) NOT NULL )") sql.Query( "INSERT INTO autoulxz ( id, idsteam, nickname, time, group ) VALUES ( '" .. newuser:UniqueID() .. "', '" .. newuser:SteamID() .. "', '" .. sql.Escape( newuser:Nick() ) .. "', '" .. sql.Escape( args[2] ) .. "', '" .. sql.Escape( args[3] ) .. "' )" )[/lua] Try that
After that, other addons were screaming. [CODE]master/lua/sv_player_extension.lua:273 3. fn - addons/pointshop-master/lua/sh_pointshop.lua:130 4. unknown - addons/ulib/lua/ulib/shared/hook.lua:168 [ERROR] addons/pointshop-master/lua/sv_player_extension.lua:269: attempt to index field 'PS_Items' (a nil value) 1. PS_HasItem - addons/pointshop-master/lua/sv_player_extension.lua:269 2. PS_HasItemEquipped - addons/pointshop-[/CODE] [editline]18th June 2013[/editline] [CODE]OutPut: INSERT INTO autoulxz ( id, idsteam, nickname, time, group ) VALUES ( '3560436323', 'STEAM_0:1:19744995', 'LostOne', '12', 'superadmin' ) near "group": syntax error П [/CODE] [editline]18th June 2013[/editline] a stop stop this error [CODE]INSERT INTO autoulxq ( id, idsteam, nickname, time ) VALUES ( '3560436323', 'STEAM_0:1:19744995', 'LostOne', '12', 'superadmin' ) 5 values for 4 columns П[/CODE]
Sorry, you need to Log In to post a reply to this thread.