PDA

View Full Version : Using qsqlrecord?



triperzonak
23rd July 2008, 09:00
hi at this time im using QT3,
can i use qsqlrecord as temporary table from my database so that i can avoid querying every time i need some record?

1.i will create a qsqlrecord with the exact fields and values(data) of a table from the database? how?
2.then i will create a qdatatable from my qsqlrecord but this time limiting the data in qdatatable to 100? how?
3.If # 1 is possible can i do next() previous() last() first()? how?
4.And last If # 1 is possible, if the table from the database was edited i want to somehow refresh my qsqlrecord, again with the same fields and values(data) of table (if # 1 is possible i can use that but I'm looking for faster way i.e qsqlrecord::refresh())

note: if the database is big, it affects querying. :confused:

munna
23rd July 2008, 10:03
1.i will create a qsqlrecord with the exact fields and values(data) of a table from the database? how?

Create a QSqlRecord Object and use void QSqlRecord::setValue ( const QString & name, const QVariant & val ) (http://doc.trolltech.com/3.3/qsqlrecord.html#setValue-2)


2.then i will create a qdatatable from my qsqlrecord but this time limiting the data in qdatatable to 100? how?

QSqlRecord can hold only one record. If I understand you right, I don't think this is possible with QSqlRecord.


3.If # 1 is possible can i do next() previous() last() first()? how?
You cannot do next() previous() etc on QSqlRecord, but you can get the field value using the field name or the index of the field.


4.And last If # 1 is possible, if the table from the database was edited i want to somehow refresh my qsqlrecord, again with the same fields and values(data) of table (if # 1 is possible i can use that but I'm looking for faster way i.e qsqlrecord::refresh())

I think you will need to use QSqlQuery along with QSqlRecord to achieve this.

triperzonak
23rd July 2008, 11:04
Create a QSqlRecord Object and use void QSqlRecord::setValue ( const QString & name, const QVariant & val ) (http://doc.trolltech.com/3.3/qsqlrecord.html#setValue-2)

QSqlRecord can hold only one record. If I understand you right, I don't think this is possible with QSqlRecord.

if i understand you right(same), your answer to #1 conflicts your answer to #2. If Qsqlrecord can only hold 1 record (do you mean one row of data?) then it is not the exact table with the all data from the table(to be copied) in the database (ex. a glass from a "glass with water") please clarify..

answer to #1 QSqlRecord::setValue ( const QString & name, const QVariant & val ) can only be use in 1 row of data of 1 table or all the data from 1 table? do i need to use query.next() to insert all the data from one table?

answer to #2 Setting Limit is possible in qdatatable, if i could just set a qsqlcursor or something like it, to the sqlrecord (but i need all the data from one table to be hold by sqlrecord)



You cannot do next() previous() etc on QSqlRecord, but you can get the field value using the field name or the index of the field.


answer to #3 next() previous() last() and first() is possible using qdatabrowser (i just want the whole table to be hold by a sqlrecord if it possible then setting qsqlcursor or something like qsqlcursor, to it)

what i want is to create a sqlrecord with the same fields and data with one table from the database.
Then instead of using query statements i will just manipulate the sqlrecord.

But again i cant pass qsqlrecord (if the 1st problem was solve) to qdatatable or qdatabrowser, am i right about this?? or it is possible to pass qsqlrecord to qdatatable or qsqldatabrowser..


if not, i need to use qsqlcursor(or something like it) but instead of querying to database it will select all the data of sqlrecord since manipulation can be done by qdatatable and qdatabrowser.