Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local oldprint = print;
- P = "";
- --Overwrite print with a print that stores the text in a variable instead
- --We can retrive this variable in nwn later
- function print (val1, val2)
- P = P .. tostring(val1);
- if val2 ~= nil then
- P = P .. " " .. tostring(val2);
- end
- P = P .. "\n";
- end
- --Define test globally
- function test()
- --Start a timer
- local timer = Timer.New();
- timer:Start();
- local server = "10.9.23.254";
- local user = "lua";
- local password = "Kah9LpSp9UEZA6qf";
- local db = user;
- local port = 3306;
- --connect to DB with above credentials
- local sql = MySQL.Connect(server,user,password,db,port);
- if(sql == nil)then
- print("Unable to connect to database");
- else
- print("Connection OK");
- --Select our gff from the database
- sql:Query("SELECT Data FROM test WHERE Name='Test';");
- if not sql:Fetch() then
- print("Unable to fetch data");
- end
- --Get the row by index and deserialize the gff into tables
- local gff = sql:GetRow(1);
- local bic = GFF.OpenString(gff);
- --Find FirstName in the topstruct and print it
- for n=1,#bic.Fields do
- if bic.Fields[n].Label == "FirstName" then
- print("First Name: " .. bic.Fields[n].Data.Strings[1].String);
- break;
- end
- end
- --Find Cha in the topstruct and print the current and increment it by 1
- for n=1,#bic.Fields do
- if bic.Fields[n].Label == "Cha" then
- print("Charisma: " .. bic.Fields[n].Data);
- bic.Fields[n].Data = bic.Fields[n].Data + 1;
- break;
- end
- end
- --Serialize the gff back into a string, encode it for sql and save
- print(sql:Query("UPDATE test SET Data="..sql.EncodeString(GFF.SaveToString(bic)).." WHERE Name='Test';"));
- end
- --Stop timer and print the time it took
- timer:Stop();
- print("SQL + GFF took "..tostring(timer:Elapsed()).." ms");
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement