m15ch4
8th May 2011, 21:57
Hello!
Is it possible to insert row into database using QSqlTableModel giving only NOT NULL values for new row.
For example I have table with 3 collumns:
ID (which is NOT NULL autoincremented integer field using postgresql sequence)
Name (which is NOT NULL varchar value with default value 'John')
Age (which is integer)
I try to do something like this but it doesn't work (no new row is inserted into table):
model.insertRows(0, 1);
model.setData(model.index(0, 1), "Bill");
model.setData(model.index(0, 2), 47);
model.submitAll();
Do I have to retrive next value for ID field from database and then set it for new row using setData or is there some other way?
Thanks,
m15ch4
Is it possible to insert row into database using QSqlTableModel giving only NOT NULL values for new row.
For example I have table with 3 collumns:
ID (which is NOT NULL autoincremented integer field using postgresql sequence)
Name (which is NOT NULL varchar value with default value 'John')
Age (which is integer)
I try to do something like this but it doesn't work (no new row is inserted into table):
model.insertRows(0, 1);
model.setData(model.index(0, 1), "Bill");
model.setData(model.index(0, 2), 47);
model.submitAll();
Do I have to retrive next value for ID field from database and then set it for new row using setData or is there some other way?
Thanks,
m15ch4