Originally Posted by rx12network
Is there no way to work with a database? its stupid to work with nonshowed tables.. i saw gathermate for ex. work with a downable database from wowhead.
Some way for better parsing and multicolumtables like sql would be nice for select statements.
|
See
Things Addons/Macros Can't Do. In particular, addons cannot see, read from, or write to any files on the hard disk, so no, it is not possible to work with any kind of "real" database like SQLite.
Addons that use the term "database" refer to data stored in simple Lua tables, including the addon that provides GatherMate with data from Wowhead.
I don't know what you mean by "nonshowed tables", but Lua tables are extremely simple to work with, and there's not really any need for complex SQL statements. It would be easy (though tedious and pointless) to write a wrapper around basic table operations to support SQL statements, but it would be far more effort than just using the basic table operations, so I can't imagine anyone actually doing it.
Finally, if you describe what goal you actually want to accomplish, we can almost certainly be more helpful in showing you the easiest way to achieve that goal.
Anyway, here are some examples that may or may not be helpful; without knowing what you actually want to do, it's pretty hard to tell you the best way to do it.
Lua Code:
-- Main storage table:
local alldata = {}
-- Populate the table:
local function UpdateData()
local numRaidMembers = GetNumRaidMembers()
for i = 1, numRaidMembers do
-- Get info about this raid member:
local name, rank, subgroup, level, className, class, zone, online, isDead, role, isML, combatRole = GetRaidRosterInfo(i)
local chardata
-- Check if data already exists at this index:
if alldata[i] then
-- If so, clear it and reuse the table:
chardata = wipe(alldata[i])
else
-- Otherwise, create a new table:
chardata = {}
end
-- Fill in the table:
chardata.index, chardata.name, chardata.rank, chardata.subgroup, chardata.level, chardata.className, chardata.class, chardata.zone, chardata.online, chardata.dead, chardata.role, chardata.masterLooter, chardata.combatRole = i, name, rank, subgroup, level, className, class, zone, online, isDead, role, isML, combatRole
-- Create or update the data at this index in the main storage table:
alldata[i] = chardata
end
if numRaidMembers < #alldata then
-- Remove data at unused indices:
for i = numRaidMembers + 1, #alldata do
-- It would be more efficient to recycle the tables, but
-- that is beyond the scope of this simple example, so here
-- we will just let the garbage collector handle it:
alldata[i] = nil
end
end
end
-- Update the table each time the raid roster changes:
local frame = CreateFrame("Frame")
frame:RegisterEvent("RAID_ROSTER_UPDATE")
frame:SetScript("OnEvent", UpdateData)
To get information about a character by their name:
Lua Code:
-- Function to return information about the named character:
local function GetCharacterByName(name)
-- Loop through the data at each index:
for i, chardata in ipairs(alldata) do
-- Check the data's name value against the search value:
if chardat.name == name then
-- If it matches, return the character's data table.
return chardata
end
end
end
-- Get information about the character whose name is "Benny":
local Benny = GetCharacterByName("Benny")
if Benny then
print(string.format("%s is a level %d %s in group %d at index %d.", Benny.name, Benny.level, Benny.className, Benny.subgroup, Benny.index))
else
print("Benny is not in the raid.")
end
To get a count of all characters who are rogues:
Lua Code:
-- Function to get a count of all characters with the specified class:
local function GetNumCharactersByClass(class)
local count = 0
for i, chardata in ipairs(alldata) do
if chardata.class == class then
count = count + 1
end
end
return count
end
-- Get a count of all rogues:
print(string.format("There are %d rogues in the raid.", GetNumCharactersByClass("ROGUE")))
To get information about all the characters in group 3:
Lua Code:
-- Function to get information about all characters in a group:
local function GetCharactersByGroup(group)
local results = {}
for i, chardata in ipairs(alldata) do
if chardata.subgroup == group then
tinsert(results, chardata)
end
end
return results
end
-- Get information about group 3:
local group3 = GetCharactersByGroup(3)
if #group3 == 0 then
print("Group 3 is empty!")
else
local names
for i, chardata in ipairs(group3) do
if names then
if i == #group3 then
-- Last name on the list:
names = names .. ", and " .. chardata.name
else
-- Name in the middle of the list:
names = names .. ", " .. chardata.name
end
else
-- First name on the list:
names = chardata.name
end
end
print(string.format("There are %d characters in group 3: %s.", #group3, names))
end