本文整理汇总了C++中QSqlError类的典型用法代码示例。如果您正苦于以下问题:C++ QSqlError类的具体用法?C++ QSqlError怎么用?C++ QSqlError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSqlError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: it
void DocumentSaverDB::saveDocumentPositions( KraftDoc *doc )
{
DocPositionList posList = doc->positions();
// invert all pos numbers to avoid a unique violation
// FIXME: We need non-numeric ids
QSqlQuery upq;
QString queryStr = "UPDATE docposition SET ordNumber = -1 * ordNumber WHERE docID=";
queryStr += doc->docID().toString();
queryStr += " AND ordNumber > 0";
upq.prepare( queryStr );
upq.exec();
int ordNumber = 1;
QSqlTableModel model;
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();
//.........这里部分代码省略.........
示例2: TR
// this differs from the version it was copied from in loadable.cpp
int CreateDBObj::upsertPkgItem(const int pkgheadid, const int itemid,
QString &errMsg)
{
QString sqlerrtxt = TR("<font color=red>The following error was "
"encountered while trying to import %1 into "
"the database:<br>%2<br>%3</font>");
if (pkgheadid < 0)
return 0;
int pkgitemid = -1;
QSqlQuery select;
select.prepare("SELECT pkgitem_id "
"FROM pkgitem "
"WHERE ((pkgitem_pkghead_id=:headid)"
" AND (pkgitem_type=:type)"
" AND (pkgitem_name=:name));");
select.bindValue(":headid", pkgheadid);
select.bindValue(":type", _pkgitemtype);
select.bindValue(":name", _name);
select.exec();
if (select.first())
pkgitemid = select.value(0).toInt();
if (select.lastError().type() != QSqlError::NoError)
{
errMsg = sqlerrtxt.arg(_filename)
.arg(select.lastError().databaseText())
.arg(select.lastError().driverText());
return -20;
}
QSqlQuery upsert;
if (pkgitemid >= 0)
upsert.prepare("UPDATE pkgitem SET pkgitem_descrip=:descrip,"
" pkgitem_item_id=:itemid "
"WHERE (pkgitem_id=:id);");
else
{
upsert.prepare("SELECT NEXTVAL('pkgitem_pkgitem_id_seq');");
upsert.exec();
if (upsert.first())
pkgitemid = upsert.value(0).toInt();
else if (upsert.lastError().type() != QSqlError::NoError)
{
QSqlError err = upsert.lastError();
errMsg = sqlerrtxt.arg(_name).arg(err.driverText()).arg(err.databaseText());
return -21;
}
upsert.prepare("INSERT INTO pkgitem ("
" pkgitem_id, pkgitem_pkghead_id, pkgitem_type,"
" pkgitem_item_id, pkgitem_name, pkgitem_descrip"
") VALUES ("
" :id, :headid, :type,"
" :itemid, :name, :descrip);");
}
upsert.bindValue(":id", pkgitemid);
upsert.bindValue(":headid", pkgheadid);
upsert.bindValue(":type", _pkgitemtype);
upsert.bindValue(":itemid", itemid);
upsert.bindValue(":name", _name);
upsert.bindValue(":descrip", _comment);
if (!upsert.exec())
{
QSqlError err = upsert.lastError();
errMsg = sqlerrtxt.arg(_name).arg(err.driverText()).arg(err.databaseText());
return -22;
}
return pkgitemid;
}
示例3: linkset
void Database::writeLinkSet()
{
/*Before the opening of each transaction,adding this code to improve the speed*/
QSqlDatabase::database().transaction();
QSqlQuery query;
query.prepare("INSERT INTO linkset(linkid, linkshield, linksetup, linktype, linknum, "
"linkINInfo1, linkINInfo2, linkINInfo3, linkINInfo4, linkINInfo5, linkINInfo6, linkINInfo7, linkINInfo8, linkINInfo9, linkINInfo10,"
"linkINInfo11, linkINInfo12, linkINInfo13, linkINInfo14, linkINInfo15, linkINInfo16, linkINInfo17, linkINInfo18, linkINInfo19,"
"linkINInfo20, linkINInfo21, linkINInfo22, linkINInfo23, linkINInfo24, linkINInfo25, linkINInfo26, linkINInfo27, linkINInfo28, "
"linkINInfo29, linkINInfo30, linkINInfo31, linkOUTInfo1, linkOUTInfo2, linkOUTInfo3, linkOUTInfo4, linkOUTInfo5, linkOUTInfo6,"
"linkOUTInfo7, linkOUTInfo8, linkOUTInfo9, linkOUTInfo10, linkOUTInfo11, linkOUTInfo12, linkOUTInfo13, linkOUTInfo14,"
"linkOUTInfo15, linkOUTInfo16, linkOUTInfo17, linkOUTInfo18, linkOUTInfo19, linkOUTInfo20, linkOUTInfo21, linkOUTInfo22, "
"linkOUTInfo23, linkOUTInfo24, linkOUTInfo25, linkOUTInfo26, linkOUTInfo27, linkOUTInfo28, linkOUTInfo29, linkOUTInfo30, linkOUTInfo31)"
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
for (int i = 0;i<30; i++)
{
long long int host = 0;
long long int iobr = 0;
int loop = 0;
int dnode = 0;
int dline = 0;
long long int linkINInfo1 = (host<<32) | (iobr<<24) | (loop<<16) | (dnode<<8) | (dline);
int znodestar = 0;
int znodeend = 0;
int zequiptype = 0;
int zsetupnum = 0;
long long int linkOUTInfo1 = ((long long int)host<<48)
| ((long long int)iobr<<40)
| ((long long int)loop<<32)
| (znodestar<<24)
| (znodeend<<16)
| (zequiptype<<8)
| zsetupnum;
query.bindValue(0,i+1);
query.bindValue(1,0);
query.bindValue(2,0);
query.bindValue(3,4);
query.bindValue(4,1);
for (int j=0; j<31; j++)
{
query.bindValue(j+5,linkINInfo1);
}
for (int j=0; j<31; j++)
{
query.bindValue(j+36,linkOUTInfo1);
}
bool bSuccess = query.exec();
if (!bSuccess)
{
QSqlError lastError = query.lastError();
qDebug() << lastError.driverText()
<<QString(QObject::tr("insert 联动error"));
}
}
/*Close the transaction*/
QSqlDatabase::database().commit();
}
示例4: TR
int LoadMetasql::writeToDB(const QByteArray &pdata, const QString pkgname, QString &errMsg)
{
if (pdata.isEmpty())
{
errMsg = TR("<font color=orange>The MetaSQL statement %1 is empty.</font>")
.arg(_name);
return -2;
}
QString metasqlStr = QString(pdata);
QStringList lines = metasqlStr.split("\n");
QRegExp groupRE = QRegExp("(^\\s*--\\s*GROUP:\\s*)(.*)",Qt::CaseInsensitive);
QRegExp nameRE = QRegExp("(^\\s*--\\s*NAME:\\s*)(.*)", Qt::CaseInsensitive);
QRegExp notesRE = QRegExp("(^\\s*--\\s*NOTES:\\s*)(.*)",Qt::CaseInsensitive);
QRegExp dashdashRE = QRegExp("(^\\s*--\\s*)(.*)");
for (int i = 0; i < lines.size(); i++)
{
if (DEBUG)
qDebug("LoadMetasql::writeToDB looking at %s", qPrintable(lines.at(i)));
if (groupRE.indexIn(lines.at(i)) >= 0)
{
_group = groupRE.cap(2).trimmed();
if (DEBUG)
qDebug("LoadMetasql::writeToDB() found group %s", qPrintable(_group));
}
else if (nameRE.indexIn(lines.at(i)) >= 0)
{
_name = nameRE.cap(2).trimmed();
if (DEBUG)
qDebug("LoadMetasql::writeToDB() found name %s", qPrintable(_name));
}
else if (notesRE.indexIn(lines.at(i)) >= 0)
{
_comment = notesRE.cap(2).trimmed();
while (dashdashRE.indexIn(lines.at(++i)) >= 0)
_comment += " " + dashdashRE.cap(2).trimmed();
if (DEBUG)
qDebug("LoadMetasql::writeToDB() found notes %s", qPrintable(_comment));
}
}
if (DEBUG)
qDebug("LoadMetasql::writeToDB(): name %s group %s notes %s\n%s",
qPrintable(_name), qPrintable(_group), qPrintable(_comment),
qPrintable(metasqlStr));
QString destschema = "public";
if (_schema.isEmpty() && pkgname.isEmpty())
; // leave it alone
else if (_schema.isEmpty() && ! pkgname.isEmpty())
destschema = pkgname;
else if ("public" == _schema)
; // leave it alone
else if (! _schema.isEmpty())
destschema = _schema;
XSqlQuery gradedsavepoint("SAVEPOINT savemetasql_graded;");
MetaSQLQuery upsertm("SELECT saveMetasql(<? value('group') ?>,"
" <? value('name') ?>, <? value('notes') ?>,"
" E<? value('query') ?>,"
" CAST(<? value('system') ?> AS BOOLEAN),"
" <? value('schema') ?>"
"<? if not exists('skipgrade') ?>"
" , <? value('grade') ?>"
"<? endif ?>"
") AS result;");
ParameterList upsertp;
upsertp.append("group", _group);
upsertp.append("name", _name);
upsertp.append("notes", _comment);
upsertp.append("query", metasqlStr);
upsertp.append("system",_system);
upsertp.append("schema",destschema);
upsertp.append("grade", _grade);
int metasqlid = -1;
XSqlQuery upsert = upsertm.toQuery(upsertp);
if (upsert.first())
metasqlid = upsert.value(0).toInt();
else if (upsert.lastError().type() != QSqlError::NoError)
{
XSqlQuery gradedrollback("ROLLBACK TO SAVEPOINT savemetasql_graded;");
upsertp.append("skipgrade");
upsert = upsertm.toQuery(upsertp);
if (upsert.first())
metasqlid = upsert.value(0).toInt();
if (upsert.lastError().type() != QSqlError::NoError)
{
QSqlError err = upsert.lastError();
errMsg = _sqlerrtxt.arg(_filename).arg(err.driverText()).arg(err.databaseText());
return -6;
}
}
else
{
errMsg = TR("Saving the MetaSQL statement returned 0 rows. This should "
"not be possible.");
//.........这里部分代码省略.........
示例5: qDebug
void DatabaseFacade::addUserStat( int userId, const QString& gameName_, int score_ )
{
if(!connected)
{
qDebug() << "Not connected to database";
return;
}
QSqlQuery query;
QSqlQuery query2;
qDebug() << "Executing query : \n\t" << queryGetGamerHighScore.arg(gameName_).arg(userId);
query.exec(queryGetGamerHighScore.arg(gameName_).arg(userId));
QSqlError err = query.lastError();
if(err.isValid())
qDebug() << err.databaseText() << "\n" << err.driverText() << "\n" << err.nativeErrorCode();
if(query.next())
{
if(query.value(1).toInt() < score_)
{
qDebug() << "Executing query : \n\t" << queryUpdateHighScore.arg(score_).arg(query.value(0).toString()).arg(userId);
query2.exec(queryUpdateHighScore.arg(score_).arg(query.value(0).toString()).arg(userId));
err = query2.lastError();
if(err.isValid())
qDebug() << err.databaseText() << "\n" << err.driverText() << "\n" << err.nativeErrorCode();
}
}
else
{
qDebug() << "Executing query : \n\t" << queryInsertHighScore.arg(userId).arg(gameName_).arg(score_);
query2.exec(queryInsertHighScore.arg(userId).arg(gameName_).arg(score_));
err = query2.lastError();
if(err.isValid())
qDebug() << err.databaseText() << "\n" << err.driverText() << "\n" << err.nativeErrorCode();
}
}
示例6:
void ErrorDialog::operator <<(const QSqlError& rhs)
{
m_message = rhs.text();
this->show();
}
示例7: showError
void Database::showError(const QSqlError &err)
{
QMessageBox::critical(0, QMessageBox::tr("Erro"),QMessageBox::tr("Erro no banco de dados: ") + err.text());
}
示例8: qDebug
DatabaseException::DatabaseException(const QSqlError& error)
{
m_message = error.text();
qDebug() << "DatabaseException: error = " << m_message;
}
示例9: qDebug
int Prerequisite::writeToDB(const QString pkgname, QString &errMsg)
{
if (DEBUG)
qDebug("Prerequisite::writeToDB(%s, &errMsg)", qPrintable(pkgname));
if (! pkgname.isEmpty() && _dependency)
{
QSqlQuery select;
int pkgheadid = -1;
select.prepare("SELECT pkghead_id FROM pkghead WHERE (pkghead_name=:name);");
select.bindValue(":name", pkgname);
select.exec();
if (select.first())
pkgheadid = select.value(0).toInt();
else if (select.lastError().type() != QSqlError::NoError)
{
errMsg = _sqlerrtxt.arg(_name)
.arg(select.lastError().databaseText())
.arg(select.lastError().driverText());
return -1;
}
int parentid = -1;
QString sql = "SELECT * FROM pkghead WHERE ((pkghead_name=:name) ";
if (! _dependency->version().isEmpty())
sql += "AND (pkghead_version=:version) ";
if (! _dependency->developer().isEmpty())
sql += "AND (pkghead_developer=:developer) ";
sql += ") ORDER BY pkghead_version DESC LIMIT 1;";
select.prepare(sql);
select.bindValue(":name", _dependency->name());
select.bindValue(":version", _dependency->version());
select.bindValue(":developer", _dependency->developer());
select.exec();
if (select.first())
parentid = select.value(0).toInt();
else if (select.lastError().type() != QSqlError::NoError)
{
errMsg = _sqlerrtxt.arg(_name)
.arg(select.lastError().databaseText())
.arg(select.lastError().driverText());
return -2;
}
else
{
errMsg = TR("Could not record the dependency %1 of package %2 "
"on package %3 (version %4, developer %5) because "
"the record for %6 was not found.")
.arg(_name).arg(pkgname).arg(_dependency->name())
.arg(_dependency->version().isEmpty() ?
TR("Unspecified") : _dependency->version())
.arg(_dependency->developer().isEmpty() ?
TR("Unspecified") : _dependency->developer())
.arg(_dependency->name());
return -3;
}
int pkgdepid = -1;
select.prepare("SELECT * FROM pkgdep "
"WHERE ((pkgdep_pkghead_id=:pkgheadid)"
" AND (pkgdep_parent_pkghead_id=:parentid));");
select.bindValue(":pkgheadid", pkgheadid);
select.bindValue(":parentid", parentid);
select.exec();
if (select.first())
pkgdepid=select.value(0).toInt();
else if (select.lastError().type() != QSqlError::NoError)
{
errMsg = _sqlerrtxt.arg(_name)
.arg(select.lastError().databaseText())
.arg(select.lastError().driverText());
return -4;
}
QSqlQuery upsert;
if (pkgdepid > 0)
upsert.prepare("UPDATE pkgdep "
"SET pkgdep_pkghead_id=:pkgheadid,"
" pkgdep_parent_pkghead_id=:parentid "
"WHERE (pkgdep_id=:pkgdepid);");
else
{
upsert.exec("SELECT NEXTVAL('pkgdep_pkgdep_id_seq');");
if (upsert.first())
pkgdepid = upsert.value(0).toInt();
else if (upsert.lastError().type() != QSqlError::NoError)
{
QSqlError err = upsert.lastError();
errMsg = _sqlerrtxt.arg(_name).arg(err.driverText()).arg(err.databaseText());
return -5;
}
upsert.prepare("INSERT INTO pkgdep ("
" pkgdep_id, pkgdep_pkghead_id, pkgdep_parent_pkghead_id"
") VALUES ("
" :pkgdepid, :pkgheadid, :parentid);");
}
upsert.bindValue(":pkgdepid", pkgdepid);
upsert.bindValue(":pkgheadid", pkgheadid);
//.........这里部分代码省略.........
示例10: logSql
quint64 IssueLogger::logSql(const QSqlError &err)
{
//TODO more info about the error for databases
return log(err.text(), IssueObject::itError);
}
示例11: QTableView
_qbe_browser::_qbe_browser(QWidget *_parent, QString _sSQL, QString _sSQLREAL) : QTableView(0)
{
parent = _parent;
sSQL = _sSQL;
sSQLREAL = _sSQLREAL;
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(_sSQLREAL);
setWindowIcon(kbasicIcon(kbasicPath("ide/PROJECT_NEW_QUERY.png")));
// bool bb = CurrentDatabase.open();
/* QSqlQuery query("", db);
bb = query.exec("SELECT * FROM address");
while (query.next()){
QMessageBox::information(this, "", query.value(0).toString());
}
QMessageBox::information(this, "Database Error", query.lastError().text());
*/
// QSqlQuery *query = new QSqlQuery("", CurrentDatabase);
// bb = query->exec(sSQL);
//mydb = CurrentDatabase.cloneDatabase();
model = new QSqlQueryModel();
model->setQuery(sSQL, CurrentDatabase);
setWindowTitle(tr("#") + QString("%1").arg(model->rowCount()) + " : " + windowTitle());
//model->clear();
// query->clear();
QSqlError e = CurrentDatabase.lastError();
if (e.type() != QSqlError::NoError){
QMessageBox::information(this, "Database Error", e.text());
//if (model) delete model; model = 0;
//query.clear();
close();
return;
}
this->setModel(model);
//int n = 0;
//bool b = model->query().exec();
if (model->lastError().type() != QSqlError::NoError){
QMessageBox::information(this, "Database Error", (model->lastError().text()));
//query.clear();
//if (model) delete model; model = 0;
close();
return;
}
showMaximized();
/*
if (model->query().isSelect());
//QMessageBox::information(this, MYAPP, (tr("Query OK.")));
else
QMessageBox::information(this, MYAPP, (tr("Query OK, number of affected rows: %1").arg(
model->query().numRowsAffected())));
*/
}
示例12: COALESCE
int PkgSchema::upsertPkgItem(const int itemid,
QString &errMsg)
{
int pkgheadid = -1;
int pkgitemid = -1;
QSqlQuery select;
select.prepare("SELECT pkghead_id, COALESCE(pkgitem_id, -1) "
"FROM pkghead LEFT OUTER JOIN"
" pkgitem ON ((pkgitem_name=pkghead_name)"
" AND (pkgitem_pkghead_id=pkghead_id)"
" AND (pkgitem_type='S'))"
"WHERE (LOWER(pkghead_name)=LOWER(:name));");
select.bindValue(":name", _name);
select.exec();
if (select.first())
{
pkgheadid = select.value(0).toInt();
pkgitemid = select.value(1).toInt();
}
else if (select.lastError().type() != QSqlError::NoError)
{
errMsg = _sqlerrtxt.arg(_name)
.arg(select.lastError().databaseText())
.arg(select.lastError().driverText());
return -20;
}
else
{
errMsg = TR("Could not find pkghead record for package %1.").arg(_name);
return -21;
}
QSqlQuery upsert;
if (pkgitemid >= 0)
upsert.prepare("UPDATE pkgitem SET pkgitem_descrip=:descrip,"
" pkgitem_item_id=:itemid "
"WHERE (pkgitem_id=:id);");
else
{
upsert.prepare("SELECT NEXTVAL('pkgitem_pkgitem_id_seq');");
upsert.exec();
if (upsert.first())
pkgitemid = upsert.value(0).toInt();
else if (upsert.lastError().type() != QSqlError::NoError)
{
QSqlError err = upsert.lastError();
errMsg = _sqlerrtxt.arg(_name)
.arg(err.driverText()).arg(err.databaseText());
return -22;
}
upsert.prepare("INSERT INTO pkgitem ("
" pkgitem_id, pkgitem_pkghead_id, pkgitem_type,"
" pkgitem_item_id, pkgitem_name, pkgitem_descrip"
") VALUES ("
" :id, :headid, 'S',"
" :itemid, :name, :descrip);");
}
upsert.bindValue(":id", pkgitemid);
upsert.bindValue(":headid", pkgheadid);
upsert.bindValue(":itemid", itemid);
upsert.bindValue(":name", _name);
upsert.bindValue(":descrip", _comment);
if (!upsert.exec())
{
QSqlError err = upsert.lastError();
errMsg = _sqlerrtxt.arg(_name)
.arg(err.driverText()).arg(err.databaseText());
return -23;
}
return pkgitemid;
}
示例13: kDebug
bool DocumentSaverDB::saveDocument(KraftDoc *doc )
{
bool result = false;
if( ! doc ) return result;
QSqlTableModel model;
model.setTable("document");
QSqlRecord record;
kDebug() << "############### Document Save ################" << endl;
if( doc->isNew() ) {
record = model.record();
} else {
model.setFilter("docID=" + doc->docID().toString());
model.select();
if ( model.rowCount() > 0 ) {
record = model.record(0);
} else {
kError() << "Could not select document record" << endl;
return result;
}
// The document was already saved.
}
if( !doc->isNew() && doc->docTypeChanged() && doc->newIdent() ) {
// an existing doc has a new document type. Fix the doc number cycle and pick a new ident
DocType dt( doc->docType() );
QString ident = dt.generateDocumentIdent( doc );
doc->setIdent( ident );
}
fillDocumentBuffer( record, doc );
if( doc->isNew() ) {
kDebug() << "Doc is new, inserting" << endl;
if( !model.insertRecord(-1, record)) {
QSqlError err = model.lastError();
kDebug() << "################# SQL Error: " << err.text();
}
model.submitAll();
dbID id = KraftDB::self()->getLastInsertID();
doc->setDocID( id );
// get the uniq id and write it into the db
DocType dt( doc->docType() );
QString ident = dt.generateDocumentIdent( doc );
doc->setIdent( ident );
model.setFilter("docID=" + id.toString());
model.select();
if ( model.rowCount() > 0 ) {
model.setData(model.index(0, 1), ident);
model.submitAll();
}
} else {
kDebug() << "Doc is not new, updating #" << doc->docID().intID() << endl;
record.setValue( "docID", doc->docID().toString() );
model.setRecord(0, record);
model.submitAll();
}
saveDocumentPositions( doc );
kDebug() << "Saved document no " << doc->docID().toString() << endl;
return result;
}
示例14: i18n
bool DatabaseDialog::databaseDoNext()
{
m_dbConnection = QSqlDatabase::addDatabase(m_driver->currentText());
if (m_dbConnection.isValid()) {
m_dbConnection.setDatabaseName(m_databaseName->text());
m_dbConnection.setHostName(m_host->text());
if (!m_username->text().isEmpty())
m_dbConnection.setUserName(m_username->text());
if (!m_password->text().isEmpty())
m_dbConnection.setPassword(m_password->text());
if (!m_port->text().isEmpty()) {
bool ok = false;
int port = m_port->text().toInt(&ok);
if (!ok) {
KMessageBox::error(this, i18n("The port must be a number"));
return false;
}
m_dbConnection.setPort(port);
}
m_databaseStatus->setText(i18n("Connecting to database..."));
if (m_dbConnection.open()) {
m_databaseStatus->setText(i18n("Connected. Retrieving table information..."));
QStringList tableList(m_dbConnection.tables());
if (tableList.isEmpty()) {
KMessageBox::error(this, i18n("This database contains no tables"));
m_databaseStatus->setText(" ");
return false;
}
m_tableView->clear();
for (int i = 0; i < tableList.size(); ++i) {
QListWidgetItem * item = new QListWidgetItem(tableList[i]);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);
m_tableView->addItem(item);
}
m_tableView->setEnabled(true);
m_databaseStatus->setText(" ");
} else {
QSqlError error = m_dbConnection.lastError();
QString errorMsg;
QString err1 = error.driverText();
QString err2 = error.databaseText();
if (!err1.isEmpty()) {
errorMsg.append(error.driverText());
errorMsg.append('\n');
}
if (!err2.isEmpty() && err1 != err2) {
errorMsg.append(error.databaseText());
errorMsg.append('\n');
}
KMessageBox::error(this, errorMsg);
m_databaseStatus->setText(" ");
return false;
}
} else {
KMessageBox::error(this, i18n("Driver could not be loaded"));
m_databaseStatus->setText(" ");
return false;
}
setValid(m_table, true);
return true;
}
示例15: TR
int Package::writeToDB(QString &errMsg)
{
XSqlQuery select;
XSqlQuery upsert;
QString sqlerrtxt = TR("<font color=red>The following error was "
"encountered while trying to import %1 into "
"the database:<br>%2<br>%3</font>");
if (_name.isEmpty())
return 0; // if there's no name then there's no package to create
int pkgheadid = -1;
select.prepare("SELECT pkghead_id FROM pkghead WHERE (pkghead_name=:name);");
select.bindValue(":name", _name);
select.exec();
if (select.first())
{
pkgheadid = select.value(0).toInt();
upsert.prepare("UPDATE pkghead "
" SET pkghead_name=:name,"
" pkghead_descrip=:descrip,"
" pkghead_version=:version,"
" pkghead_developer=:developer,"
" pkghead_notes=:notes "
"WHERE (pkghead_id=:id);");
}
else if (select.lastError().type() != QSqlError::NoError)
{
QSqlError err = select.lastError();
errMsg = sqlerrtxt.arg(_name).arg(err.driverText()).arg(err.databaseText());
return -1;
}
else
{
upsert.exec("SELECT NEXTVAL('pkghead_pkghead_id_seq');");
if (upsert.first())
pkgheadid = upsert.value(0).toInt();
else if (upsert.lastError().type() != QSqlError::NoError)
{
QSqlError err = upsert.lastError();
errMsg = sqlerrtxt.arg(_name).arg(err.driverText()).arg(err.databaseText());
return -2;
}
upsert.prepare("INSERT INTO pkghead ("
" pkghead_id, pkghead_name, pkghead_descrip,"
" pkghead_version, pkghead_developer, pkghead_notes"
") VALUES ("
" :id, :name, :descrip, :version, :developer, :notes);");
}
upsert.bindValue(":id", pkgheadid);
upsert.bindValue(":name", _name);
upsert.bindValue(":descrip", _descrip);
upsert.bindValue(":version", _pkgversion.toString());
upsert.bindValue(":developer", _developer);
upsert.bindValue(":notes", _notes);
if (!upsert.exec())
{
QSqlError err = upsert.lastError();
errMsg = sqlerrtxt.arg(_name).arg(err.driverText()).arg(err.databaseText());
return -3;
}
return pkgheadid;
}