Skip to content
  • 0 Votes
    4 Posts
    130 Views
    dheerendraD

    May be you missed creating the someSqlModel object itself ? Is someSqlModel local object ?

  • Sqlite nested select

    Unsolved General and Desktop
    4
    0 Votes
    4 Posts
    191 Views
    JonBJ

    @GeorgiosKoropoulis
    If you want to use whatever SQLite constructs in queries you have, like INSERT OR IGNORE INTO ... or SELECT ... FROM/VALUES (SELECT ... FROM), you can but you have to build the text of the query yourself. In this case you may find that binding does not work (that is supported by the driver, so depends what that allows for binding), but you can build that yourself into the text of the query without using binding. Just beware of correct syntax (e.g. quoting) and SQL injection.

  • 0 Votes
    2 Posts
    623 Views
    SGaistS

    Hi,

    You might want to check the qsqlcipher-qt5 project (they have Qt 6 branches).

  • 0 Votes
    7 Posts
    471 Views
    D

    @SGaist Hi. No I didn't. That fixed the problem I was having. Thanks so much for your help.

  • 0 Votes
    1 Posts
    286 Views
    No one has replied
  • 0 Votes
    1 Posts
    239 Views
    No one has replied
  • 0 Votes
    7 Posts
    707 Views
    BambusFanB

    @eyllanesc Thank you very much, you are right and it works now. I thought it was a function of prepare, so it would be identical.

  • 0 Votes
    3 Posts
    2k Views
    JonBJ

    @Lalremruata said in How to avoid Null or empty value in QLineedit of Pyqt5:

    even the self.lineEdit_2 is empty.

    Are you really 100% sure? I used PyQt5 and I'm pretty sure self.lineEdit_2.text() == "" would work as expected. Get rid of all your other code and behaviour and check just this in a tiny program?

    @jsulm

    You should rather use https://doc.qt.io/qt-5/qstring.html#isEmpty

    My understanding is PyQt5's QLineEdit.text() returns a Python str rather than a C++ QString anyway. I never found using QString methods of any use in PyQt5.

  • 0 Votes
    4 Posts
    386 Views
    P

    Hello,

    to make easy solution I just changed the databaseName when I need the other database and go back to the first databaseName when I don't need the second db :

    databaseManager::databaseManager() { QDir dir; dir.setPath("./Databases"); if (!dir.exists()){ dir.mkdir("."); } db=QSqlDatabase::addDatabase("QSQLITE"); databaseName="./Databases/battery.sqlite"; db.setDatabaseName(databaseName); dbInitCheckStep(); } void databaseManager::dbInitCheckStep() { db.open(); { QSqlQuery query; qDebug()<<"query.exec()"<< query.exec("CREATE TABLE IF NOT EXISTS check_data (step TEXT, periodical_CheckOk TEXT, periodical_CheckNo TEXT,regular_CheckOk TEXT, regular_CheckNo TEXT,general_OverhaulOk TEXT, general_OverhaulNo TEXT, rtos_aft_short_storageOk TEXT, rtos_aft_short_storageNo TEXT)"); query.finish(); query.clear(); db.close(); } QSqlDatabase::removeDatabase("QSQLITE"); } QStringList databaseManager::comboListOtMat() { QStringList listCheck; db.setDatabaseName("../Software32/Databases/kardexdb.sqlite"); db.open(); { QSqlQuery query; query.exec("SELECT otnumber FROM ot_log where ottype='EQUIPMENT' and description='BATTERY' order by cast (substr(otnumber, -2) as decimal) desc, cast(substr(otnumber,1,2) as decimal) desc"); while(query.next()) { qDebug()<<query.value(0).toString(); listCheck<<query.value(0).toString(); } query.finish(); query.clear(); db.close(); } QSqlDatabase::removeDatabase("QSQLITE"); db.setDatabaseName("./Databases/battery.sqlite"); return listCheck; }

    it's not beautyfull but it's easy and it's working fine ;-)

  • 0 Votes
    6 Posts
    788 Views
    JonBJ

    @eleventy
    Ah ha! I did think it would be a good idea to go back to some simple example Qt provides, because one can be unaware that a change one has made can affect things unexpectedly!

    Sounds like you now have what you were supposed to have, well done!

  • 0 Votes
    18 Posts
    3k Views
    SGaistS

    Yes you do, or you can make your own custom QAbstractTableModel that will return the content of your vector of records.

    Yes you do. However you can use an in-memory database if you don't want to have another database in a file.

  • 0 Votes
    5 Posts
    3k Views
    mrdebugM

    Hi, I suggest you to create a class to manage exceptions, so if you have a situation like this

    if (!MyQuery.Exec("select ..")) GeneralException.raise();
    if (!MyQuery.Exec("select ..")) GeneralException.raise();
    if (!MyQuery.Exec("select ..")) GeneralException.raise();

    if a query fails you will jump in the exception function manager.

    If you want to have the list of the columns present in a sqlite database you should use the sqlite features, so
    "pragma table_info(Table01)"
    To have the list of the tables I think there is a similar way.

    Regards.

  • 0 Votes
    4 Posts
    2k Views
    N

    @JonB
    I'm sorry, I thought it would be helpful if people saw the entirety of the code. I didn't know which part of the code I was lacking.

    Ohhh. thank you for the instruction. I'll work on the changes.

  • 0 Votes
    13 Posts
    5k Views
    kshegunovK

    @Christian-Ehrlicher said in SQLite3 Errors: Parameter count mismatch and Unable to fetch row:

    This overload is really confusion and I wonder if it should not be marked as deprecated. There were already some bugreports about this because the usage was unexpected to the users so they did an exec afterwards and screwed up the query with it.

    I appreciate your discreetness, but I don't try to hide my stupidity. ;)

  • 0 Votes
    9 Posts
    3k Views
    T

    @SGaist

    Thanks for the reply. Indeed you are wright. It is very easy actually. I just compiled qt4.8.6 for my system. Then I found the sqlite project in sqldrivers. Compiled this library for my system, copied it and it works!

    Very easy. Learned again a lot!
    Thank you all for the great support!

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    Did you already checked the bug report system to see if there was something related ?

    If not, please consider opening a new report providing a minimal compilable example showing the behaviour.

  • 0 Votes
    9 Posts
    4k Views
    SGaistS

    What default location did you had in mind ?

  • 1 Votes
    4 Posts
    3k Views
    SGaistS

    That's strange, you are binding to :ID which is not available in your query.

  • 0 Votes
    16 Posts
    7k Views
    ?

    Hi! Just to be sure I understood this correctly: You have a single DB with a humongous number of identically structured tables? Do you really believe you can store 2^128 bits / rows / tables / whatever in your database / filesystem / datacenter?

    In worst case I will have to keep in RAM about 4e+38 of 16 bytes pointers

    Even that is way more rows than what a SQLite table can hold (see: https://www.sqlite.org/limits.html).

  • 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. :)