From 26d564567198a8c01e171df060ffbe34c236c816 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 19 Jul 2013 22:36:28 +0200 Subject: [PATCH] SqliteTableModel: Don't add LIMIT to query if it is a PRAGMA or EXPLAIN Don't add a "LIMIT x,y" at the end of the query in fetchData() when it is a PRAGMA or EXPLAIN statement. This way correct SQL code is produced and it also fixes an endless loop when the statement didn't end in a semicolon. --- src/sqlitetablemodel.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index a8c1102d..122f3ba9 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -285,7 +285,11 @@ void SqliteTableModel::fetchData(unsigned int from, unsigned to) { int currentsize = m_data.size(); - QString sLimitQuery = QString("%1 LIMIT %2, %3;").arg(m_sQuery).arg(from).arg(to-from); + QString sLimitQuery; + if(m_sQuery.startsWith("PRAGMA", Qt::CaseInsensitive) || m_sQuery.startsWith("EXPLAIN", Qt::CaseInsensitive)) + sLimitQuery = m_sQuery; + else + sLimitQuery = QString("%1 LIMIT %2, %3;").arg(m_sQuery).arg(from).arg(to-from); m_db->logSQL(sLimitQuery, kLogMsg_App); QByteArray utf8Query = sLimitQuery.toUtf8(); sqlite3_stmt *stmt;