aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpieh <misiek.piechowiak@gmail.com>2012-05-10 11:35:01 +0200
committerpieh <misiek.piechowiak@gmail.com>2012-05-10 12:22:12 +0200
commit7f57410c2085cbf1a9d3d1c6f4ac91e84d983e89 (patch)
treeb2cf2ee197083784a56bbe843901bd282ba35c88
parentdaf3b4082ce42e2d061f19f0d90707f2f8e08d7a (diff)
do case insensitive searches on queries in MysqlDataset::exec()
-rw-r--r--xbmc/dbwrappers/mysqldataset.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/xbmc/dbwrappers/mysqldataset.cpp b/xbmc/dbwrappers/mysqldataset.cpp
index cd85e69387..2d80ef8b83 100644
--- a/xbmc/dbwrappers/mysqldataset.cpp
+++ b/xbmc/dbwrappers/mysqldataset.cpp
@@ -1319,6 +1319,20 @@ bool MysqlDataset::dropIndex(const char *table, const char *index)
return true;
}
+static bool ci_test(char l, char r)
+{
+ return tolower(l) == tolower(r);
+}
+
+static size_t ci_find(const string& where, const string& what)
+{
+ std::string::const_iterator loc = std::search(where.begin(), where.end(), what.begin(), what.end(), ci_test);
+ if (loc == where.end())
+ return string::npos;
+ else
+ return loc - where.begin();
+}
+
int MysqlDataset::exec(const string &sql) {
if (!handle()) throw DbErrors("No Database Connection");
string qry = sql;
@@ -1328,25 +1342,25 @@ int MysqlDataset::exec(const string &sql) {
// enforce the "auto_increment" keyword to be appended to "integer primary key"
size_t loc;
- if ( (loc=qry.find("integer primary key")) != string::npos)
+ if ( (loc=ci_find(qry, "integer primary key")) != string::npos)
{
qry = qry.insert(loc + 19, " auto_increment ");
}
// force the charset and collation to UTF-8
- if ( qry.find("CREATE TABLE") != string::npos )
+ if ( ci_find(qry, "CREATE TABLE") != string::npos )
{
qry += " CHARACTER SET utf8 COLLATE utf8_general_ci";
}
// sqlite3 requires the BEGIN and END pragmas when creating triggers. mysql does not.
- else if ( qry.find("CREATE TRIGGER") != string::npos )
+ else if ( ci_find(qry, "CREATE TRIGGER") != string::npos )
{
- if ( (loc=qry.find("BEGIN ")) != string::npos )
+ if ( (loc=ci_find(qry, "BEGIN ")) != string::npos )
{
qry.replace(loc, 6, "");
}
- if ( (loc=qry.find(" END")) != string::npos )
+ if ( (loc=ci_find(qry, " END")) != string::npos )
{
qry.replace(loc, 4, "");
}