Skip to content
QtWS25 Last Chance
  • 0 Votes
    11 Posts
    3k Views
    D
    @SGaist Ok that makes sense. Thank you
  • 0 Votes
    2 Posts
    2k Views
    Y
    I created custom model which works fast enough. It fetches and writes data using queries. Seems like working solution.
  • 0 Votes
    2 Posts
    767 Views
    raven-worxR
    @Saman19 You may want to check out Cutelyst if you want to support the HTTP protocol. If you do not need to rely on HTTP, but just want to receive JSON (or any custom protocol), take a look at QTcpServer examples.
  • 0 Votes
    6 Posts
    2k Views
    BuckwheatB
    @JonB Very good observation. Triggers seem to be under utilized in SQLite. This would actually be a preferred way to update summary calculations. Imagine if you were doing this across a server. The back-and-forth traffic would be so inefficient. I have used triggers for years in SQLite without incident. I even use them for housekeeping modifications to tables. Views are another great tool to coalesce data from relation tables for display.
  • Loading data from sqlite database

    Solved General and Desktop qtcreator sqlite tableview button
    10
    0 Votes
    10 Posts
    7k Views
    SGaistS
    What was the problem ?
  • 0 Votes
    3 Posts
    1k Views
    D
    @SGaist Thank you for your answer!
  • Qt Quick database for MySQL or Postgresql

    Unsolved QML and Qt Quick mysql postgresql qml sqlite database
    1
    0 Votes
    1 Posts
    940 Views
    No one has replied
  • Basic QSqlite

    Solved General and Desktop sqlite
    14
    0 Votes
    14 Posts
    4k Views
    SGaistS
    So you have everything working now with your original database ?
  • 0 Votes
    4 Posts
    2k Views
    mrjjM
    @michalos Well knowing windows searching, i always cheat and use https://www.voidtools.com/ On NTFS drives, it will find anything really fast and takes wildcards. Its only for filenames but on the other hand, it finds a file in secs even on a 4 TB drive. :)
  • 0 Votes
    11 Posts
    14k Views
    michalosM
    Thanks :)
  • 0 Votes
    8 Posts
    4k Views
    SGaistS
    Can you show how you setup and run your query ?
  • 0 Votes
    6 Posts
    7k Views
    kshegunovK
    @Kofr If the above snippet works, then you don't respect the SQL's type. You're trying to pass a string representation to Qt when it clearly expects a binary (BLOB is "Binary Large OBject"). So then the question: How to fix Qt implementation? comes back as: "How to fix your implementation". Anyway, I'd suggest passing the appropriate type to the driver. My thoughts are that something like this should be working: const char rawData[4] = { 0x00, 0x00, 0x00, 0x07 }; QByteArray id = QByteArray::fromRawData(rawData, 4); QSqlQuery query; if (!query.prepare(QStringLiteral("SELECT row FROM %1 WHERE id = :id").arg(tableName))) // Handle the error! query.bindValue(":id", id); // Pass binary data for columns that expect binary if (!query.exec()) // Handle error again!
  • Sqlite User Define Functions

    Solved General and Desktop sqlite sqlite3 udf custom function
    6
    0 Votes
    6 Posts
    4k Views
    DongD
    @therj It's may be too late but... better than not. I found the problem is sqlite version i'm using is not match with the version Qt used in the core of Qt Framework. So, I'm check the compatible of sqlite.h (3rd party) with Qt Sqlite driver to make sure it is the same version like this: //Qt QSqlDatabase driver for Sqlite query = db.PrepareQuery("SELECT sqlite_version()"); //Vs 3rd Party driver (included sqlite.h) qDebug() << "sqlite3_libversion() =" << sqlite3_libversion(); there are few note to remember: Cannot create SQLite custom functions when db object is not open. Need to call sqlite3_initialize() before call sqlite3_create_function() If you have more questions, contact me via facebook Lã Đại Đồng. :)
  • Encrypted sqlite file problem in QT

    Unsolved QML and Qt Quick encryption sqlite qml
    6
    0 Votes
    6 Posts
    4k Views
    SGaistS
    Then you should take a look at the SQLCipher project. AFAIK, you can also find instructions to build a Qt SQL plugin with it to use in your project.
  • How to handle auto_increment with bindvalue()

    Unsolved General and Desktop sql sqlite
    2
    0 Votes
    2 Posts
    1k Views
    SGaistS
    Hi, At first sight your position parameter to bindValue are wrong. You have two values so it should be 0 and 1 not 1 and 2.
  • What's wrong with this SQLite query ?

    Unsolved General and Desktop qt5.5 sqlite3 sqlite database sqlite
    3
    0 Votes
    3 Posts
    3k Views
    the_T
    @Qjay As far as I remember, it is not possible to create indices within a create table statement in sqlite. So you have to split this into the create table and the create index statement as mentioned by @mrjj
  • 0 Votes
    2 Posts
    2k Views
    P
    Hello, I don't think it's that simple as you try to make it, at least if you want to include the data too. Few years ago I had a similar problem and I wrote a function for that purpose. I'm copying-pasting the code from my old post after some reformatting to be readable. Although I have improved the code a bit since then in my own app, this should help you get started (please check the indentation, some fixes may be needed). This function doesn't transfer the schema, but I think it's easy to include it. void DbManager::exportTables() { QHash<QString,QStringList> tablesWithFields; //It holds the table name and its fields QStringList tables = sourceDb.tables(); QSqlQuery query(sourceDb); foreach(const QString &table,tables) { query.exec(QString("PRAGMA TABLE_INFO(%1)").arg(table)); QStringList fields; while(query.next()) { fields << query.value(1).toString(); } tablesWithFields.insert(table,fields); } QFile f(QDir::homePath() + "/myDump.sql"); f.open(QIODevice::Append | QIODevice::Text); QTextStream streamer(&f); //If constraints can't be dropped in the target database, some reordering of //the INSERT statements may be needed QStringList sortedTables = tablesWithFields.keys(); sortedTables.move(sorted.indexOf("table1"),0); ... streamer << "BEGIN;\n"; foreach(const QString &table,sortedTables) { if(table=="sqlite_sequence" /*|| table=="table4", etc*/) continue; QString statement = QString("INSERT INTO %1 VALUES('").arg(table); QStringList fields = tablesWithFields.value(table); QString fieldsString = fields.join(","); query.exec(QString("SELECT %1 FROM %2").arg(fieldsString).arg(table)); if(!query.next()) continue; query.previous(); while(query.next()) { for(int i=0; i < fields.size(); ++i) { QString value = query.value(i).toString(); value.replace("'","''"); //Handle single quotes inside strings if(value.isEmpty()) { value = "NULL"; statement.chop(1); //NULL should not appear inside quotes statement.append(value+",'"); } else { statement.append(value+"','"); } } statement.chop(2); //Remove comma and single quote from the end of value group statement.append("),('"); //Close the value group and start a new one } statement.chop(3);//Remove comma, opening parenthesis, single quote from the end streamer << statement << ";\n"; //Complete the INSERT statement } streamer << "COMMIT;"; f.close(); } And then batch execute the sql file like this: ... exportTables(); QSqlQuery query(targetDb); QFile f(QDir::homePath()+"/myDump.sql"); f.open(QIODevice::ReadOnly | QIODevice::Text); if(!query.exec(f.readAll())) qCritical() << "Can't execute sql file: " << query.lastError().text();
  • how to connect to sqlite database

    Unsolved General and Desktop sqlite
    6
    0 Votes
    6 Posts
    13k Views
    mrjjM
    @Yugui Often best design is open once at start. and close at end. and is possible do update with bindvalue? yes. it is. QSqlQuery query; query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (:id, :forename, :surname)"); query.bindValue(":id", 1001); query.bindValue(":forename", "Bart"); query.bindValue(":surname", "Simpson"); query.exec(); http://doc.qt.io/qt-5/qsqlquery.html
  • Database Connection Error

    Solved General and Desktop database sqlite sqlite database
    5
    0 Votes
    5 Posts
    3k Views
    mrjjM
    @M4RZB4Ni Ok ? I normally used .DB but didn't now it did mean anything ??