fixed: fix mysql compatability when creating triggers with BEGIN and END keywords...
authorfirnsy <firnsy@svn>
Tue, 28 Sep 2010 12:50:54 +0000 (12:50 +0000)
committertheuni <theuni-nospam-@xbmc.org>
Tue, 22 Feb 2011 00:56:02 +0000 (19:56 -0500)
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@34276 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
(cherry picked from commit e78a94ca0202a67f7782935d63ac8ffbc4dc5e81)

xbmc/lib/sqLite/mysqldataset.cpp

index 236d2da..e7bf086 100644 (file)
@@ -1216,11 +1216,24 @@ int MysqlDataset::exec(const string &sql) {
   exec_res.clear();
 
   // enforce the "auto_increment" keyword to be appended to "integer primary key"
-  const char* toFind = "integer primary key";
-  size_t loc = qry.find(toFind);
-  if (loc != string::npos)
+  size_t loc;
+  if ( (loc=qry.find("integer primary key")) != string::npos)
   {
-    qry = qry.insert(loc + strlen(toFind), " auto_increment ");
+    qry = qry.insert(loc + 19, " auto_increment ");
+  }
+
+  // sqlite3 requires the BEGIN and END pragmas when creating triggers. mysql does not.
+  if ( qry.find("CREATE TRIGGER") != string::npos )
+  {
+    if ( (loc=qry.find("BEGIN ")) != string::npos )
+    {
+        qry.replace(loc, 6, "");
+    }
+
+    if ( (loc=qry.find(" END")) != string::npos )
+    {
+        qry.replace(loc, 4, "");
+    }
   }
 
   CLog::Log(LOGDEBUG,"Mysql execute: %s", qry.c_str());