Commit ad5cacfe authored by mvogt's avatar mvogt

[qtcontacts-sqlite] Provide hook to debug SQL expansion of filters

Define QTCONTACTS_SQLITE_DEBUG_FILTERS to a non-empty value to report
the SQL expansion of contact filters.
parent 0ecf2819
......@@ -1224,6 +1224,28 @@ static QString buildOrderBy(const QList<QContactSortOrder> &order, QString *join
return fragments.join(QLatin1String(", "));
}
static void debugFilterExpansion(const QString &description, const QString &queryString, const QVariantList &bindings)
{
static const bool debugFilters = !qgetenv("QTCONTACTS_SQLITE_DEBUG_FILTERS").isEmpty();
static const QChar marker = QChar::fromLatin1('?');
if (debugFilters) {
QString query(queryString);
int index = 0;
for (int i = 0; i < bindings.count(); ++i) {
QString value = bindings.at(i).toString();
index = query.indexOf(marker, index);
if (index == -1)
break;
query.replace(index, 1, value);
index += value.length();
}
qDebug() << description << query;
}
}
ContactReader::ContactReader(const QSqlDatabase &database)
: m_database(database)
{
......@@ -1310,6 +1332,8 @@ static QContactManager::Error createTemporaryContactIdsTable(
qWarning() << insertQuery.lastError();
qWarning() << insertStatement;
return QContactManager::UnspecifiedError;
} else {
debugFilterExpansion("Contacts selection:", insertStatement, boundValues);
}
} else {
// specified by id list
......@@ -1781,6 +1805,8 @@ QContactManager::Error ContactReader::readContactIds(
qWarning() << query.lastError();
qWarning() << queryString;
return QContactManager::UnspecifiedError;
} else {
debugFilterExpansion("Contact IDs selection:", queryString, bindings);
}
do {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment