Questions tagged [qsqlquery]

The QSqlQuery class, part of the Qt framework, provides a means of executing and manipulating SQL statements.

QSqlQuery encapsulates the functionality involved in creating, navigating and retrieving data from SQL queries which are executed on a QSqlDatabase.

Documentation can be found here.

365 questions
40
votes
2 answers

How to group items from database and display them - Android

I have receipt and logs model in android app. Receipt hasMany logs. I made query for group_by logs by sortID and grade. //recieve RecepitID and query to group logs final long forwardedId = (long)…
RubyDigger19
  • 775
  • 8
  • 34
11
votes
1 answer

Qt QSqlQuery bindValue works with ? but not with :placeholders

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…
user3136871
  • 205
  • 2
  • 3
  • 7
9
votes
3 answers

QSqlQuery size() always returns -1

QSqlQuery query; QString queryText("SELECT * FROM section"); query.exec(queryText); qDebug() << query.size(); //always -1 while (query.next()) qDebug() << query.value(0).toString(); //got 16 records Method size() always returns -1. Help, please.…
Efog
  • 1,126
  • 12
  • 33
8
votes
3 answers

QSqlQuery::prepare + MySQL ODBC Connector

I was using Qt's MySQL driver with 32bit MinGW Qt. This was working: QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName("MyDatabase"); //SETUP if (db.open) { QSqlQuery q; if (q.prepare("SELECT id FROM Things WHERE…
smsware
  • 383
  • 1
  • 12
  • 35
7
votes
2 answers

Qt 5 with SQLite: bindValue() results in "Parameter count mismatch" error

I'm doing a simple parameterized query with Qt 5.3.1 (64-bit) on Windows 7 using the SQLite driver. When I use bindValue() to set the value of the single parameter of my query, I systematically get the dreaded "Parameter count mismatch" error.…
François Beaune
  • 3,782
  • 6
  • 35
  • 53
7
votes
1 answer

QSqlQuery with prepare and bindValue for column name Sqlite

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",…
Littlebitter
  • 621
  • 3
  • 8
  • 17
6
votes
1 answer

QT SQL datatype (QVariant) mapping for BINARY type of arbitrary length

I have a SQL query( call to a stored procedure to MSSQL) that takes arbitrary length of BINARY type as argument.I am using QT's support for stored procedure. But according to this, there is no corresponding QT type for varbinary for ODBC. QT…
msrepo
  • 63
  • 3
5
votes
2 answers

Query Azure SQL Database using Rest-API

I have a SQL database server in Microsoft Azure. I want to use Azure Rest-API to select some records from a table. When I refer to Azure SQL Database REST API I can't find any section for this purpose, just I can get a DB information, server info or…
Sohrab
  • 876
  • 4
  • 10
  • 26
5
votes
2 answers

xml path returns "<" for < and ">" for > while executing query. how to get original value?

I have a query which results some text on the basis of condition in it. but do not worry about all the conditions, I am only facing issue when 'md.OtherMedication = 'OTHERMEDICATION' and its comment to be shown. So if comment have value like…
shubham bahuguna
  • 364
  • 4
  • 13
5
votes
1 answer

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

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…
bkausbk
  • 2,622
  • 1
  • 31
  • 48
4
votes
2 answers

Sql query to create a calculated field

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…
eviB
  • 43
  • 1
  • 1
  • 8
4
votes
2 answers

Retrieving row count from QSqlQuery, but got -1

I'm trying to get the row count of a QSqlQuery, the database driver is qsqlite bool Database::runSQL(QSqlQueryModel *model, const QString & q) { Q_ASSERT (model); model->setQuery(QSqlQuery(q, my_db)); rowCount = model->query().size(); …
daisy
  • 19,459
  • 24
  • 111
  • 218
3
votes
1 answer

Can someone help me with this join statment in SQL? There are two JOINS after each other

In the image below ([2]) on line 20 you see "LEFT JOIN HUB_EMPLOYEES HM" and immediately after a join on LINK_EMPLOYEES. What is the HUB_EMPLOYEES left joined on? The join on LINK_EMPLOYEES is specified on line 21, but I don't see how the left join…
3
votes
2 answers

Invalid length parameter passed to the LEFT or SUBSTRING function ERROR msg

I am working on a query for work. I am attempting to pull the SECOND WORD of a stop name, separated by spaces. So if the stop name is "Jane Doe" I want to pull "Doe." I have a field that I am trying to define in sql, and it looks like this: [pull…
pynewbee
  • 553
  • 1
  • 6
  • 16
3
votes
1 answer

SQL: How to select distinct on some columns

I have a table looking something like this: +---+------------+----------+ |ID | SomeNumber | SomeText | +---+------------+----------+ |1 | 100 | 'hey' | |2 | 100 | 'yo' | |3 | 100 | 'yo' | <- Second occurrence |4 …
Rasmus Bækgaard
  • 1,168
  • 1
  • 8
  • 11
1
2 3
24 25