Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-30088

Add SQLite UTF-16 Collating Sequences

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Incomplete
    • P3: Somewhat important
    • None
    • 4.8.4, 5.0.1
    • SQL Support
    • None

    Description

      We're using this patch to support UTF-16 CaseInsensitive comparisons. Would be nice, if you'd add this to Qt 5

      Index: qsql_sqlite.cpp
      ===================================================================
      — qsql_sqlite.cpp (Revision 166)
      +++ qsql_sqlite.cpp (Revision 167)
      @@ -31,6 +31,7 @@
      #include <qstringlist.h>
      #include <qvector.h>
      #include <qdebug.h>
      +#include <qchar.h>

      #if defined Q_OS_WIN

      1. include <qt_windows.h>
        @@ -520,6 +521,22 @@
        return false;
        }

      +static int sqlite_compare_utf16( void* /arg/,int size1, const void str1, int size2, const void str2)
      +

      { + QString string1 = QString::fromRawData(reinterpret_cast<const QChar*>(str1), size1 / sizeof(QChar)); + QString string2 = QString::fromRawData(reinterpret_cast<const QChar*>(str2), size2 / sizeof(QChar)); + + return QString::compare(string1, string2, Qt::CaseSensitive); +}

      +
      +static int sqlite_compare_utf16ci( void* /arg/,int size1, const void str1, int size2, const void str2)
      +

      { + QString string1 = QString::fromRawData(reinterpret_cast<const QChar*>(str1), size1 / sizeof(QChar)); + QString string2 = QString::fromRawData(reinterpret_cast<const QChar*>(str2), size2 / sizeof(QChar)); + + return QString::compare(string1, string2, Qt::CaseInsensitive); +}

      +
      /*
      SQLite dbs have no user name, passwords, hosts or ports.
      just file names.
      @@ -551,7 +568,28 @@

      if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, openMode, NULL) == SQLITE_OK) {
      sqlite3_busy_timeout(d->access, timeOut);

      • setOpen(true);
        +
        + int res = SQLITE_OK;
        +
        + // add UTF16 collation (comparison is performed by QString functions)
        + res = sqlite3_create_collation(d->access, "UTF16", SQLITE_UTF16, 0, sqlite_compare_utf16);
        + if (res != SQLITE_OK) { + setLastError(qMakeError(d->access, tr("Error opening database"), + QSqlError::ConnectionError, res)); + setOpenError(true); + return false; + }

        +
        + // add UTF16CI (case insensitive) collation (comparison is performed by QString functions)
        + res = sqlite3_create_collation(d->access, "UTF16CI", SQLITE_UTF16, 0, sqlite_compare_utf16ci);
        + if (res != SQLITE_OK)

        { + setLastError(qMakeError(d->access, tr("Error opening database"), + QSqlError::ConnectionError, res)); + setOpenError(true); + return false; + }

        +
        + setOpen(true);
        setOpenError(false);
        return true;
        } else {

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mabrand Mark Brand
            sebastianphilipp Sebastian Philipp
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes