mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Less hardcoding of MySQL / SQLite stuff
This commit is contained in:
parent
29441bd5b9
commit
e31836f218
@ -35,6 +35,12 @@ namespace MCGalaxy.SQL {
|
||||
Server.MySQLUsername, Server.MySQLPassword, Server.DatabasePooling); }
|
||||
}
|
||||
public override bool EnforcesTextLength { get { return true; } }
|
||||
|
||||
public MySQLBackend() {
|
||||
CaselessWhereSuffix = " COLLATE utf8_general_ci";
|
||||
CaselessLikeSuffix = "";
|
||||
}
|
||||
|
||||
|
||||
public override void CreateDatabase() {
|
||||
ParameterisedQuery query = GetStaticParameterised();
|
||||
|
@ -35,6 +35,12 @@ namespace MCGalaxy.SQL {
|
||||
}
|
||||
public override bool EnforcesTextLength { get { return false; } }
|
||||
|
||||
public SQLiteBackend() {
|
||||
CaselessWhereSuffix = " COLLATE NOCASE";
|
||||
CaselessLikeSuffix = " COLLATE NOCASE";
|
||||
}
|
||||
|
||||
|
||||
public override void CreateDatabase() { }
|
||||
|
||||
public override BulkTransaction CreateBulk() {
|
||||
|
@ -32,6 +32,13 @@ namespace MCGalaxy.SQL {
|
||||
/// <summary> Whether this backend enforces the character length in VARCHAR columns. </summary>
|
||||
public abstract bool EnforcesTextLength { get; }
|
||||
|
||||
/// <summary> Suffix required after a WHERE clause for caseless string comparison. </summary>
|
||||
public string CaselessWhereSuffix { get; protected set; }
|
||||
|
||||
/// <summary> Suffix required after a LIKE clause for caseless string comparison. </summary>
|
||||
public string CaselessLikeSuffix { get; protected set; }
|
||||
|
||||
|
||||
/// <summary> Creates the schema for this database (if required). </summary>
|
||||
public abstract void CreateDatabase();
|
||||
|
||||
|
@ -188,13 +188,13 @@ namespace MCGalaxy {
|
||||
|
||||
|
||||
internal static DataTable Query(string name, string columns) {
|
||||
string suffix = Server.useMySQL ? " utf8_general_ci" : " NOCASE";
|
||||
string suffix = Database.Backend.CaselessWhereSuffix;
|
||||
return Database.Backend.GetRows("Players", columns,
|
||||
"WHERE Name=@0 COLLATE" + suffix, name);
|
||||
"WHERE Name=@0" + suffix, name);
|
||||
}
|
||||
|
||||
internal static DataRow QueryMulti(Player p, string name, string columns) {
|
||||
string suffix = Server.useMySQL ? "" : " COLLATE NOCASE";
|
||||
string suffix = Database.Backend.CaselessLikeSuffix;
|
||||
using (DataTable results = Database.Backend.GetRows("Players", columns,
|
||||
"WHERE Name LIKE @0 LIMIT 21" + suffix,
|
||||
"%" + name + "%")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user