I am working on a small application in Qt, and I use the SQL library along with SQLite as a database. So far, it has worked out well. The QSqlQuery class provides only a method for retrieving the values of an index column instead of a field name . However, using the record() function, the current query string can be turned into QSqlRecord , which has a value() function to get values by the field name.
So this works very well and allows me to write shorter and cleaner code, but a connection request such as the following causes problems:
SELECT t1.*, t2.* FROM table1 AS t1, table2 AS t2 WHERE t1.table2_id=t2.id
So, we execute this request as usual and convert the string to a record. But it turns out that the column names in QSqlRecord do not have a prefix with the table name - for example, there are two columns named id in the record object. This is obviously a bit problematic.
What is the best solution to this problem?
(I found this problem in the Qt error debugger, but that doesn't help much.)
Veeti source share