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

Qt5.9 build-in SQLite 3.16 not support JSON1 Extension

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P3: Somewhat important
    • 5.13.0 Alpha 1
    • 5.7.0, 5.7.1, 5.8.0, 5.9.0, 5.9.1
    • SQL Support
    • None
    • Qt 5.9.1 for Windows 7

      Qt 5.9.1 for Linux (Ubuntu 16.04)

      Qt 5.9.1 for MacOSX 10.8

      Qt 5.9.1 for Android 4.4

      Qt 5.9.1 for IOS

       

    • f46c9f67bafd01654ac41867144c9c476a0a5649

    Description

      I want to use the SQLite3 database to store JSON as a JSON DB in IOS and Android. Qt 5.9 build-in SQLite 3.16 module not support the JSON1 extension. SQLite version must be 3.9 or higher, and Qt's SQLite module has support the JSON1 extension. The offical document: http://www.sqlite.org/json1.html.
       
      This is my code to test SQLite JSON1 extension, and get the error message: no json function.
      -------------------------------------------------------------------------------------------------------------
      #include <QCoreApplication>
      #include <QSqlDatabase>
      #include <QSqlQuery>
      #include <QtDebug>
      #include <QSqlError>
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );
          db.setDatabaseName( ":memory:" );
          if( !db.open() )
          {
              qDebug() << db.lastError();
              return 1;
          }
          qDebug( "Connected!" );
          QSqlQuery qry;
          qry.exec("create table user (data text)");
          qDebug( "Table creatd!" );
          bool success = qry.exec("INSERT INTO user VALUES(json('{\"id\":1}'))" );
          if( !success )
              qDebug() << qry.lastError();
          else
              qDebug( "Inserted!" );
          db.close();
          return 0;
      }
      -------------------------------------------------------------------------------------------------------------
       
      To support the JSON1 extension with the Qt build-in SQLite3 module, just add "SQLITE_ENABLE_JSON1" to the line 2 in the file: qtbase/src/3rdparty/sqlite.pri.
      Like this:
      DEFINES += SQLITE_OMIT_LOAD_EXTENSION SQLITE_OMIT_COMPLETE SQLITE_ENABLE_FTS3 SQLITE_ENABLE_FTS3_PARENTHESIS SQLITE_ENABLE_FTS5 SQLITE_ENABLE_RTREE SQLITE_ENABLE_JSON1

       

      I will use the json db for mobile apps:

      Result API + NoSQL --->JSON transfer ---> Qt QML Quick Controls 2 APP ---> JS + JSON ---> storage in SQLite3 as json db

      It is more easily to storage json datas in the SQLite3 database with the JSON1 extension than the SQLite3 database without the JSON1 extension. So I want the Qt offical workers to help me and all of us who use Qt5 for Android and IOS developments. Thanks !.

       

      Attachments

        Activity

          People

            chehrlic Christian Ehrlicher
            tianlang yi tianlang
            Votes:
            4 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: