Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. qsqlquery
    Log in to post

    • UNSOLVED QSqlQueryModel and QSqlQuery methods taking more execution time with QSQLCIPHER plugins
      QML and Qt Quick • qsqldatabase qsqlquery qsqlquerymodel sqlcipher • • Kuldip Somwanshi  

      9
      0
      Votes
      9
      Posts
      148
      Views

      I have worked with the qsqlcipher plugins well and gone through with the qsqlcipher plugin code and I puted some print statement in the plugin code itself then observed that the fetchNext function taking is more time, Please look into it
    • UNSOLVED Segmentation Fault after assigning QSqlQueryModel from function return in switch statement
      General and Desktop • c++ sql qsqlquery qsqlquerymodel sigsegv • • achoy011  

      14
      0
      Votes
      14
      Posts
      299
      Views

      @RyanSolanki Please mark as solved if you are happy the issue is resolved. Also consider reading up further about Qt's memory management model (maybe it would make sense to pass a parent during the QSqlQueryModel's construction to avoid all that manual memory management or else perhaps smart pointers if there is no clear parent to assign ownership to). Furthermore, SGaist's point about passing a pointer to a function whose signature expects a const reference cannot be understated. If the function expects a pointer, give it a pointer. If it expects a const reference, give it an object created on the stack! https://doc.qt.io/qt-5/qsqlquerymodel.html#details The documentation is good; use it! It is unclear to me why you are using functions such as "clear" for the model. The setQuery() function already clears the model. Why mess around with new and delete several times when you can just pass in a new query to modify the existing model? Futhermore, why bother clear()-ing the model immediately before you delete it? The destructor is called during the delete, which itself frees up any resources, per the documentation. There are deeper problems of comprehension going on here!
    • SOLVED Copies of QSqlQuery share the same bound values
      General and Desktop • qsqlquery copying • • Skogach  

      7
      0
      Votes
      7
      Posts
      304
      Views

      Thx. Will take a look on it and hope it will go into 5.15 (even we as opensource user currently don't have an advantage currently but this hopefully changes somehow in the near future)
    • SOLVED Store custom QVariant type in database
      General and Desktop • qvariant qsqlquery qsql • • Max13  

      6
      0
      Votes
      6
      Posts
      770
      Views

      @Max13 said in Store custom QVariant type in database: I will write a toJson() instead, as I'm loading the data from Json already. Sounds good. Thanks for your advice. Indeed, it would be the correct way to implement this, in my situation I didn't think it would be necessary to implement it that way. I'm updating some models from an API, and save them as a read-only cache in an sqlite because the desktop may be disconnected. So in my opinion, adding another table would make me write more queries and deal with relations when I can do that in a nasty way 馃槄 That's fair enough. Simplicity is often a good thing in code. Thanks for your complete answer. You're most welcome. Happy coding!
    • UNSOLVED QSqlquery exec timeout
      General and Desktop • qsqldatabase qsqlquery qt 5.12 exec timeout • • BartoszPaj  

      5
      0
      Votes
      5
      Posts
      754
      Views

      Process still block, when I lost connection.
    • UNSOLVED calling stored procedure with prepared query vs execute
      General and Desktop • qsqlquery • • dahman  

      9
      0
      Votes
      9
      Posts
      1722
      Views

      @Kent-Dorfman said in calling stored procedure with prepared query vs execute: Since a stored procedure is simply a server-side wrapper around an SQL transaction, it is IRRELEVANT AND REDUNDANT to wrap it in a prepared statement on the client. Yes, I start to understand what you mean. I will study in deep this argument. Thanks a lot for your precious comments.
    • SOLVED SQLQuery Like problem
      General and Desktop • qsqlquery binding • • gaab  

      3
      0
      Votes
      3
      Posts
      295
      Views

      @SGaist My bad ! I did not think to check the docs on that point ! A big thanks G茅rard
    • SOLVED BindValue() in QPSQL is not working?
      General and Desktop • sql qsqlquery postgresql sqldriver • • BartoszPaj  

      13
      0
      Votes
      13
      Posts
      1946
      Views

      @bartoszpaj said in BindValue() in QPSQL is not working?: driver()->hasFeature(QSqlDriver::NamedPlaceholders) returns false. Good catch. I think it's because support for PostgreSQL 10 was added in a later version. If the version is not known to the driver it will fall back to the oldest.
    • SOLVED Receiving multiple result sets of return value in SQL server stored procedure from Qt (QSqlQuery)
      General and Desktop • qsqldatabase qsqlquery odbc sqlserver qodbc • • alizadeh91  

      17
      0
      Votes
      17
      Posts
      3143
      Views

      @SGaist I did it this way for reading return params: Query.nextResult(); // after reading table values //Get Return Parameter for (int i=0; i<CountReturnParam; i++) { qDebug() << QString("Returnparam %1 = %2") .arg(i).arg(Query.boundValue(i).toString()); }
    • SOLVED MySQL Stored Procedure, accessing a single result set
      General and Desktop • sql mysql qsqlquery qsqlquerymodel • • DaveK 0  

      3
      0
      Votes
      3
      Posts
      1437
      Views

      Hi, There鈥檚 also no need to allocate the query on the heap as the QSqlQueryModel::setQuery method parameter suggests.
    • UNSOLVED How to correctly read DECIMAL values from MySQL with QSqlQuery
      General and Desktop • mysql qsqlquery • • deleted602  

      4
      0
      Votes
      4
      Posts
      1509
      Views

      As it is now, double is used. Depending on how your DECIMAL filed is configured, it might be enough. If not, then you can modify the plugin to read the field as described here.
    • SOLVED Cannot retrieve the SQL query string from QSqlQuery?
      General and Desktop • qsqlquery • • JonB  

      6
      0
      Votes
      6
      Posts
      3618
      Views

      @jsulm said in Cannot retrieve the SQL query string from QSqlQuery?: @mostefa This is not the answer to the question as @JNBarchan want to have the query text not its result. From your example he wants to get "SELECT id,name,birthday FROM artist". @mostefa As @jsulm says, I am indeed not looking to execute the query, rather only to retrieve its text. This has indeed turned out to be QSqlQuery::lastQuery(), and I have now marked this question as Solved. Thanks all.
    • SOLVED Ask for help (maybe) in query.value(0).
      General and Desktop • mysql qsqlquery select • • LuAria  

      4
      0
      Votes
      4
      Posts
      972
      Views

      hi, @LuAria , wat ws the value coming in Numtwo ?. Nways ur got solution. Happy coding. Thanks,
    • UNSOLVED Very slow QSqlQuery select
      General and Desktop • qsqlquery qodbc out of memory badalloc blob • • cherevon  

      7
      0
      Votes
      7
      Posts
      2529
      Views

      Hi, Did you check that you are using similar connection parameters for both your Dephi and C++ application ?
    • SOLVED QSqlQuery Access violation by out of scope
      General and Desktop • sql qt 5.7 mysql qsqlquery • • masterofeye  

      17
      0
      Votes
      17
      Posts
      5598
      Views

      @SGaist is VS express not excotic enough ? ;)
    • Detect if SQLite UPDATE statement does not actually update anything
      General and Desktop • sql sqlite qsqlquery • • Kofr  

      8
      0
      Votes
      8
      Posts
      3261
      Views

      Can you show how you setup and run your query ?
    • SOLVED SQLite WHERE clause with BLOB. Or how to make QT query BLOB as x'00000000'?
      General and Desktop • sql sqlite qsqlquery query • • Kofr  

      6
      0
      Votes
      6
      Posts
      5712
      Views

      @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!
    • UNSOLVED Best practices to use CRUD SQL in QML
      QML and Qt Quick • qml sql qsqlquery qsqlquerymodel • • Cleiton Bueno  

      6
      0
      Votes
      6
      Posts
      3350
      Views

      @Cleiton-Bueno Yes. If the query string is correct it will work.
    • UNSOLVED What is the problem in QSqlQuery?
      General and Desktop • qsqldatabase qsqlquery qtsql • • _compiler  

      11
      0
      Votes
      11
      Posts
      2736
      Views

      @_compiler Ok, i see, its a helper class. Well you need to open a db then. You dont need to do it in QueryBuilder. If you open a db in main , QSqlQuery will use this DB. You dont need pointer or reference. Its handled internally.
    • SOLVED Advice on adding threading in database application
      General and Desktop • qsqldatabase qsqlquery threading • • panosk  

      10
      0
      Votes
      10
      Posts
      6674
      Views

      @panosk and to be honest I had already started work on this You already have that in QSqlDatabase, you only need to keep track of the connections' names. Good luck!
    • UNSOLVED QSqlQuery adds records twice
      General and Desktop • qsqlquery • • gabor53  

      4
      0
      Votes
      4
      Posts
      841
      Views

      dont know. should work as before. just not inserting twice.
    • SOLVED 'SELECT' was not declared in this scope
      General and Desktop • sql qsqlquery select • • cxam  

      3
      0
      Votes
      3
      Posts
      1661
      Views

      @alex_malyu Thanks a lot
    • UNSOLVED QSqlQuery different value() type
      General and Desktop • mysql qvariant qsqlquery 5.6.0 • • Xardas  

      13
      0
      Votes
      13
      Posts
      3458
      Views

      The plugin hasn't changed anything related to that between 5.5 and 5.6 so I wonder if it's a change in QVariant. By the way, why do you need that information ? You should be able to just convert to int without any problem.
    • UNSOLVED Dynamic SELECT statement
      General and Desktop • qsqlquery qsqlite • • ealione  

      2
      0
      Votes
      2
      Posts
      789
      Views

      Hi, Sounds like a job for a query builder. Each time you modify one of these variable, you rebuild the query using condition based on what you need. i.e.: QString query = "SELECT * FROM "; if (condition) { query += "WHERE foo=\"" + parameterValue + "\""; //etc. } Hope it helps
    • SOLVED Improve efficiency of database connection
      General and Desktop • qsqldatabase qsqlquery • • reezeus  

      10
      0
      Votes
      10
      Posts
      2445
      Views

      Done :)
    • UNSOLVED Update QSqlTableModel after QSqlQuery executing
      General and Desktop • qsqltablemodel qsqldatabase qsqlquery filtering • • EskeHagen  

      4
      0
      Votes
      4
      Posts
      2524
      Views

      Adapted from the documentation example: model->setFilter("should_alarm=1");
    • [Solved] QSqlDatabase: Insert values from a database to another
      General and Desktop • sql database sqlite qsqldatabase qsqlquery qsql qtsql sqlite database qsqlite • • Alberto  

      5
      0
      Votes
      5
      Posts
      3784
      Views

      At the end it was a typo. I was trying to insert a value into a column called Localizaci贸n by using: guardar_s.prepare("INSERT INTO Solicitudes_Trabajo (Localizacion) The problem is in the accent mark. So if anyone gets this error, watch out the typos. Thanks @clochydd !
    • [Solved] Help Databases QtSql
      General and Desktop • database sqlite qsqldatabase qsqlquery qsql qtsql sqlite database qsqlite • • Alberto  

      5
      0
      Votes
      5
      Posts
      2286
      Views

      Solved. I tried a lot of things to solve the problem. Some of them included calling next before accessing the result as @SGaist said, but it continued saying: QSqlQuery::value: not positioned on a valid record At last I created a new project with a new database and it worked properly with this code: hospital=QSqlDatabase::addDatabase("QSQLITE"); hospital.setDatabaseName("C:/Sqlite3/Hospital.sqlite"); if(hospital.open()){ qDebug()<<"4.Se ha conectado a la base de datos Hospital"; }else{ qDebug()<<"4.ERROR. No se ha conectado a la base de datos Hospital"; } QSqlQuery mostrar; mostrar.prepare("SELECT*FROM Partes WHERE N_Parte=:ID"); mostrar.bindValue(":ID",ui->lineEditN_Parte->text()); if(mostrar.exec()) { qDebug()<<"5.Los datos del parte se han mostrado correctamente"; }else{ qDebug()<<"5.ERROR. Los datos del parte no se han mostrado correctamente"; qDebug()<<"5.ERROR:"<<mostrar.lastError(); } mostrar.next(); ui->tableWidget->setRowCount(15); QStringList Campos; Campos<<"Fecha de Emisi贸n"<<"Unidad Hospitalaria"; ui->tableWidget->setVerticalHeaderLabels(Campos); ui->tableWidget->insertColumn(0); ui->tableWidget->setColumnCount(1); ui->tableWidget->setItem(0, 0, new QTableWidgetItem(mostrar.value(1).toByteArray().constData())); ui->tableWidget->setItem(2, 0, new QTableWidgetItem(mostrar.value(2).toByteArray().constData())); So I guess the problem was in the database, maybe in the columns, maybe in the rows, maybe in the values or maybe in the name of each of them. The important thing is that the code I post in this reply works perfectly, so if anyone has a similar problem I hope it helps. Thank you very much!
    • [Resuelto] Bases de datos QtSql
      Spanish • sql qtablewidget database sqlite qsqldatabase qsqlquery qtsql sqlite database qsqlite base de datos • • Alberto  

      4
      0
      Votes
      4
      Posts
      4510
      Views

      Resuelto. Intent茅 muchas cosas para solucionar el problem, algunas incluian la utilizaci贸n de next() que me faltaba en el c贸digo de mi respuesta anterior pero continuaba saliendo el error: QSqlQuery::value: not positioned on a valid record Al final cre茅 un nuevo proyecto con una base de atos nuevas y funciona correctamente con este c贸digo: hospital=QSqlDatabase::addDatabase("QSQLITE"); hospital.setDatabaseName("C:/Sqlite3/Hospital.sqlite"); if(hospital.open()){ qDebug()<<"4.Se ha conectado a la base de datos Hospital"; }else{ qDebug()<<"4.ERROR. No se ha conectado a la base de datos Hospital"; } QSqlQuery mostrar; mostrar.prepare("SELECT*FROM Partes WHERE N_Parte=:ID"); mostrar.bindValue(":ID",ui->lineEditN_Parte->text()); if(mostrar.exec()) { qDebug()<<"5.Los datos del parte se han mostrado correctamente"; }else{ qDebug()<<"5.ERROR. Los datos del parte no se han mostrado correctamente"; qDebug()<<"5.ERROR:"<<mostrar.lastError(); } mostrar.next(); ui->tableWidget->setRowCount(15); QStringList Campos; Campos<<"Fecha de Emisi贸n"<<"Unidad Hospitalaria"; ui->tableWidget->setVerticalHeaderLabels(Campos); ui->tableWidget->insertColumn(0); ui->tableWidget->setColumnCount(1); ui->tableWidget->setItem(0, 0, new QTableWidgetItem(mostrar.value(1).toByteArray().constData())); ui->tableWidget->setItem(2, 0, new QTableWidgetItem(mostrar.value(2).toByteArray().constData())); As铆 que supongo que el problema estaba en la base de datos anterior, quiz谩s en las columnas, quiz谩s en las filas, quiz谩s en los valores o quiz谩s en el nombre de cada uno de estos elementos. Lo importante es que el c贸digo que adjunto en esta respuesta funciona correctamente, de modo que si alguien tiene un problema parecido espero que esto le ayude. Muchas gracias!
    • [solved] Application crash QSqlQuery(dbconnection) is called.
      General and Desktop • database qsqlquery • • sachi  

      13
      0
      Votes
      13
      Posts
      3629
      Views

      Thanks for sharing your solution ! Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)
    • QSqlQueryModel shows empty table with correct headers.
      General and Desktop • sql qt5.4 qsqlquery qsqlquerymodel odbc • • Charlie42  

      1
      0
      Votes
      1
      Posts
      807
      Views

      No one has replied

    • QSqlQuery bindValue doesn't work properly
      General and Desktop • qsqlquery bindvalue • • Arthil  

      0
      0
      Votes
      0
      Posts
      364
      Views

      No one has replied

    • QSqlQuery bindValue() Function fails to Bind
      General and Desktop • qsqlquery • • Corpse0327  

      7
      0
      Votes
      7
      Posts
      3984
      Views

      @p3c0 Thank you for your help I have realized that If query execution is a failure, than lastQuery() returns a string with either placeHolders or placeHolders replaced with quos. Making the user thinking something with binding is wrong. If query is succesful, lastQuery() returns either placeHolders replaced with quos or actual values. I am going to further test things out and see if something may be improved with bindValue() and make a request based on that.
    • [SOLVED] Strange Sigsev On QSqlQuery.exec();
      General and Desktop • qlist qsqlquery qt 5.4.2 qt 5.3.2 • • Brochadinho  

      9
      0
      Votes
      9
      Posts
      2721
      Views

      at funtion gerarRelatorio i swap the qDeleteAll on line down(original position). and it worked. qDebug()<<"Documentos processados para a Tabela de Relatorio"; acessodb::setDataUltimoRelatorio(idEmpresa,idCliente); qDeleteAll(listaDocumentos); listaDocumentos.clear(); delete modelo; return true; I now will upload to my test server, and see what happens. i doesn't care any more about what is causing the problem, i just hope that is solved.
    • [Solved]Error while using 'bindValue' for my QSqlQuery
      General and Desktop • qsqlquery qsqlquerymodel bindvalue • • ealione  

      3
      0
      Votes
      3
      Posts
      1210
      Views

      Thanks for the heads up. I had no idea. Since I tried to use a model and failed, I became curious. I have done one more example using this tutorial, and it went fine. Do you have any idea why is it complaining about my database not being open, when it clearly is, judging from the fact that my query worked fine.
    • QSqlQuery.nex() and QSqlQuery.seek(i) crashes randomly. [SOLVED]
      General and Desktop • sqlite qsqlquery • • amahta  

      6
      0
      Votes
      6
      Posts
      1520
      Views

      Indeed, as you wrote, you have 40GB database and I don't know the size of the images you have in there. So depending on that and the current number of entries you might be just filling your memory. Try starting with e.g. 100, if it resist increase the value.