datanas
15th June 2012, 20:52
Hi Guys,
Here's the table:
CREATE TABLE IF NOT EXISTS PersonsTbl(
ID INTEGER NOT NULL AUTO_INCREMENT,
NAME VARCHAR(100) NOT NULL,
MOL VARCHAR(100),
BULSTAT_EGN NUMERIC(10) NOT NULL,
IDNUMDDS VARCHAR(11),
CONTACT VARCHAR(100),
FLAG NUMERIC(1) NOT NULL CHECK(FLAG IN (0, 1)),
TYPEID INTEGER NOT NULL,
CONSTRAINT PersonsTbl_PK PRIMARY KEY(ID));
This is the actual mapping of the fields:
...
orderClientMapper = new QDataWidgetMapper();
orderClientMapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
orderClientMapper->setModel(clientTableModel);
orderClientMapper->setItemDelegate(new QSqlRelationalDelegate());
orderClientMapper->addMapping(clientTypeComboBox, Person_Flag);
orderClientMapper->addMapping(clientNameEdit, Person_Name);
orderClientMapper->addMapping(clientMOLEdit, Person_MOL);
orderClientMapper->addMapping(clientBulstatEgnEdit, Person_ENG_Bulstat);
orderClientMapper->addMapping(clientIdNumDDSEdit, Person_IDNumDDS);
orderClientMapper->addMapping(clientContactEdit, Person_Contact);
...
orderClientMapper->toLast();
When Add button is clicked it should submit a new record but instead it updates the one record I had manually entered
in the DB, i.e. it does not autoincrement the PK.
Here's the actual submit:
int clientRow = orderClientMapper->currentIndex();
QSqlRecord record= clientTableModel->record(clientRow);
record.setValue(Person_Type, 1);
orderClientMapper->submit();
clientTableModel->insertRow(clientRow);
If you have any thoughts why this happens please do share.
Here's the table:
CREATE TABLE IF NOT EXISTS PersonsTbl(
ID INTEGER NOT NULL AUTO_INCREMENT,
NAME VARCHAR(100) NOT NULL,
MOL VARCHAR(100),
BULSTAT_EGN NUMERIC(10) NOT NULL,
IDNUMDDS VARCHAR(11),
CONTACT VARCHAR(100),
FLAG NUMERIC(1) NOT NULL CHECK(FLAG IN (0, 1)),
TYPEID INTEGER NOT NULL,
CONSTRAINT PersonsTbl_PK PRIMARY KEY(ID));
This is the actual mapping of the fields:
...
orderClientMapper = new QDataWidgetMapper();
orderClientMapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
orderClientMapper->setModel(clientTableModel);
orderClientMapper->setItemDelegate(new QSqlRelationalDelegate());
orderClientMapper->addMapping(clientTypeComboBox, Person_Flag);
orderClientMapper->addMapping(clientNameEdit, Person_Name);
orderClientMapper->addMapping(clientMOLEdit, Person_MOL);
orderClientMapper->addMapping(clientBulstatEgnEdit, Person_ENG_Bulstat);
orderClientMapper->addMapping(clientIdNumDDSEdit, Person_IDNumDDS);
orderClientMapper->addMapping(clientContactEdit, Person_Contact);
...
orderClientMapper->toLast();
When Add button is clicked it should submit a new record but instead it updates the one record I had manually entered
in the DB, i.e. it does not autoincrement the PK.
Here's the actual submit:
int clientRow = orderClientMapper->currentIndex();
QSqlRecord record= clientTableModel->record(clientRow);
record.setValue(Person_Type, 1);
orderClientMapper->submit();
clientTableModel->insertRow(clientRow);
If you have any thoughts why this happens please do share.