My *guess* at what might be best for you is the SQL record data. If that's enough for the thing to do its job, that's what you should send.
Thanks for your answer. Perfect, thats what I chose to try. Here is what I wrote:
if (customerSelect->exec())
{
...
}
if (customerSelect->exec())
{
QSqlRecord record = customerSelect->passRecord();
...
}
To copy to clipboard, switch view to plain text mode
{
QSqlRecord record
= modelCustomer
->record
(index.
row());
return record;
}
QSqlRecord SelectAddress::passRecord()
{
QModelIndex index = tableView->currentIndex();
QSqlRecord record = modelCustomer->record(index.row());
return record;
}
To copy to clipboard, switch view to plain text mode
It's working fine.
Can you help me with another quick question:
I would like to assign a customer number to every entry in the customer-database. It should be a concatenation of a Prefix, e.g. "C" and a number.
As number I would like to use either the number of rows (means customers) in the database or the PrimaryKey for that row.
Do you know how I can access the primary key for the row, or the highest primary key?
So far I found two possibilities, but maybe there are "cleaner" ones.
1.) The number of entries ist listed in a special table for SQLite databases, read the value from there:
QSqlQuery query
("SELECT * FROM sqlite_sequence");
int fieldNo = query.record().indexOf("seq");
while (query.next()) {
QString rows
= query.
value(fieldNo
).
toString();
out << "rows: " << rows << "\n";
}
QSqlQuery query("SELECT * FROM sqlite_sequence");
int fieldNo = query.record().indexOf("seq");
while (query.next()) {
QString rows = query.value(fieldNo).toString();
out << "rows: " << rows << "\n";
}
To copy to clipboard, switch view to plain text mode
2.) List the all customer entries and read the number of lines using query.size() or just count them using a loop.
int rows = query2.size();
QSqlQuery query("SELECT * FROM customers");
int rows = query2.size();
To copy to clipboard, switch view to plain text mode
But using size() always returns -1, I found out right know that's because SQLite does not support size().
Are there other possibilities?
But both methods are not working if rows have been deleted...
Bookmarks