mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -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); }
|
Server.MySQLUsername, Server.MySQLPassword, Server.DatabasePooling); }
|
||||||
}
|
}
|
||||||
public override bool EnforcesTextLength { get { return true; } }
|
public override bool EnforcesTextLength { get { return true; } }
|
||||||
|
|
||||||
|
public MySQLBackend() {
|
||||||
|
CaselessWhereSuffix = " COLLATE utf8_general_ci";
|
||||||
|
CaselessLikeSuffix = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override void CreateDatabase() {
|
public override void CreateDatabase() {
|
||||||
ParameterisedQuery query = GetStaticParameterised();
|
ParameterisedQuery query = GetStaticParameterised();
|
||||||
|
@ -35,6 +35,12 @@ namespace MCGalaxy.SQL {
|
|||||||
}
|
}
|
||||||
public override bool EnforcesTextLength { get { return false; } }
|
public override bool EnforcesTextLength { get { return false; } }
|
||||||
|
|
||||||
|
public SQLiteBackend() {
|
||||||
|
CaselessWhereSuffix = " COLLATE NOCASE";
|
||||||
|
CaselessLikeSuffix = " COLLATE NOCASE";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override void CreateDatabase() { }
|
public override void CreateDatabase() { }
|
||||||
|
|
||||||
public override BulkTransaction CreateBulk() {
|
public override BulkTransaction CreateBulk() {
|
||||||
|
@ -32,6 +32,13 @@ namespace MCGalaxy.SQL {
|
|||||||
/// <summary> Whether this backend enforces the character length in VARCHAR columns. </summary>
|
/// <summary> Whether this backend enforces the character length in VARCHAR columns. </summary>
|
||||||
public abstract bool EnforcesTextLength { get; }
|
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>
|
/// <summary> Creates the schema for this database (if required). </summary>
|
||||||
public abstract void CreateDatabase();
|
public abstract void CreateDatabase();
|
||||||
|
|
||||||
|
@ -188,13 +188,13 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
|
|
||||||
internal static DataTable Query(string name, string columns) {
|
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,
|
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) {
|
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,
|
using (DataTable results = Database.Backend.GetRows("Players", columns,
|
||||||
"WHERE Name LIKE @0 LIMIT 21" + suffix,
|
"WHERE Name LIKE @0 LIMIT 21" + suffix,
|
||||||
"%" + name + "%")) {
|
"%" + name + "%")) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user