Skip to content
This repository
Browse code

mysql: fix SELECT queries containing "CAST(foo as integer)" (fixes #1…

…4496)
  • Loading branch information...
commit ef7dffba042c4dcde3ac03aa8b4b7f874ff8a85d 1 parent ab8b165
Sascha Montellese authored July 28, 2013

Showing 1 changed file with 7 additions and 1 deletion. Show diff stats Hide diff stats

  1. 8  xbmc/dbwrappers/mysqldataset.cpp
8  xbmc/dbwrappers/mysqldataset.cpp
@@ -1403,9 +1403,15 @@ bool MysqlDataset::query(const char *query) {
1403 1403
 
1404 1404
   close();
1405 1405
 
  1406
+  size_t loc;
  1407
+
  1408
+  // mysql doesn't understand CAST(foo as integer) => change to CAST(foo as signed integer)
  1409
+  if ((loc = ci_find(qry, "as integer)")) != string::npos)
  1410
+    qry = qry.insert(loc + 3, "signed ");
  1411
+
1406 1412
   MYSQL_RES *stmt = NULL;
1407 1413
 
1408  
-  if ( static_cast<MysqlDatabase*>(db)->setErr(static_cast<MysqlDatabase*>(db)->query_with_reconnect(query), query) != MYSQL_OK )
  1414
+  if ( static_cast<MysqlDatabase*>(db)->setErr(static_cast<MysqlDatabase*>(db)->query_with_reconnect(qry.c_str()), qry.c_str()) != MYSQL_OK )
1409 1415
     throw DbErrors(db->getErrorMsg());
1410 1416
 
1411 1417
   MYSQL* conn = handle();

0 notes on commit ef7dffb

Please sign in to comment.
Something went wrong with that request. Please try again.