本文整理汇总了C#中TShockAPI.DB.SqlTable类的典型用法代码示例。如果您正苦于以下问题:C# SqlTable类的具体用法?C# SqlTable怎么用?C# SqlTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlTable类属于TShockAPI.DB命名空间,在下文中一共展示了SqlTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitTerraDB
public static void InitTerraDB()
{
string sql = Path.Combine(terraDB);
if (!File.Exists(terraDB))
{
SqliteConnection.CreateFile(terraDB);
}
DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
SQLWriter = new SqlTableCreator(DB, new SqliteQueryCreator());
var table = new SqlTable("Clans",
new SqlColumn("clanname", MySqlDbType.Text) { Unique = true },
new SqlColumn("clangroup", MySqlDbType.Text),
new SqlColumn("leaders", MySqlDbType.Text),
new SqlColumn("members", MySqlDbType.Text),
new SqlColumn("motd", MySqlDbType.Text),
new SqlColumn("invites", MySqlDbType.Text)
);
SQLWriter.EnsureExists(table);
table = new SqlTable("FoundQueue",
new SqlColumn("clanname", MySqlDbType.Text) { Unique = true },
new SqlColumn("founder", MySqlDbType.Text),
new SqlColumn("cofounder", MySqlDbType.Text)
);
SQLWriter.EnsureExists(table);
}
示例2: CheckTables
internal static void CheckTables(IDbConnection connection)
{
SQLWriter = new SqlTableCreator(connection, new MysqlQueryCreator());
var table = new SqlTable("BannedIP",
new SqlColumn("IP", MySqlDbType.Text),
new SqlColumn("BanDate", MySqlDbType.Int32),
new SqlColumn("UnbanDate", MySqlDbType.Int32),
new SqlColumn("BannedBy", MySqlDbType.Text),
new SqlColumn("Reason", MySqlDbType.Text)
);
SQLWriter.EnsureExists(table);
table = new SqlTable("BannedPlayer",
new SqlColumn("Player", MySqlDbType.Text),
new SqlColumn("BanDate", MySqlDbType.Int32),
new SqlColumn("UnbanDate", MySqlDbType.Int32),
new SqlColumn("BannedBy", MySqlDbType.Text),
new SqlColumn("Reason", MySqlDbType.Text)
);
SQLWriter.EnsureExists(table);
table = new SqlTable("MutedPlayer",
new SqlColumn("Player", MySqlDbType.Text),
new SqlColumn("MuteDate", MySqlDbType.Int32),
new SqlColumn("UnmuteDate", MySqlDbType.Int32),
new SqlColumn("MutedBy", MySqlDbType.Text),
new SqlColumn("Reason", MySqlDbType.Text)
);
SQLWriter.EnsureExists(table);
}
示例3: GroupManager
public GroupManager(IDbConnection db)
{
database = db;
var table = new SqlTable("GroupList",
new SqlColumn("GroupName", MySqlDbType.VarChar, 32) {Primary = true},
new SqlColumn("Parent", MySqlDbType.VarChar, 32),
new SqlColumn("Commands", MySqlDbType.Text),
new SqlColumn("ChatColor", MySqlDbType.Text),
new SqlColumn("Prefix", MySqlDbType.Text),
new SqlColumn("Suffix", MySqlDbType.Text)
);
var creator = new SqlTableCreator(db,
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureExists(table);
//Add default groups
AddGroup("guest", "canbuild,canregister,canlogin,canpartychat,cantalkinthird");
AddGroup("default", "guest", "warp,canchangepassword");
AddGroup("newadmin", "default", "kick,editspawn,reservedslot");
AddGroup("admin", "newadmin",
"ban,unban,whitelist,causeevents,spawnboss,spawnmob,managewarp,time,tp,pvpfun,kill,logs,immunetokick,tphere");
AddGroup("trustedadmin", "admin", "maintenance,cfg,butcher,item,heal,immunetoban,usebanneditem,manageusers");
AddGroup("vip", "default", "reservedslot");
}
示例4: GroupManager
public GroupManager(IDbConnection db)
{
database = db;
var table = new SqlTable("GroupList",
new SqlColumn("GroupName", MySqlDbType.VarChar, 32) { Primary = true },
new SqlColumn("Parent", MySqlDbType.VarChar, 32),
new SqlColumn("Commands", MySqlDbType.Text),
new SqlColumn("ChatColor", MySqlDbType.Text)
);
var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
creator.EnsureExists(table);
//Add default groups
AddGroup("default", "canwater,canlava,warp,canbuild");
AddGroup("newadmin", "default", "kick,editspawn,reservedslot");
AddGroup("admin", "newadmin", "ban,unban,whitelist,causeevents,spawnboss,spawnmob,managewarp,time,tp,pvpfun,kill,logs,immunetokick,tphere");
AddGroup("trustedadmin", "admin", "maintenance,cfg,butcher,item,heal,immunetoban,ignorecheatdetection,ignoregriefdetection,usebanneditem,manageusers");
AddGroup("vip", "default", "canwater,canlava,warp,canbuild,reservedslot");
String file = Path.Combine(TShock.SavePath, "groups.txt");
if (File.Exists(file))
{
using (StreamReader sr = new StreamReader(file))
{
String line;
while ((line = sr.ReadLine()) != null)
{
if (!line.Equals("") && !line.Substring(0, 1).Equals("#"))
{
String[] info = line.Split(' ');
String comms = "";
int size = info.Length;
for (int i = 1; i < size; i++)
{
if (!comms.Equals(""))
comms = comms + ",";
comms = comms + info[i].Trim();
}
string query = "";
if (TShock.Config.StorageType.ToLower() == "sqlite")
query = "INSERT OR IGNORE INTO GroupList (GroupName, Commands) VALUES (@0, @1);";
else if (TShock.Config.StorageType.ToLower() == "mysql")
query = "INSERT IGNORE INTO GroupList SET [email protected], [email protected];";
db.Query(query, info[0].Trim(), comms);
}
}
}
String path = Path.Combine(TShock.SavePath, "old_configs");
String file2 = Path.Combine(path, "groups.txt");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
if (File.Exists(file2))
File.Delete(file2);
File.Move(file, file2);
}
}
示例5: CharacterManager
public CharacterManager(IDbConnection db)
{
database = db;
var table = new SqlTable("tsCharacter",
new SqlColumn("Account", MySqlDbType.Int32) {Primary = true},
new SqlColumn("Health", MySqlDbType.Int32),
new SqlColumn("MaxHealth", MySqlDbType.Int32),
new SqlColumn("Mana", MySqlDbType.Int32),
new SqlColumn("MaxMana", MySqlDbType.Int32),
new SqlColumn("Inventory", MySqlDbType.Text),
new SqlColumn("extraSlot", MySqlDbType.Int32),
new SqlColumn("spawnX", MySqlDbType.Int32),
new SqlColumn("spawnY", MySqlDbType.Int32),
new SqlColumn("skinVariant", MySqlDbType.Int32),
new SqlColumn("hair", MySqlDbType.Int32),
new SqlColumn("hairDye", MySqlDbType.Int32),
new SqlColumn("hairColor", MySqlDbType.Int32),
new SqlColumn("pantsColor", MySqlDbType.Int32),
new SqlColumn("shirtColor", MySqlDbType.Int32),
new SqlColumn("underShirtColor", MySqlDbType.Int32),
new SqlColumn("shoeColor", MySqlDbType.Int32),
new SqlColumn("hideVisuals", MySqlDbType.Int32),
new SqlColumn("skinColor", MySqlDbType.Int32),
new SqlColumn("eyeColor", MySqlDbType.Int32),
new SqlColumn("questsCompleted", MySqlDbType.Int32)
);
var creator = new SqlTableCreator(db,
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
creator.EnsureTableStructure(table);
}
示例6: WarpplateManager
public WarpplateManager(IDbConnection db)
{
this.database = db;
string arg_ED_0 = "Warpplates";
SqlColumn[] array = new SqlColumn[11];
array[0] = new SqlColumn("X1", MySqlDbType.Int32);
array[1] = new SqlColumn("Y1", MySqlDbType.Int32);
array[2] = new SqlColumn("width", MySqlDbType.Int32);
array[3] = new SqlColumn("height", MySqlDbType.Int32);
SqlColumn[] arg_7E_0 = array;
int arg_7E_1 = 4;
SqlColumn sqlColumn = new SqlColumn("WarpplateName", MySqlDbType.VarChar, new int?(50));
sqlColumn.Primary = true;
arg_7E_0[arg_7E_1] = sqlColumn;
array[5] = new SqlColumn("WorldID", MySqlDbType.Text);
array[6] = new SqlColumn("UserIds", MySqlDbType.Text);
array[7] = new SqlColumn("Protected", MySqlDbType.Int32);
array[8] = new SqlColumn("WarpplateDestination", MySqlDbType.VarChar, new int?(50));
array[9] = new SqlColumn("Delay", MySqlDbType.Int32);
array[10] = new SqlColumn("Label", MySqlDbType.Text);
SqlTable sqlTable = new SqlTable(arg_ED_0, array);
IQueryBuilder arg_10D_1;
if (DbExt.GetSqlType(db) != SqlType.Sqlite)
{
IQueryBuilder queryBuilder = new MysqlQueryCreator();
arg_10D_1 = queryBuilder;
}
else
{
arg_10D_1 = new SqliteQueryCreator();
}
SqlTableCreator sqlTableCreator = new SqlTableCreator(db, arg_10D_1);
sqlTableCreator.EnsureExists(sqlTable);
this.ReloadAllWarpplates();
}
示例7: GetColumns
public List<string> GetColumns(SqlTable table)
{
var ret = new List<string>();
var name = database.GetSqlType();
if (name == SqlType.Sqlite)
{
using (var reader = database.QueryReader("PRAGMA table_info({0})".SFormat(table.Name)))
{
while (reader.Read())
ret.Add(reader.Get<string>("name"));
}
}
else if (name == SqlType.Mysql)
{
using (
var reader =
database.QueryReader(
"SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE [email protected] AND [email protected]", table.Name,
database.Database))
{
while (reader.Read())
ret.Add(reader.Get<string>("COLUMN_NAME"));
}
}
else
{
throw new NotSupportedException();
}
return ret;
}
示例8: BanManager
/// <summary>
/// Initializes a new instance of the <see cref="TShockAPI.DB.BanManager"/> class.
/// </summary>
/// <param name="db">A valid connection to the TShock database</param>
public BanManager(IDbConnection db)
{
database = db;
var table = new SqlTable("Bans",
new SqlColumn("IP", MySqlDbType.String, 16) {Primary = true},
new SqlColumn("Name", MySqlDbType.Text),
new SqlColumn("UUID", MySqlDbType.Text),
new SqlColumn("Reason", MySqlDbType.Text),
new SqlColumn("BanningUser", MySqlDbType.Text),
new SqlColumn("Date", MySqlDbType.Text),
new SqlColumn("Expiration", MySqlDbType.Text)
);
var creator = new SqlTableCreator(db,
db.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder) new SqliteQueryCreator()
: new MysqlQueryCreator());
try
{
creator.EnsureTableStructure(table);
}
catch (DllNotFoundException)
{
System.Console.WriteLine("Possible problem with your database - is Sqlite3.dll present?");
throw new Exception("Could not find a database library (probably Sqlite3.dll)");
}
}
示例9: InitializeTable
public void InitializeTable()
{
var table = new SqlTable("RegionHelper",
new SqlColumn("RegionName", MySql.Data.MySqlClient.MySqlDbType.Text),
new SqlColumn("IsLocked", MySql.Data.MySqlClient.MySqlDbType.Text));
var creator = new SqlTableCreator(_Connection, _Connection.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
creator.EnsureExists(table);
}
示例10: AlterTable
/// <summary>
/// Alter a table from source to destination
/// </summary>
/// <param name="from">Must have name and column names. Column types are not required</param>
/// <param name="to">Must have column names and column types.</param>
/// <returns></returns>
public string AlterTable(SqlTable from, SqlTable to)
{
var rstr = rand.NextString(20);
var alter = "RENAME TABLE {0} TO {1}_{0}".SFormat(from.Name, rstr);
var create = CreateTable(to);
//combine all columns in the 'from' variable excluding ones that aren't in the 'to' variable.
//exclude the ones that aren't in 'to' variable because if the column is deleted, why try to import the data?
var insert = "INSERT INTO {0} ({1}) SELECT {1} FROM {2}_{0}".SFormat(from.Name, string.Join(", ", from.Columns.Where(c => to.Columns.Any(c2 => c2.Name == c.Name)).Select(c => c.Name)), rstr);
var drop = "DROP TABLE {0}_{1}".SFormat(rstr, from.Name);
return "{0}; {1}; {2}; {3};".SFormat(alter, create, insert, drop);
}
示例11: Initialize
public static void Initialize()
{
if (!Directory.Exists(SavePath))
Directory.CreateDirectory(SavePath);
switch (TShock.Config.StorageType.ToLower())
{
case "mysql":
string[] host = TShock.Config.MySqlHost.Split(':');
Database = 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)
};
break;
case "sqlite":
string sql = Path.Combine(SavePath, "Clans.sqlite");
Database = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
break;
}
SqlTableCreator SQLcreator = new SqlTableCreator(Database, Database.GetSqlType() == SqlType.Sqlite
? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
SqlTable[] tables = new SqlTable[]
{
new SqlTable("Clans",
new SqlColumn("Name", MySqlDbType.VarChar) { Primary=true, Unique=true },
new SqlColumn("Owner", MySqlDbType.VarChar),
new SqlColumn("InviteMode", MySqlDbType.Int32),
new SqlColumn("TileX", MySqlDbType.Int32),
new SqlColumn("TileY", MySqlDbType.Int32),
new SqlColumn("ChatColor", MySqlDbType.VarChar),
new SqlColumn("Bans", MySqlDbType.VarChar)
),
new SqlTable("ClanMembers",
new SqlColumn("Username",MySqlDbType.VarChar) { Primary=true, Unique=true },
new SqlColumn("ClanName", MySqlDbType.VarChar)
),
new SqlTable("ClanWarps",
new SqlColumn("WarpName",MySqlDbType.VarChar) { Primary=true, Unique=true }
)
};
for (int i = 0; i < tables.Length; i++)
SQLcreator.EnsureTableStructure(tables[i]);
Config = Config.Read();
LoadClans();
}
示例12: VocationManager
public VocationManager(IDbConnection conn)
{
_conn = conn;
var table = new SqlTable(TableName,
new SqlColumn("id", MySqlDbType.Int32) { Primary = true },
new SqlColumn("level", MySqlDbType.Int32),
new SqlColumn("experience", MySqlDbType.Int64),
new SqlColumn("vocation", MySqlDbType.VarChar) { Primary = true, Length = 16 });
var creator = new SqlTableCreator(conn, DbProvider);
creator.EnsureTableStructure(table);
}
示例13: ChatManager
public ChatManager(IDbConnection db)
{
database = db;
var table = new SqlTable("Chat",
new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true },
new SqlColumn("Username", MySqlDbType.VarChar, 32),
new SqlColumn("ToUsername", MySqlDbType.VarChar, 32),
new SqlColumn("Message", MySqlDbType.VarChar, 32)
);
var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
creator.EnsureExists(table);
}
示例14: InventoryManager
public InventoryManager(IDbConnection db)
{
database = db;
var table = new SqlTable("Inventory",
new SqlColumn("Account", MySqlDbType.Int32) { Primary = true },
new SqlColumn("MaxHealth", MySqlDbType.Int32),
new SqlColumn("MaxMana", MySqlDbType.Int32),
new SqlColumn("Inventory", MySqlDbType.Text)
);
var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
creator.EnsureExists(table);
}
示例15: ArmorShopManager
public ArmorShopManager(IDbConnection db)
{
database = db;
var table = new SqlTable("Armor",
new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, AutoIncrement = true },
new SqlColumn("Name", MySqlDbType.VarChar, 32),
new SqlColumn("InGameName", MySqlDbType.VarChar, 128),
new SqlColumn("Contains", MySqlDbType.VarChar, 128),
new SqlColumn("Price", MySqlDbType.Int32));
var creator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
creator.EnsureExists(table);
}