Thread Tools Display Modes
08-30-05, 11:43 PM   #1
inkognito
A Defias Bandit
Join Date: Aug 2005
Posts: 3
Question Saving Data & Transfering to a SQL DB?

Is it possible in some way to store the data collected from your char, like name, race, level, stats, resistances etc to another datafile, than the standard file used when Using ResgisterForSave(); Function?
And, are there any functions that you can use to transfer those data to a SQL database, either through web access or some ODBC connection?
  Reply With Quote
08-30-05, 11:50 PM   #2
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
SavedVariables is it, mostly. You can write stuff to the chat logs, that will be saved when you exit also. But it will be monumentally easier to parse the SavedVariables files themselves.

Make a simple parser to convert the text to a comma-delimeted format and you should have no problem getting it into a SQL database.

By design the UI attempts to stop all interaction with outside programs.
  Reply With Quote
09-01-05, 08:50 AM   #3
farang
A Deviate Faerie Dragon
 
farang's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 19
as a little help, of how to convert such savedvariable.lua easy:

Get the Lua standalone exe.

Create a Lua script ,that uses "print()" to output the resulting data (that script won't work inside wow, just with the lua standalone).

Now you can just capture the output of it, to get for example CSV Format or XML Format out of the original Lua Table data.

of course you can also write code in any programming language that does the converstation.
  Reply With Quote
09-01-05, 09:22 AM   #4
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
yeah grabbing a lua exe is a great route. You can get them at the lua wiki: http://lua-users.org/wiki/LuaBinaries

Best part of using the lua compiler is you can then directly use the tables you make in game (as long as they're saved to SavedVariables)

For instance if you tag a table named GuildRoster to save in SavedVaribles, your offline script can look like this:

dofile("c:\\Program Files\\World of Warcraft\\WTF\\Account\\YourAccountName\\SavedVariables.lua")
f = io.open("guild.out","w")
for i in GuildRoster do
f:write(GuildRoster[i].Name..","..GuildRoster[i].Class..","..GuildRoster[i].Level.."\n")
end
f:close()

And it will create a file called guild.out with a listing of every guild member in GuildRoster (which is a table your mod would create).
  Reply With Quote
09-01-05, 10:50 AM   #5
Devla
A Cobalt Mageweaver
 
Devla's Avatar
AddOn Compiler - Click to view compilations
Join Date: Mar 2005
Posts: 206
Hmm

Yea I've been working on exporting a 'member list' for my guildmaster. Since our DKP system is a bit different than normal, the GM takes note of everyone online after every boss kill. Pen & paper works ok, and may be the only way...since a forced reloadui would be needed to parse any of the data into an external text file.

The setup I have right now is a custom version of the Guild Roster mod that I hacked up. Then, use the java applet at http://rezzed.com/ to parse the data and export it to an html friendly file.

Now, I've been playing with a script to pull this data myself locally using the lua compiler and a batch file. However I can't seem to pull the proper data. Below is the bit from the mod that pulls the data and saves it into SV:

Code:
	for i=1, numGuildMembers do
		name, rank, rankIndex, level, class, zone, group, note, officernote, online = GetGuildRosterInfo(i);
		year, month, day, hour = GetGuildRosterLastOnline(i); 
		
		GuildInfo_GuildRoster[RealmName]["Guild"]["Members"][name] = {};
		GuildInfo_GuildRoster[RealmName]["Guild"]["Members"][name]["Name"] = name; 
		GuildInfo_GuildRoster[RealmName]["Guild"]["Members"][name]["Level"] = level; 
		GuildInfo_GuildRoster[RealmName]["Guild"]["Members"][name]["Class"] = class;
		GuildInfo_GuildRoster[RealmName]["Guild"]["Members"][name]["Note"] = note;
		GuildInfo_GuildRoster[RealmName]["Guild"]["Members"][name]["Online"] = online;
			
		num=i;
	end
And below is a sample of the SV data:

Code:
GuildInfo_GuildRoster = {
["Servername"] = {
		["Guild"] = {
			["NumMembers"] = 12,
			["Name"] = "Blahguild",
			["Members"] = {
				["String"] = {
					["Note"] = "",
					["Name"] = "Blahblah",
					["Class"] = "Warlock",
					["Online"] = 1,
					["Level"] = 29,
				},}
If anyone could help me with the actual code for a compiler script to pull this data, it would be greatly appreciated.

Thanks
__________________
RETIRED Author
  Reply With Quote
09-01-05, 11:29 AM   #6
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
Really this is the entire script you need and the only part to change is the fields in italics and of course the string.format and which bits of data you want:

dofile("c:\\Program Files\\World of Warcraft\\WTF\\Account\\YourAccountName\\SavedVariables.lua")
-- pretend VARIABLES_LOADED just happen. All your Gatherer, LootLink, every mod's tables are now loaded because the dofile actually ran SavedVariables.
f = io.open("guild.out","w") -- open "guild.out" for write access

for i in GuildInfo_GuildRoster["RealmName"]["Guild"]["Members"] do
info = GuildRoster["RealmName"]["Guild"]["Members"]
text = string.format("Name: %s, Class: %s, Level: %d\n",i,info.Class or "",info.Level or 0)
-- pretend f:write is DEFAULT_CHAT_FRAME:AddMessage
f:write(text)
end

f:close() -- close "guild.out"
--

The script runs SavedVariables.lua, so all tables that the mod uses are available to the script. It's just a matter of writing out the information. The above will create a file called guild.out that contains:

Name: Soandso, Class: Priest, Level: 60
Name: Otherperson, Class: Mage, Level: 35
Name: Thatguy, Class: Druid, Level: 58
  Reply With Quote
06-26-06, 09:37 PM   #7
Conradin
A Kobold Labourer
Join Date: Jun 2006
Posts: 1
It looks like you're using the GuildInfo or Guild Roster addon to get the printout. We use that addon too, and I just wrote this php code to parse out the file . As the code is here, it will only print output to the screen, but I have it commented where you should put any calls to a database to INSERT or UPDATE your tables. I should point out that I wrote this code specifically to update a mysql database, so the webpage that displays the guild roster exists elsewhere in the site--this code prepares the info for insertion into the DB.
Best of all, it's a direct step: Copy the GuildRoster.lua file to a location accessible to the code. You don't have to get a lua engine involved


$filepath = ""); //put the relative path to your file inside the quotes, like "../files/uploads/GuildRoster.lua
$fp= fopen($filepath ,'r');
$guildname="AoE,";//put your guild name here **followed by a comma**
if(!$fp)
{
echo "<p> <strong> No lua file available."
."Please try again later.</strong></p></body></html>";
exit;
}

while(!feof($fp))
{
$order=fgets($fp, 100);
$char_array= explode("=",$order);
$element=trim(str_replace('"','',$char_array[0])); //gets rid of the spaces & quotes around data that will compose $element
$attribute =trim(str_replace('"','',$char_array[1])); //gets rid of the spaces & quotes around data that will compose $attribute
$attribute = str_replace(',',"",$attribute);//gets rid of trailing comma after attribute data
if($element=='[Name]' && $attribute != $guildname)
{$currentchar = $attribute;}
if($element=='[Note]' )
{$currentnote = $attribute;}
if($element=='[Zone]' )
{$currentzone = $attribute;}
if($element=='[Class]' )
{$currentclass = $attribute;}
if($element=='[Online]' )
{$currentonline = $attribute;}
if($element=='[RankIndex]' )
{$currentrank = $attribute;}
if($element=='[year]' )
{$currentyear = $attribute;}
if($element=='[month]' )
{$currentmonth = $attribute;}
if($element=='[hour]' )
{$currenthour = $attribute;}
if($element=='[day]' )
{$currentday = $attribute;}
if($element=='[Level]' )
{$currentlevel = $attribute;}
if ($currentonline == 1 ) {$lastonline = "Online during roster snapshot";}
else{
$lastonline = "";
if ($currentyear == 1){$lastonline .="1 year, ";}
if ($currentyear > 1) {$lastonline .=$currentyear." years, "; }
if ($currentmonth == 1){$lastonline .="1 month, ";}
if ($currentmonth > 1) {$lastonline .=$currentmonth." months, ";}
if ($currentday == 1){$lastonline .="1 day, ";}
if ($currentday > 1) {$lastonline .=$currentday." days, ";}
if ($currenthour == 1){$lastonline .="1 hour ";}
if ($currenthour > 1) {$lastonline .=$currenthour." hours ";}
}
if ($element == "[Rank]"){
echo "<BR><BR>Character: $currentchar--Lvl $currentlevel $currentclass.";
echo "Guild Rank=$currentrank. <BR>Last online: $lastonline. Notes: $currentnote";
//if you want to include any interactions with a mysql db regarding this info, run it here, BEFORE the closing bracket of the if statement

}//end of if ($element)
}//closeof while(!feof($fp));
fclose($fp);

Last edited by Conradin : 06-26-06 at 09:49 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Saving Data & Transfering to a SQL DB?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off