Hi List,

I am trying to add a record to a QSqlTableModel like this:

QSqlRecord record =  new QSqlRecord(model.record());
record.setValue("ID", 11112);
record.setValue("NAME", "myname1");
record.setValue("COUNTRYID", 1);
record.setValue("LASTNAME", "My country");

System.out.println(record);

model.insertRecord(-1, record);

System.err.println(model.lastError().driverText());

The first printout shows the record as empty:

QSqlRecord( 4 )
 " 0:" QSqlField("ID", int, length: 11, precision: 10, required: yes,
generated: yes) ""
 " 1:" QSqlField("NAME", QString, length: 100, precision: 100,
required: no, generated: yes) ""
 " 2:" QSqlField("LASTNAME", QString, length: 100, precision: 100,
required: no, generated: yes) ""
 " 3:" QSqlField("COUNTRYID", int, length: 11, precision: 10,
required: no, generated: yes) ""

And the second printout shows an error:

"No Fields to update"

I tried also to copy all the fields into a new empty QSqlRecord, which
gives me finally a non empty record, but model.insertRecord() still
gives the same error.

I am using the QJDBC driver, so I wrote my own driver, well I copy /
pasted the code from QJDBCSqlDriver as it is protected and cannot be
extended, I overrode the sqlStatement method to catch what was
happening.

The record passed to the sqlStatement method is empty(!), it must get
lost somewhere between insertRecord and sqlStatement in the C++
implementation of qsqltablemodel.

Maybe I am using QSqlRecord the wrong way?

If so, how do I insert data in a qsqltablemodel?

Thanks for helping,
-- 
Stéphane Konstantaropoulos
--> ! <--

_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to