Skip to content

Commit

Permalink
[qtcontacts-sqlite] Provide hook to debug SQL expansion of filters
Browse files Browse the repository at this point in the history
Define QTCONTACTS_SQLITE_DEBUG_FILTERS to a non-empty value to report
the SQL expansion of contact filters.
  • Loading branch information
matthewvogt committed Jul 4, 2013
1 parent 0ecf281 commit ad5cacf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Empty file added .building
Empty file.
26 changes: 26 additions & 0 deletions src/engine/contactreader.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1781,6 +1805,8 @@ QContactManager::Error ContactReader::readContactIds(
qWarning() << query.lastError();
qWarning() << queryString;
return QContactManager::UnspecifiedError;
} else {
debugFilterExpansion("Contact IDs selection:", queryString, bindings);
}

do {
Expand Down

0 comments on commit ad5cacf

Please sign in to comment.