rquery.prepare("Select * from wbn where insp_nip = :nip");
rquery.bindValue(":nip", "9262485545"); //selecting values from remote database
if(rquery.exec()){
while(rquery.next()){
query.prepare("Select id, count(*) from wbn where database_id = :id");
query.bindValue(":id", rquery.value(0).toInt()); //getting id and count from local database to see if we need to insert or update
query.next();
int id = 0;
if (!query.exec() || !query.first()){
qDebug() << query.lastError().text();
}else if (query.value(1) == 0){
//We need to insert, this part works great;
id = accomodationsModel->rowCount();
qDebug() << "id = " << id;
accomodationsModel->insertRow(id);
accomodationsModel->setData(accomodationsModel->index(id, 1), rquery.value(0).toInt());
}else{
//We need to update, from debuging everything seems fine
int id = query.value(0).toInt();
for(int row=0; row < accomodationsModel->rowCount(); ++row)
{
if (accomodationsModel->index(row, 0).data(Qt::DisplayRole).toInt() == id )
id = row;
}
//primary key to QSqlTableModel row, any better way to do it ?
}
for(int i = 2; i < 45; i++){
QString field
= rquery.
value(i
).
toString();
accomodationsModel->setData(accomodationsModel->index(id, i), field);
//seting data to model
}
}
ret = accomodationsModel->submitAll();
//submiting all, here it fails, there is no error, but only last QSqlTableModel row is really updated, from qDebug i can see that setData is setting good values, so problem is only with submitAll() i think ?
QSqlQuery rquery(remotedb);
rquery.prepare("Select * from wbn where insp_nip = :nip");
rquery.bindValue(":nip", "9262485545"); //selecting values from remote database
if(rquery.exec()){
while(rquery.next()){
QSqlQuery query;
query.prepare("Select id, count(*) from wbn where database_id = :id");
query.bindValue(":id", rquery.value(0).toInt()); //getting id and count from local database to see if we need to insert or update
query.next();
int id = 0;
if (!query.exec() || !query.first()){
qDebug() << query.lastError().text();
}else if (query.value(1) == 0){
//We need to insert, this part works great;
id = accomodationsModel->rowCount();
qDebug() << "id = " << id;
accomodationsModel->insertRow(id);
accomodationsModel->setData(accomodationsModel->index(id, 1), rquery.value(0).toInt());
}else{
//We need to update, from debuging everything seems fine
int id = query.value(0).toInt();
for(int row=0; row < accomodationsModel->rowCount(); ++row)
{
if (accomodationsModel->index(row, 0).data(Qt::DisplayRole).toInt() == id )
id = row;
}
//primary key to QSqlTableModel row, any better way to do it ?
}
for(int i = 2; i < 45; i++){
QString field = rquery.value(i).toString();
accomodationsModel->setData(accomodationsModel->index(id, i), field);
//seting data to model
}
}
ret = accomodationsModel->submitAll();
//submiting all, here it fails, there is no error, but only last QSqlTableModel row is really updated, from qDebug i can see that setData is setting good values, so problem is only with submitAll() i think ?
To copy to clipboard, switch view to plain text mode
Bookmarks