本文整理汇总了C++中QSqlError::type方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlError::type方法的具体用法?C++ QSqlError::type怎么用?C++ QSqlError::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlError
的用法示例。
在下文中一共展示了QSqlError::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runQuery
void SQLManager::runQuery(const QString &text, const QString &connection)
{
kDebug() << "connection:" << connection;
kDebug() << "text:" << text;
if (text.isEmpty())
return;
if (!isValidAndOpen(connection))
return;
QSqlDatabase db = QSqlDatabase::database(connection);
QSqlQuery query(db);
if (!query.prepare(text))
{
QSqlError err = query.lastError();
if (err.type() == QSqlError::ConnectionError)
m_model->setStatus(connection, Connection::OFFLINE);
emit error(err.text());
return;
}
if (!query.exec())
{
QSqlError err = query.lastError();
if (err.type() == QSqlError::ConnectionError)
m_model->setStatus(connection, Connection::OFFLINE);
emit error(err.text());
return;
}
QString message;
/// TODO: improve messages
if (query.isSelect())
{
if (!query.driver()->hasFeature(QSqlDriver::QuerySize))
message = i18nc("@info/plain", "Query completed successfully");
else
{
int nRowsSelected = query.size();
message = i18ncp("@info/plain", "%1 record selected", "%1 records selected", nRowsSelected);
}
}
else
{
int nRowsAffected = query.numRowsAffected();
message = i18ncp("@info/plain", "%1 row affected", "%1 rows affected", nRowsAffected);
}
emit success(message);
emit queryActivated(query, connection);
}
示例2: deleteTemplate
void tableTemplateWidget::deleteTemplate(void)
{
if (templateId == 0)
return;
QMessageBox delTmp(QMessageBox::Question,
tr("Deleting template!"),
tr("Do you want delete template ?"),
QMessageBox::Yes | QMessageBox::No);
int code = delTmp.exec();
if (code == QMessageBox::No)
return;
QSqlQuery query;
QSqlError le;
query.prepare("DELETE FROM crossword.private_data WHERE _template = ?;");
query.addBindValue(QVariant(templateId));
query.exec();
le = query.lastError();
if (le.type() != QSqlError::NoError)
qDebug() << "1. deleteTemplate: " << le.text();
query.prepare("DELETE FROM crossword.grids WHERE _template = ?;");
query.addBindValue(QVariant(templateId));
query.exec();
le = query.lastError();
if (le.type() != QSqlError::NoError)
qDebug() << "2. deleteTemplate: " << le.text();
query.prepare("DELETE FROM crossword.templates WHERE _id = ?;");
query.addBindValue(QVariant(templateId));
query.exec();
le = query.lastError();
if (le.type() != QSqlError::NoError)
qDebug() << "3. deleteTemplate: " << le.text();
for (int i = 0; i < numCol; i++)
removeColumn(0);
setRowCount(0);
sb->showMessage(tr("Template deleted"), 2000);
// need for templateListWidget
emit deletedFromDB(templateId);
numCol = numRow = 0;
templateId = 0;
countWords = 0;
wi.clear();
}
示例3: DBErrorMessage
QString MythDB::DBErrorMessage(const QSqlError& err)
{
if (!err.type())
return "No error type from QSqlError? Strange...";
return QString("Driver error was [%1/%2]:\n"
"%3\n"
"Database error was:\n"
"%4\n")
.arg(err.type())
.arg(err.number())
.arg(err.driverText())
.arg(err.databaseText());
}
示例4: insertColor
void plumaje::insertColor ()
{
if (!nombrePluma->text().isEmpty() && !descripcionPluma->text().isEmpty())
{
if (modificando)
{
QString consulta = "UPDATE plumaje SET nombre = \"" + nombrePluma->text() + "\", \
descripcion = \"" + descripcionPluma->text() + "\" \
WHERE plumajeID = " + tablaPlumaje->currentRecord()->value(0).toString();
qWarning (consulta);
QSqlQuery queryUpdate (consulta, QSqlDatabase::database("palomar" ));
QSqlError error = queryUpdate.lastError();
if (error.type() != QSqlError::None)
KMessageBox::error (this, i18n("Error actualizando el color de pluma. El error devuelto por la base de datos es:\n") +
error.databaseText(),
i18n ("Error actualizando color de pluma"));
else
{
tablaPlumaje->refresh();
InsertButton->setText(i18n("Insertar"));
modificando = FALSE;
descripcionPluma->clear();
nombrePluma->clear();
}
}
else
{
QString consulta = "INSERT INTO plumaje (nombre, descripcion) VALUES ('";
consulta += nombrePluma->text() + "', '" + descripcionPluma->text() + "');";
qWarning (consulta);
QSqlQuery queryInsert (consulta, QSqlDatabase::database("palomar" ));
QSqlError error = queryInsert.lastError();
if (error.type() != QSqlError::None)
KMessageBox::error (this, i18n("Error insertantdo el color de pluma.El error devuelto por la base de datos es:\n") +
error.databaseText(),
i18n ("Error añadiendo el color de pluma"));
else
{
tablaPlumaje->refresh();
descripcionPluma->clear();
nombrePluma->clear();
}
}
}
else
KMessageBox::error (this, i18n("Debe rellenar el nombre y la descripción."),
i18n ("Error añadiendo tipo de suelta"));
}
示例5: on_okButton_clicked
void ConnDlg::on_okButton_clicked()
{
if (ui.comboDriver->currentText().isEmpty())
{
ui.status_label->setText(tr("请选择一个数据库驱动!"));
ui.comboDriver->setFocus();
}
else if(ui.comboDriver->currentText() =="QSQLITE")
{
addSqliteConnection();
//创建数据库表,如已存在则无须执行
creatDB();
accept();
}
else
{
QSqlError err = addConnection(driverName(), databaseName(), hostName(),userName(), password(), port());
if (err.type() != QSqlError::NoError)
ui.status_label->setText(err.text());
else
ui.status_label->setText(tr("连接数据库成功!"));
//创建数据库表,如已存在则无须执行
accept();
}
}
示例6: exec
/*!
* \brief SqlQuery::exec Execute a existing query with capability to throw SqlException
* if necessary.
* \return true if successfully executed, false otherwise.
*/
bool SqlQuery::exec() throw(SqlException)
{
bool b = m_sqlQuery.exec();
QSqlError sqlError = m_sqlQuery.lastError();
switch(sqlError.type ())
{
case QSqlError::NoError:
return b;
case QSqlError::ConnectionError:
case QSqlError::StatementError:
if(sqlError.databaseText() == "MySQL server has gone away"){
throw SqlConnectionException(sqlError);
}else{
throw SqlStatementException(sqlError);
}
case QSqlError::TransactionError:
throw SqlTransactionException(sqlError);
case QSqlError::UnknownError:
throw SqlUnknownException(sqlError);
default:
throw SqlException(sqlError);
}
}
示例7: logqmsg
bool DatabaseLogger::logqmsg(MSqlQuery &query, LoggingItem *item)
{
char timestamp[TIMESTAMP_MAX];
char *threadName = getThreadName(item);
strftime( timestamp, TIMESTAMP_MAX-8, "%Y-%m-%d %H:%M:%S",
(const struct tm *)&item->tm );
query.bindValue(":THREAD", threadName);
query.bindValue(":MSGTIME", timestamp);
query.bindValue(":LEVEL", item->level);
query.bindValue(":MESSAGE", item->message);
if (!query.exec())
{
// Suppress Driver not loaded errors that occur at startup.
// and suppress additional errors for one second after the
// previous error (to avoid spamming the log).
QSqlError err = query.lastError();
if ((err.type() != 1 || err.number() != -1) &&
(!m_errorLoggingTime.isValid() ||
(m_errorLoggingTime.elapsed() > 1000)))
{
MythDB::DBError("DBLogging", query);
m_errorLoggingTime.start();
}
return false;
}
deleteItem(item);
return true;
}
示例8: loadKTSs
bool SvDeviceEditor::loadKTSs()
{
QSqlQuery* q = new QSqlQuery(SQLITE->db);
QSqlError serr = SQLITE->execSQL(QString(SQL_SELECT_KTSS_LIST), q);
if(QSqlError::NoError != serr.type()) {
_last_error = serr.text();
delete q;
return false;
}
while(q->next())
ui->cbDeviceType->addItem(q->value("kts_name").toString(), q->value("kts_id").toUInt());
q->finish();
delete q;
if(ui->cbDeviceType->count()) ui->cbDeviceType->setCurrentIndex(0);
ui->bnSave->setEnabled(!ui->cbDeviceType->currentData().isNull());
connect(ui->cbDeviceType, SIGNAL(currentIndexChanged(int)), this, SLOT(updateKTSInfo(int)));
return true;
}
示例9: updateCurrencies
void MainWindow::updateCurrencies() {
QList<Currency> list;
market->getCurrenciesList(list);
QSqlError err = db_helper->updateCurrenciesTable(list);
if (err.type() != QSqlError::NoError) {
showError(err);
return;
}
}
示例10: checkDatabaseError
void checkDatabaseError(const QSqlDatabase &db) {
QSqlError lastError = db.lastError();
if (lastError.type() != QSqlError::NoError) {
#if QT_VERSION >= 0x050300
throw Exception { lastError.nativeErrorCode().toInt(), lastError.text().toStdString() };
#else
throw Exception { lastError.number(), lastError.text().toStdString() };
#endif
}
}
示例11: QObject
TestMarketData::TestMarketData(QObject *parent) :
QObject(parent), db_helper(NULL), market(NULL)
{
db_helper = new DBHelper(":memory:");
QSqlError err = db_helper->initDb();
if (err.type() != QSqlError::NoError) {
qDebug() << "Error: " << err;
}
market = new CryptocoinChartsMDP();
}
示例12: eliminarColor
void plumaje::eliminarColor()
{
QString consulta = "DELETE FROM plumaje WHERE plumajeID = " + tablaPlumaje->currentRecord()->value(0).toString();
QSqlQuery queryDelete (consulta, QSqlDatabase::database("palomar" ));
QSqlError error = queryDelete.lastError();
if (error.type() != QSqlError::None)
KMessageBox::error (this, i18n("Error eliminando el color de pluma. El error devuelto por la base de datos es:\n") +
error.databaseText(),
i18n ("Error eliminando el color de pluma"));
tablaPlumaje->refresh();
}
示例13: isLockError
bool SqlUtils::isLockError(const QSqlError& error)
{
if (error.type() == QSqlError::StatementError &&
( error.text().contains(QLatin1String("(55P03)")) || //the actual error code, not translated. needs patched QPSQL driver
error.text().contains(QLatin1String("could not obtain lock")) )
)
{
return true;
}
return false;
}
示例14: eliminarTipo
void ojo::eliminarTipo()
{
QString consulta = "DELETE FROM ojo WHERE ojoID = " + tablaOjos->currentRecord()->value(0).toString();
QSqlQuery queryDelete (consulta, QSqlDatabase::database("palomar" ));
QSqlError error = queryDelete.lastError();
if (error.type() != QSqlError::None)
KMessageBox::error (this, i18n("Error eliminando el tipo de ojo. El error devuelto por la base de datos es:\n") +
error.databaseText(),
i18n ("Error eliminando el tipo de ojo"));
tablaOjos->refresh();
}
示例15: showError
SQLconnector::SQLconnector()
{
if (!QSqlDatabase::drivers().contains("QSQLITE"));
// initialize the database
QSqlError err = this->initDb();
if (err.type() != QSqlError::NoError) {
showError(err);
return;
}
}