core: Workaround Qt 4 SQL bindValue() duplicates
authorShane Synan <digitalcircuit36939@gmail.com>
Wed, 6 Feb 2019 23:37:01 +0000 (18:37 -0500)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 14 Feb 2019 19:25:41 +0000 (20:25 +0100)
commit85087a839d89dc53ed71b41e12244e57f21f67b1
treef6084e02f7e5ab1f2f35ae68d69ccc1f23e767a1
parent3c910a417a72dfa529ad514d9a616139b7d57bab
core: Workaround Qt 4 SQL bindValue() duplicates

Workaround Qt 4 QSqlQuery::bindValue() not handling duplicate
parameter names by giving every duplicated parameter a unique name.

Qt 5 handles this as one expects, so this doesn't need forward-ported
to 0.14/master where Qt 4 support has been dropped.

Applies to SQLite and PostgreSQL.

Note: PostgreSQL prepared statements properly handle repeated "$"
parameters, so there's no need to modify those.

Test case for prepared statements:
> PREPARE qcore_test_var
  AS SELECT * FROM buffer WHERE bufferid = $1 AND userid = $1
    AND networkid = $1;
> EXECUTE qcore_test_var(1);
Gives a result if bufferid = userid = networkid = 1 exists.

Credit to @justJanne for finding the root cause of the issue, and
suggesting the fix, and to 'galfwender' and @darkstar for reporting.

Fixes #1506

See https://doc.qt.io/archives/qt-4.8/qsqlquery.html#bindValue
And https://doc.qt.io/qt-5/qsqlquery.html#bindValue
14 files changed:
src/core/SQL/PostgreSQL/select_messagesAllNew_filtered.sql
src/core/SQL/PostgreSQL/select_messagesAll_filtered.sql
src/core/SQL/PostgreSQL/select_messagesNewerThan_filtered.sql
src/core/SQL/PostgreSQL/select_messagesNewestK_filtered.sql
src/core/SQL/PostgreSQL/select_messagesRange_filtered.sql
src/core/SQL/SQLite/select_messagesAllNew_filtered.sql
src/core/SQL/SQLite/select_messagesAll_filtered.sql
src/core/SQL/SQLite/select_messagesNewerThan.sql
src/core/SQL/SQLite/select_messagesNewerThan_filtered.sql
src/core/SQL/SQLite/select_messagesNewestK.sql
src/core/SQL/SQLite/select_messagesNewestK_filtered.sql
src/core/SQL/SQLite/select_messagesRange_filtered.sql
src/core/postgresqlstorage.cpp
src/core/sqlitestorage.cpp