• SQL help needed
    5 replies, posted
I would like to make a preemptive thank you to whomever can help me (and all those who try, the effort was appreciated) The function below is not working, and below it I'm going to list the console output, if anyone see's what's wrong, please tell me, as I don't see it [lua] function StartSQL() MsgN("Loading MySQL...\n") if sql.TableExists("rpm_wallets") and sql.TableExists("rpm_bank") and sql.TableExists("rpm_doors") then MsgN("Tables exist..\n") else MsgN("Tables do not exist! Creating...") if !sql.TableExists("rpm_wallets") then local query = "CREATE TABLE rpm_wallets ( steam varchar(20), money int );" local result = sql.Query(query) if !sql.TableExists("rpm_wallets") then MsgN(sql.LastError( result )) else MsgN("rpm_wallets created!") end end if !sql.TableExists("rpm_bank") then local query2 = "CREATE TABLE rpm_bank ( steam varchar(20), items TEXT );" local result2 = sql.Query(query2) if !sql.TableExists("rpm_bank") then MsgN(sql.LastError( result2 )) else MsgN("rpm_bank created!") end end if !sql.TableExists("rpm_doors") then local query3 = "CREATE TABLE rpm_doors ( map varchar(20), entindex int, steam char(20), noown int, title varchar(25) );" local result3 = sql.Query(query3) if !sql.TableExists("rpm_doors") then MsgN(sql.LastError( result3 )) else MsgN("rpm_doors created!") end end if sql.TableExists("rpm_wallets") and sql.TableExists("rpm_bank") and sql.TableExists("rpm_doors") then MsgN("Success! Tables Created") else MsgN("MySQL load error!") end end sql.Commit() end [/lua] [quote] Loading MySQL... Tables do not exist! Creating... table rpm_wallets already exists table rpm_doors already exists MySQL load error! [/quote]
Mysql or Sql? Possible not connected to the database - Either your ip isn't allowed into the remote database Or You have some values wrong. [editline]26th July 2011[/editline] Also you could've done IF NOT EXIST CREATE TABLE rpm_bank
sqlite, the built in module I was just following the sqlite tutorial in the gmod wiki, but you're right
[QUOTE=RetTurtl3;31353080] Also you could've done IF NOT EXIST CREATE TABLE rpm_bank[/QUOTE] I believe its EXISTS not EXIST.
yah, Bee's right, but I still have no idea why it's not working er. put lua tags on the first post rather than code, I had my editor set to basic so I had no idea this bbcode existed! --edit-- I just recoded the function like this [lua] function StartSQL() MsgN("Loading MySQL...\n") local query = "CREATE TABLE IF NOT EXISTS rpm_wallets ( steam varchar(20), money int );" local query2 = "CREATE TABLE IF NOT EXISTS rpm_bank ( steam varchar(20), items TEXT );" local query3 = "CREATE TABLE IF NOT EXISTS rpm_doors ( map varchar(20), entindex int, steam char(20), noown int, title varchar(25) );" sql.Query(query) sql.Query(query2) sql.Query(query3) sql.Commit() if !sql.TableExists("rpm_wallets") or !sql.TableExists("rpm_bank") or !sql.TableExists("rpm_doors") then MsgN("SQL Error!") if !sql.TableExists("rpm_wallets") then MsgN("rpm_wallets is missing!") end if !sql.TableExists("rpm_bank") then MsgN("rpm_bank is missing!") end if !sql.TableExists("rpm_doors") then MsgN("rpm_doors is missing!") end end end [/lua] the wallet and door tables are missing according to this, which were the ones saying they already exist in the previous version??
Deleted sv.db... works fine now /threadclosed :\
Sorry, you need to Log In to post a reply to this thread.