Example #1
0
 public static void createDatabase(String string) {
   ConfigManager.reloadConfig();
   MySQLConfig msqlc2 = ConfigManager.getMySQLConfig();
   (new SQLQuery("CREATE DATABASE IF NOT EXISTS £;", msqlc2)).excecuteUpdate();
   (new SQLQuery(
           "CREATE TABLE IF NOT EXISTS £.`locations` (`id` int(11) NOT NULL AUTO_INCREMENT, `world` varchar(45) NOT NULL, `chunkx` int(11) NOT NULL, `chunkz` int(11) NOT NULL, `x` int(11) NOT NULL,  `y` int(11) NOT NULL, `z` int(11) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1",
           msqlc2))
       .excecuteUpdate();
   (new SQLQuery(
           "CREATE TABLE IF NOT EXISTS £.`gods` (`idGod` int(11) NOT NULL AUTO_INCREMENT, `champ` varchar(45) DEFAULT NULL, `Descrizione` varchar(45) DEFAULT NULL, `lastActivated` date DEFAULT NULL, PRIMARY KEY (`idGod`)) ENGINE=InnoDB DEFAULT CHARSET=latin1",
           msqlc2))
       .excecuteUpdate();
   (new SQLQuery(
           "CREATE TABLE IF NOT EXISTS £.`followers` (`id` int(11) NOT NULL AUTO_INCREMENT,`follower` varchar(45) NOT NULL,`reputation` int(11) NOT NULL, `points` int(11) NOT NULL,`god` int(11) NOT NULL,`lastpray` date DEFAULT NULL, `lastheal` date DEFAULT NULL, `priest` binary NOT NULL DEFAULT FALSE,PRIMARY KEY (`id`),KEY `FollowerGod_idx` (`god`),CONSTRAINT `FollowerGod` FOREIGN KEY (`god`) REFERENCES £.`gods` (`idGod`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1",
           msqlc2))
       .excecuteUpdate();
   (new SQLQuery(
           "CREATE TABLE IF NOT EXISTS £.`altar`(`id` int(11) NOT NULL AUTO_INCREMENT, `god` int(11) NOT NULL,`type` varchar(20) NOT NULL, `location` int(11) NOT NULL, `owner` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `FK_god_idx` (`god`), KEY `FK_location_altar_idx` (`location`), KEY `FK_priest_idx`(`priest`), CONSTRAINT `FK_god` FOREIGN KEY (`god`) REFERENCES £.`gods` (`idGod`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_location_altar` FOREIGN KEY (`location`) REFERENCES £.`locations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FK_priest` FOREIGN KEY (`owner`) REFERENCES £.`followers` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1;",
           msqlc2))
       .excecuteUpdate();
   (new SQLQuery(
           "CREATE TABLE IF NOT EXISTS £.`nonnatural` (`id` int(11) NOT NULL AUTO_INCREMENT, `location` int(11) NOT NULL,`dayPlaced` date NOT NULL, PRIMARY KEY (`id`),KEY `FK_loc_idx` (`location`),CONSTRAINT `FK_loc` FOREIGN KEY (`location`) REFERENCES £.`locations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1",
           msqlc2))
       .excecuteUpdate();
   (new SQLQuery(
           "CREATE TABLE IF NOT EXISTS £.`thrones` (`god` int(11) NOT NULL,`hasThrone` tinyint(1) NOT NULL, `location` int(11) DEFAULT NULL,PRIMARY KEY (`god`), KEY `fkgod_idx` (`god`), KEY `fklocation_idx` (`location`), CONSTRAINT `fkgod` FOREIGN KEY (`god`) REFERENCES £.`gods` (`idGod`) ON DELETE NO ACTION ON UPDATE NO ACTION,  CONSTRAINT `fklocation` FOREIGN KEY (`location`) REFERENCES £.`locations` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=latin1",
           msqlc2))
       .excecuteUpdate();
   msqlc = msqlc2;
   for (int i = 1; i < 5; i++) {
     (new SQLQuery("insert into £.gods(descrizione) values ('desc')", msqlc)).excecuteUpdate();
     (new SQLQuery("insert into £.thrones(god,hasthrone) values (" + i + ",0)", msqlc))
         .excecuteUpdate();
   }
 }