· 4 years ago · Jul 04, 2021, 07:38 PM
1public async static Task<Boolean> CheckTableExists(MySqlConnection Conn)
2 {
3 String query = "CREATE TABLE IF NOT EXISTS `player` ";
4 Boolean flag = false;
5
6 query = $"{query} (accno INT(11) NOT NULL AUTO_INCREMENT, name VARCHAR(128) NOT NULL DEFAULT '', password VARCHAR(256) NOT NULL DEFAULT '', admin INT(2) NOT NULL DEFAULT '0', arrested INT(11) NOT NULL DEFAULT '0',";
7 query = $"{query} kills INT(11) NOT NULL DEFAULT '0', bankcash INT(11) NOT NULL DEFAULT '10000', crimescommited INT(11) NOT NULL DEFAULT '0',";
8 query = $"{query} death INT(11) NOT NULL DEFAULT '0', dimension INT(11) NOT NULL DEFAULT '0', isbanned INT(2) NOT NULL DEFAULT '0',";
9 query = $"{query} level INT(11) NOT NULL DEFAULT '1', phonenumber INT(11) NOT NULL DEFAULT '0', playinghours INT(11) NOT NULL DEFAULT '0', heading FLOAT NOT NULL DEFAULT '-19.084805',";
10 query = $"{query} respect INT(11) NOT NULL DEFAULT '0', spawnx DOUBLE NOT NULL DEFAULT '-427.52097', spawny DOUBLE NOT NULL DEFAULT '1116.4626', spawnz DOUBLE NOT NULL DEFAULT '326.74954',";
11 query = $"{query} cash INT(11) NOT NULL DEFAULT '2000', master INT(11) NOT NULL DEFAULT '0', UNIQUE(name), PRIMARY KEY(accno));";
12
13 if (IsConnected)
14 {
15 using (Conn)
16 {
17 MySqlCommand command = new MySqlCommand(query, Conn);
18 int count = 0;
19 count = await command.ExecuteNonQueryAsync();
20
21 if(count > 0)
22 {
23 Functions.LogConsole($"{count} table was successfully created.");
24 flag = false;
25 }
26
27 query = "CREATE TABLE IF NOT EXISTS `master`";
28 query = $"{query} ( id INT(11) NOT NULL AUTO_INCREMENT, name VARCHAR(128) NOT NULL DEFAULT '',";
29 query =
30 $"{query}banned INT(2) NOT NULL DEFAULT '0', password VARCHAR(256) NOT NULL DEFAULT '', email VARCHAR(128) NOT NULL DEFAULT '', PRIMARY KEY(id) );";
31
32 command = new MySqlCommand(query, Conn);
33 count = 0;
34
35 count = await command.ExecuteNonQueryAsync();
36
37 if (count > 0)
38 {
39 Functions.LogConsole($"{count} table was successfully created.");
40 flag = false;
41 }
42 }
43 }
44
45 return flag;
46 }