Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create mulitple database connections for a shared cache memory SqliteDB in Qt?
Forum Updated to NodeBB v4.3 + New Features

How to create mulitple database connections for a shared cache memory SqliteDB in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 331 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Heiduc
    wrote on last edited by
    #1

    I want to create a shared cache memory SqliteDB(https://www.sqlite.org/inmemorydb.html) in a process, and use different connections in a few threads to query that SqliteDB.
    But when I followed example use to open the DB, I got the the error.
    My code:
    QSqlDatabase db;
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(file::memory:?cache=shared);
    if(!db.open())
    {
    qDebug() << db.lastError().text();
    }
    How to create a shared sqliteDb, and create several connetions to this shared database?

    Thanks!
    Heiduc

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Heiduc
      wrote on last edited by
      #2

      I got it,
      1 setConnectOptions("QSQLITE_OPEN_URI;QSQLITE_ENABLE_SHARED_CACHE") ;
      2 setDatabaseName("file::memory:");
      3 QSqlDatabase::cloneDatabase

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved