mob/proc/insert_table()
set background=1
var/dbConnection/connector = new()
var/dbconnection=connector.getConnection(connector.getDbi())
if(dbconnection)
var/Guide/G=new/Guide
G.load(src.clan,src.slots[currentguide])// loads the guide
var/DBQuery/resultset1 = connector.runQuery(dbconnection,"INSERT INTO `GOAHelper` (ckey, name) VALUES('[ckey]','[G.name]')")
if(resultset1)
if(debug) src << "Phase1: Okay"
resultset1.Close(); //free up and erase data.
else
resultset1.Close();
if(debug) src << "Failed.";
//INITIATE THE GUIDE
spawn()
var/DBQuery/resultset2 = connector.runQuery(dbconnection,"UPDATE GOAHelper SET clan='[G.clan]', date='[G.date]', description='[G.description]', views='[G.views]' WHERE name='[G.name]' AND ckey='[G.owner]'")
if(resultset2)
if(debug) src << "Phase2: Okay"
resultset2.Close(); //free up and erase data.
else
resultset2.Close();
if(debug) src << "Failed.";
spawn()
var/DBQuery/resultset3 = connector.runQuery(dbconnection,"UPDATE GOAHelper SET likes='[G.likes]', creator='[G.creator]', descr='[G.descr]' WHERE name='[G.name]' AND ckey='[G.owner]'")
if(resultset3)
if(debug) src << "Phase3: Okay"
resultset3.Close(); //free up and erase data.
else
resultset3.Close();
if(debug) src << "Failed.";
spawn()
var/DBQuery/resultset4 = connector.runQuery(dbconnection,"UPDATE GOAHelper SET pros='[G.pros]', cons='[G.cons]', skillpoints='[G.skillpoints]' WHERE name='[G.name]' AND ckey='[G.owner]'")
if(resultset4)
if(debug) src << "Phase4: Okay"
resultset4.Close(); //free up and erase data.
else
resultset4.Close();
if(debug) src << "Failed.";
spawn()
var/DBQuery/resultset5 = connector.runQuery(dbconnection,"UPDATE GOAHelper SET str1='[G.str1]', rfx1='[G.rfx1]', con1='[G.con1]' WHERE name='[G.name]' AND ckey='[G.owner]'")
if(resultset5)
if(debug) src << "Phase5: Okay"
resultset5.Close(); //free up and erase data.
else
resultset5.Close();
if(debug) src << "Failed.";
spawn()
var/DBQuery/resultset6 = connector.runQuery(dbconnection,"UPDATE GOAHelper SET ent1='[G.int1]', lvl1='[G.lvl1]' WHERE name='[G.name]' AND ckey='[G.owner]'")
if(resultset6)
if(debug) src << "Phase6: Okay"
resultset6.Close(); //free up and erase data.
else
resultset6.Close();
if(debug) src << "Failed.";
Version 2:
mob/proc/insert_table2()//updated version 2
set background=1
var/dbConnection/connector = new()
var/dbconnection=connector.getConnection(connector.getDbi())
if(dbconnection)
var/Guide/G=new/Guide
G.load(src.clan,src.slots[currentguide])// loads the guide
var/DBQuery/resultset1 = connector.runQuery(dbconnection,"INSERT INTO `GOAHelper` (ckey, name) VALUES('[ckey]','[G.name]')")
if(resultset1)
if(debug) src << "Phase1: Okay"
resultset1.Close(); //free up and erase data.
else
resultset1.Close();
if(debug) src << "Failed.";
//INITIATE THE GUIDE
var/SQLQuery
SQLQuery+="\"UPDATE GOAHelper SET clan='[G.clan]', date='[G.date]', description='[G.description]', views='[G.views]'"
SQLQuery+="SET likes='[G.likes]', creator='[G.creator]', descr='[G.descr]'"
SQLQuery+="SET pros='[G.pros]', cons='[G.cons]', skillpoints='[G.skillpoints]'"
SQLQuery+="SET str1='[G.str1]', rfx1='[G.rfx1]', con1='[G.con1]'"
SQLQuery+="SET ent1='[G.int1]', lvl1='[G.lvl1]' WHERE name='[G.name]' AND ckey='[G.owner]'\""
var/DBQuery/resultset2 = connector.runQuery(dbconnection,SQLQuery)
if(resultset2)
if(debug) src << "Phase2: Okay"
resultset2.Close(); //free up and erase data.
else
resultset2.Close();
if(debug) src << "Failed.";
Problem description:
I am Having an issue with my mysql setup. The ugly code(version 1) works perfectly and uploads all the information needed. However it is ugly, and I wouldn't dream of porting that to my multiplaer project. I have tried to streamline the code abit and do things more efficiently in version 2, however when that query is run, only the first 3 fields are uploaded to the server. The rest remain as null.
Which is the reason I resorted to version 1 in the first place so I could break the query into small bite sizes that can get uploaded.
Row 1: compressed code(version 2)
Row 2: ugly code(version 1)
I am using Dantom's Library, and someone else's mysql demo, when I find the name I will give credit. If anyone can give me some insight on how to make more robust queries, I would be grateful.
Thanks
Are you intending to use 'SET' repeatedly?