本文整理汇总了C++中QSqlTableModel::tableName方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlTableModel::tableName方法的具体用法?C++ QSqlTableModel::tableName怎么用?C++ QSqlTableModel::tableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel::tableName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveDocumentPositions
//.........这里部分代码省略.........
model.setTable("docposition");
model.setEditStrategy(QSqlTableModel::OnManualSubmit);
QVector<int> deleteIds;
DocPositionListIterator it( posList );
while( it.hasNext() ) {
DocPositionBase *dpb = it.next();
DocPosition *dp = static_cast<DocPosition*>(dpb);
QSqlRecord record ;
bool doInsert = true;
int posDbID = dp->dbId().toInt();
kDebug() << "Saving Position DB-Id: " << posDbID << endl;
if( dp->toDelete() ) {
kDebug() << "Delete item " << dp->dbId().toString() << endl;
// store the id to delete, rather than killing the model index.
// did that before here, which removed wrong items.
deleteIds << posDbID;
// delete all existing attributes no, which will not disturb the model index
dp->attributes().dbDeleteAll( dp->dbId() );
continue;
}
if( posDbID > -1 ) {
const QString selStr = QString("docID=%1 AND positionID=%2").arg( doc->docID().toInt() ).arg( posDbID );
// kDebug() << "Selecting with " << selStr << endl;
model.setFilter( selStr );
model.select();
if ( model.rowCount() > 0 ) {
if( ! dp->toDelete() )
record = model.record(0);
doInsert = false;
} else {
kError() << "ERR: Could not select document position record" << endl;
return;
}
} else {
// The record is new
record = model.record();
}
if( record.count() > 0 ) {
// kDebug() << "Updating position " << dp->position() << " is " << dp->text() << endl;
QString typeStr = PosTypePosition;
double price = dp->unitPrice().toDouble();
if ( dp->type() == DocPositionBase::ExtraDiscount ) {
typeStr = PosTypeExtraDiscount;
}
record.setValue( "docID", QVariant(doc->docID().toInt()));
record.setValue( "ordNumber", QVariant(ordNumber));
record.setValue( "text", QVariant(dp->text()));
record.setValue( "postype", QVariant(typeStr));
record.setValue( "amount", QVariant(dp->amount()));
int unitId = dp->unit().id();
record.setValue( "unit", QVariant(unitId));
record.setValue( "price", QVariant(price));
record.setValue( "taxType", QVariant(dp->taxType()));
ordNumber++; // FIXME
if( doInsert ) {
kDebug() << "Inserting!" << endl;
model.insertRecord(-1, record);
model.submitAll();
dp->setDbId( KraftDB::self()->getLastInsertID().toInt() );
} else {
kDebug() << "Updating!" << endl;
model.setRecord(0, record);
model.submitAll();
}
} else {
kDebug() << "ERR: No record object found!" << endl;
}
dp->attributes().save( dp->dbId() );
QSqlError err = model.lastError();
if( err.type() != QSqlError::NoError ) {
kDebug() << "SQL-ERR: " << err.text() << " in " << model.tableName() << endl;
}
}
model.submitAll();
/* remove the docpositions that were marked to be deleted */
if( deleteIds.count() ) {
QSqlQuery delQuery;
delQuery.prepare( "DELETE FROM docposition WHERE positionID=:id" );
foreach( int id, deleteIds ) {
kDebug() << "Deleting attribute id " << id;
delQuery.bindValue( ":id", id );
delQuery.exec();
}