Esempio n. 1
0
        public static Database InitDb(string name)
        {
            IDbConnection idb;

            if (TShock.Config.StorageType.ToLower() == "sqlite")
                idb =
                    new SqliteConnection(string.Format("uri=file://{0},Version=3",
                        Path.Combine(TShock.SavePath, name + ".sqlite")));

            else if (TShock.Config.StorageType.ToLower() == "mysql")
            {
                try
                {
                    var host = TShock.Config.MySqlHost.Split(':');
                    idb = new MySqlConnection
                    {
                        ConnectionString = String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4}",
                            host[0],
                            host.Length == 1 ? "3306" : host[1],
                            TShock.Config.MySqlDbName,
                            TShock.Config.MySqlUsername,
                            TShock.Config.MySqlPassword
                            )
                    };
                }
                catch (MySqlException x)
                {
                    TShockAPI.TShock.Log.Error(x.ToString());
                    throw new Exception("MySQL not setup correctly.");
                }
            }
            else
                throw new Exception("Invalid storage type.");

            var db = new Database(idb);
            return db;
        }
Esempio n. 2
0
        private void OnInitialize(EventArgs args)
        {
            database = Database.InitDb("Statistics");
            tshock = Database.InitDb("tshock");

            var table = new SqlTable("Statistics",
                new SqlColumn("ID", MySqlDbType.Int32) {Unique = true, Primary = true, AutoIncrement = true},
                new SqlColumn("UserID", MySqlDbType.Int32) {Unique = true},
                new SqlColumn("Time", MySqlDbType.Int32),
                new SqlColumn("PlayerKills", MySqlDbType.Int32),
                new SqlColumn("Deaths", MySqlDbType.Int32),
                new SqlColumn("MobKills", MySqlDbType.Int32),
                new SqlColumn("BossKills", MySqlDbType.Int32),
                new SqlColumn("Logins", MySqlDbType.Int32),
                new SqlColumn("MobDamageGiven", MySqlDbType.Int32),
                new SqlColumn("BossDamageGiven", MySqlDbType.Int32),
                new SqlColumn("PlayerDamageGiven", MySqlDbType.Int32),
                new SqlColumn("DamageReceived", MySqlDbType.Int32));

            var table2 = new SqlTable("Highscores",
                new SqlColumn("ID", MySqlDbType.Int32) {Unique = true, Primary = true, AutoIncrement = true},
                new SqlColumn("UserID", MySqlDbType.Int32) {Unique = true},
                new SqlColumn("Score", MySqlDbType.Int32));

            database.EnsureExists(table, table2);

            //database.Import();
        }