Loading...   


DROP VIEW IF EXISTS `vwBotCharacterMobs`;
CREATE VIEW `vwBotCharacterMobs` AS
select _utf8'C' AS `mobtype`,
`c`.`id` AS `id`,
`c`.`name` AS `name`,
`c`.`class` AS `class`,
`c`.`level` AS `level`,
`c`.`last_login` AS `timelaston`,
`c`.`zone_id` AS `zoneid` 
from `character_data` `c` 
union all 
select _utf8'B' AS `mobtype`,
`b`.`BotID` AS `id`,
`b`.`Name` AS `name`,
`b`.`Class` AS `class`,
`b`.`BotLevel` AS `level`,
0 AS `timelaston`,
0 AS `zoneid` 
from `bots` `b`;

DELIMITER $$

DROP FUNCTION IF EXISTS `GetMobType` $$
CREATE FUNCTION `GetMobType` (mobname VARCHAR(64)) RETURNS CHAR(1)
BEGIN
    DECLARE Result CHAR(1);

    SET Result = NULL;

    IF (select count(*) from character_data where name = mobname) > 0 THEN
      SET Result = 'C';
    ELSEIF (select count(*) from bots where Name = mobname) > 0 THEN
      SET Result = 'B';
    END IF;

    RETURN Result;
END $$

DELIMITER ;


DROP VIEW IF EXISTS `vwGroups`;
CREATE VIEW `vwGroups` AS
  select g.groupid as groupid,
GetMobType(g.name) as mobtype,
g.name as name,
g.charid as mobid,
ifnull(c.level, b.BotLevel) as level
from group_id as g
left join character_data as c on g.name = c.name
left join bots as b on g.name = b.Name;

DROP VIEW IF EXISTS `vwBotGroups`;
CREATE VIEW `vwBotGroups` AS
select g.BotGroupId,
g.BotGroupName,
g.BotGroupLeaderBotId,
b.Name as BotGroupLeaderName,
b.BotOwnerCharacterId,
c.name as BotOwnerCharacterName
from botgroup as g
join bots as b on g.BotGroupLeaderBotId = b.BotID
join character_data as c on b.BotOwnerCharacterID = c.id
order by b.BotOwnerCharacterId, g.BotGroupName;

Raw Paste Data