qsqlquery

Swapping headers in QSqlQueryModel (transpose table)

拜拜、爱过 提交于 2019-12-11 07:25:41
问题 I am having a problem to properly transpose the table I recieve from db. I followed the path found here , and ended up in subclassing a QAbstractProxyModel - like described here . unfortunatelly, it doesn't fully work, here's where the problem is: What I have: X | A | B ---------- 1 | A1 | B1 2 | A2 | B2 What I want: X | 1 | 2 ---------- A | A1 | A2 B | B1 | B2 What I get: X | 1 | 1 ---------- A | A1 | A2 A | B1 | B2 So as you can see, the data is correctly transposed, but the headers get bad

QSqlQuery for SQLite in forward iteration with next() will only find one row

非 Y 不嫁゛ 提交于 2019-12-07 08:40:47
问题 The following problem has been discussed from time to time. However there was never a solution for the problem it self. As I found out there is a difference in iterating rows forward and backward. Forward iteration with QSqlQuery::next() may result in only one row, however backward iteration with QSqlQuery::previous() will always find all rows. Whether forward iteration is set explicitely or not, has no effect. Edit: References removed Concerning Qt documentation the right approach would be

QSqlQuery with prepare and bindValue for column name Sqlite

戏子无情 提交于 2019-12-06 01:39:13
问题 void updateDB(const int id, const QString& column, const QVariant& value) const //***** //all stuff on open DB etc. QSqlQuery query; query.prepare("UPDATE table SET :column = :value WHERE id = :id "); query.bindValue(":column", QVariant(column)); query.bindValue(":value", value); query.bindValue(":id", id); query.exec(); Doesn't work. Meanwhile if I rewrite query to query.exec("UPDATE table SET " + column + " = " + value.toString() + " WHERE id = " + QString::number(id)); it works. It also

QSqlQuery for SQLite in forward iteration with next() will only find one row

江枫思渺然 提交于 2019-12-05 15:12:48
The following problem has been discussed from time to time. However there was never a solution for the problem it self. As I found out there is a difference in iterating rows forward and backward. Forward iteration with QSqlQuery::next() may result in only one row, however backward iteration with QSqlQuery::previous() will always find all rows. Whether forward iteration is set explicitely or not, has no effect. Edit: References removed Concerning Qt documentation the right approach would be following: QSqlQuery q = db.exec("SELECT * FROM Table"); while (q.next()) { // Do something with row...

Qt QSqlQuery bindValue works with ? but not with :placeholders

心不动则不痛 提交于 2019-12-01 16:55:33
I'm working with SQLite, doing insert into table. Folowwing QSqlQuery testQuery(QString("INSERT INTO test(testcol) VALUES(?)")); testQuery.bindValue(0, someQStringObg); testQuery.exec(); works, but QSqlQuery testQuery(QString("INSERT INTO test(testcol) VALUES(:val)")); testQuery.bindValue(":val", someQStringObg); testQuery.exec(); don't. testQuery.lastError().text() returns No query Unable to fetch row Have no clue why things are that way, but really want to find out. lpapp Please use prepare as the official example : QSqlQuery testQuery; testQuery.prepare("INSERT INTO test(testcol) VALUES(

Qt QSqlQuery bindValue works with ? but not with :placeholders

假如想象 提交于 2019-12-01 14:55:49
问题 I'm working with SQLite, doing insert into table. Folowwing QSqlQuery testQuery(QString("INSERT INTO test(testcol) VALUES(?)")); testQuery.bindValue(0, someQStringObg); testQuery.exec(); works, but QSqlQuery testQuery(QString("INSERT INTO test(testcol) VALUES(:val)")); testQuery.bindValue(":val", someQStringObg); testQuery.exec(); don't. testQuery.lastError().text() returns No query Unable to fetch row Have no clue why things are that way, but really want to find out. 回答1: Please use prepare

Sql query to create a calculated field

做~自己de王妃 提交于 2019-11-29 11:05:18
I have a database table like this: I hope I can explain this well, so you can understand. I want to calculate how many hours each employee has worked. For example for "Arjeta Domi" we have Cell(2,3) - Cell(3,3) + Cell(4,3) + Cell(5,3), making the difference of each logOut time with Login time. The final table that I want will have these columns: CardNo , UserName , Date , PauseTime , WorkTime I tried this query: taken from the duplicate SELECT DISTINCT [Card NO], [User Name], ( SELECT MIN(DateTime) AS [Enter Time], MAX(DateTime) AS [Exit Time], MAX(DateTime) - MIN(DateTime) AS [Inside Hours]