Fix infinite loop when executing some SQL statements with limit part

Issue #31 was about some problems in the SqliteTableModel which caused
an endless loop in the Execute SQL tab when executing statements with a
LIMIT part that didn't end with a semicolon. This was fixed in 0362d615fd
but the regular expression in this commit only worked for statements
like 'SELECT * FROM t LIMIT 0,10' and didn't detect a statement like
'SELECT * FROM t LIMIT 10' where there is only one number after 'limit',
so the bug still ocurred for those commands. This is fixed by this
commit.
This commit is contained in:
Martin Kleusberg
2014-01-01 14:45:27 +01:00
parent 190deca0c3
commit 044907f655

View File

@@ -328,7 +328,7 @@ void SqliteTableModel::fetchData(unsigned int from, unsigned to)
QString queryTemp = rtrimChar(m_sQuery, ';');
// If the query ends with a LIMIT statement take it as it is, if not append our own LIMIT part for lazy population
if(queryTemp.contains(QRegExp("LIMIT\\s+\\d+\\s*,\\s*\\d+\\s*$", Qt::CaseInsensitive)))
if(queryTemp.contains(QRegExp("LIMIT\\s+\\d+\\s*(,\\s*\\d+\\s*)?$", Qt::CaseInsensitive)))
sLimitQuery = queryTemp;
else
sLimitQuery = QString("%1 LIMIT %2, %3;").arg(queryTemp).arg(from).arg(to-from);