Skip to content


Subversion checkout URL

You can clone with
Download ZIP


mysql: replace all "cast(foo as integer)" to "cast(foo as signed integer)" and not just the first one #4331

merged 1 commit into from

3 participants


The current code in the MySQL db wrapper has some logic to replace

cast(foo as integer)


cast(foo as signed integer)

in SQL queries because MySQL doesn't understand the first one (SQLite does). But the logic that takes care of this is only applied once so if there are multiple occurances that need to be fixed only the first is caught and the rest isn't which results in invalid SQL queries on MySQL.

@koying: Would you mind testing this? Easiest is probably to create a smartplaylist for movies and add two rules for the runtime/duration (which is movie.c11 and results in the usage of above SQL snippets).


Sorry for late reply.
Does this come from an actual issue or is it a potential one?

Anyway, you produce an endless loop, don't you?
"as signed signed signed ... integer"


It's matching "as integer" which doesn't happen once "signed" is inserted into it.


It's an actual issue with smartplaylists using multiple conditions on playcount, duration or any other integer field. And I don't create an infinite loop because I'm looking for "as integer)" and then replace it with "as signed integer)" so the previous search doesn't match that part anymore.


Yeah, was about to retract the endless loop part ;)
Fine for me.


PS If you prefer an actual test, you'll have to consider me as an end-user as I never used smartplaylists at all ;)


This is the actual ticket:

@koying: an actual test would be nice. Just put into your userdata/playlists/video/ directory and choose some filename ending with ".xsp". Then go into XBMC, Videos -> Library -> Playlists and open the "randomunplayedmovie" item. Then please check your logs for the appropraite GetMoviesByWhere call for that smartplaylist.


Confirmed ok.

@jmarshallnz jmarshallnz merged commit eb45236 into xbmc:master

Thanks :)

@jmarshallnz jmarshallnz removed the Gotham label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2014
  1. @Montellese

    mysql: replace all "cast(foo as integer)" to "cast(foo as signed inte…

    Montellese authored
    …ger)" and not just the first one
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  xbmc/dbwrappers/mysqldataset.cpp
2  xbmc/dbwrappers/mysqldataset.cpp
@@ -1484,7 +1484,7 @@ bool MysqlDataset::query(const char *query) {
size_t loc;
// mysql doesn't understand CAST(foo as integer) => change to CAST(foo as signed integer)
- if ((loc = ci_find(qry, "as integer)")) != string::npos)
+ while ((loc = ci_find(qry, "as integer)")) != string::npos)
qry = qry.insert(loc + 3, "signed ");
Something went wrong with that request. Please try again.