I am creating a database for a collection of servers for minecraft, and the way I have it set up, I want a table to be created for each server as it is added. At the moment, I have everything working except for the fact that i cannot get the tables that are being created to contain the IP address. I want the table to be something like [IP]_Players where the [IP] is replaced by the actual IP address, which will be send through the function that it is being created through. Here is what I have so far:
DELIMITER $$
CREATE PROCEDURE `minecraft`.`AddServer` (ip Text)
BEGIN
DECLARE play TEXT;
DECLARE tran TEXT;
SET play = ip + '_Players';
SET tran = ip + '_Transactions';
INSERT INTO `minecraft`.`Server_Data` (`Server_IP`) VALUES (ip);
CREATE TABLE `minecraft`.play (
`Player` TEXT NOT NULL ,
`Balance` DOUBLE NOT NULL DEFAULT 100 ,
`Warnings` INT NOT NULL DEFAULT 0 ,
`Offences` INT NOT NULL DEFAULT 0 ,
UNIQUE INDEX `Player_UNIQUE` (`Player` ASC) );
CREATE TABLE `minecraft`.tran (
`Time` TIMESTAMP NOT NULL ,
`Player` TEXT NOT NULL ,
`Destination` TEXT NOT NULL ,
`Amount` DOUBLE NOT NULL ,
`Description` TEXT NOT NULL ,
PRIMARY KEY (`Time`) );
END
Instead of creating it as 192.168.001.107_Players when
CALL minecraft.AddServer('192.168.001.107');
is preformed, it creates a table called play.
What am I doing wrong?
I was playing around and got this to work. Note that you cannot have periods in a table name. So you may want to use the REPLACE function to replace the periods with underscores for example.