本文整理汇总了C++中QSqlError::databaseText方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlError::databaseText方法的具体用法?C++ QSqlError::databaseText怎么用?C++ QSqlError::databaseText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlError
的用法示例。
在下文中一共展示了QSqlError::databaseText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle
SErrorPackage PostgresErrorHandler::handle(const QSqlError &error)
{
// new row for relation "doms_persons" violates check constraint doms_persons_email_check
// insert or update on table "doms_pacients" violates foreign key constraint "doms_pacients_iddocument_fkey"
QString text = error.databaseText().toLower();
if ( text.contains("duplicate key") )
{
SErrorPackage package(error.number(), QObject::tr("Seems like pacients already exists"));
return package;
}
else if ( text.contains("syntax error") )
{
SErrorPackage package(error.number(), QObject::tr("You're trying to do an invalid action"));
return package;
}
SErrorPackage package(error.number(), QObject::tr("PostgresErrorHandler %1").arg(error.databaseText()));
// TODO: Analizar los textos!
return package;
}
示例2: handleError
/*! \internal
Virtual function which is called when an error has occurred The
default implementation displays a warning message to the user with
information about the error.
*/
void QDataManager::handleError( QWidget* parent, const QSqlError& e )
{
#ifndef QT_NO_MESSAGEBOX
if (e.driverText().isEmpty() && e.databaseText().isEmpty()) {
QMessageBox::warning ( parent, "Warning", "An error occurred while accessing the database");
} else {
QMessageBox::warning ( parent, "Warning", e.driverText() + "\n" + e.databaseText(),
0, 0 );
}
#endif // QT_NO_MESSAGEBOX
}
示例3: writeQueryLog
void Tf::writeQueryLog(const QString &query, bool success, const QSqlError &error)
{
QString q = query;
if (!success) {
QString err = (!error.databaseText().isEmpty()) ? error.databaseText() : error.text().trimmed();
if (!err.isEmpty()) {
err = QLatin1Char('[') + err + QLatin1String("] ");
}
q = QLatin1String("(Query failed) ") + err + query;
}
Tf::traceQueryLog("%s", qPrintable(q));
}
示例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: upsertPkgItem
int Loadable::upsertPkgItem(int &pkgitemid, const int pkgheadid,
const int itemid, QString &errMsg)
{
if (pkgheadid < 0)
return 0;
QSqlQuery select;
QSqlQuery upsert;
if (pkgitemid >= 0)
upsert.prepare("UPDATE pkgitem SET pkgitem_descrip=:descrip "
"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 -20;
}
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 -21;
}
return pkgitemid;
}
示例6: ErrorString
QString toQSqlConnectionSub::ErrorString(const QSqlError &err, const QString &sql)
{
QString ret;
if (err.databaseText().isEmpty())
{
if (err.driverText().isEmpty())
ret = QString::fromLatin1("Unknown error");
else
ret = err.driverText();
}
else
ret = err.databaseText();
if (!sql.isEmpty())
ret += QString::fromLatin1("\n\n") + sql;
return ret;
}
示例7: login
void Database::login() throw (TimesheetProcessorException )
{
MySqlStorage::Parameters parameters;
try {
parameters = MySqlStorage::parseParameterEnvironmentVariable();
} catch( ParseError& e ) {
throw TimesheetProcessorException( e.what() );
}
m_storage.configure( parameters );
bool ok = m_storage.database().open();
if ( !ok ) {
QSqlError error = m_storage.database().lastError();
QString msg = QObject::tr( "Cannot connect to database %1 on host %2, database said "
"\"%3\", driver said \"%4\"" )
.arg( parameters.database ) .arg( parameters.host )
.arg( error.driverText() )
.arg( error.databaseText() );
throw TimesheetProcessorException( msg );
}
// check if the driver has transaction support
if( ! m_storage.database().driver()->hasFeature( QSqlDriver::Transactions ) ) {
QString msg = QObject::tr( "The database driver in use does not support transactions. Transactions are required." );
throw TimesheetProcessorException( msg );
}
}
示例8: notify
bool Application::notify(QObject * receiver, QEvent * e)
{
try
{
return QApplication::notify(receiver, e);
}
catch (Exception & e)
{
qCritical() << e.title() << ':' << e.description();
QMessageBox::critical(nullptr, e.title(), e.description());
}
catch (QSqlQuery & q)
{
QString s;
QTextStream str(&s);
QSqlError e = q.lastError();
str << "Query: " << q.lastQuery() << '\n';
str << "Driver text: " << e.driverText() << '\n';
str << "Database text: " << e.databaseText() << '\n';
str << "Native error code: " << e.nativeErrorCode();
qCritical() << "Database error:" << s;
QMessageBox::critical(nullptr, "Database error", s);
}
return false;
}
示例9: qDebug
std::vector< Profile > DatabaseFacade::getUsers()
{
std::vector<Profile> profiles;
if(!connected)
{
qDebug() << "Not connected to database";
return profiles;
}
QSqlQuery query;
query.exec("SELECT * FROM Gamers");
QSqlError err = query.lastError();
if(err.isValid())
qDebug() << err.databaseText() << "\n" << err.driverText() << "\n" << err.nativeErrorCode();
while (query.next())
{
int id = query.value(0).toInt();
QString name = query.value(1).toString();
QPixmap picture;
picture.loadFromData(query.value(2).toByteArray());
profiles.emplace_back(id, name, picture);
}
query.clear();
return profiles;
}
示例10: 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);
}
}
示例11: setLastError
void SQLiteDriver::setLastError(const QSqlError& e)
{
#if defined(SQLITEDRIVER_DEBUG)
if (e.isValid())
qDebug() << "SQLite error:" << e.driverText() << e.databaseText();
#endif
QSqlDriver::setLastError(e);
}
示例12: checkMySQLError
void checkMySQLError(QSqlQuery& q) {
QSqlError e = q.lastError();
if(!e.isValid())
return;//no error
qDebug()<<"got MySQL-Error"<<e.number()<<e.text()<<"/"<<e.databaseText()<<"/"<<e.driverText();
qDebug()<<"on query"<<q.lastQuery();
qDebug()<<"Terminating Application";
QCoreApplication::quit();
}
示例13:
QT_BEGIN_NAMESPACE
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QSqlError &s)
{
dbg.nospace() << "QSqlError(" << s.number() << ", " << s.driverText() <<
", " << s.databaseText() << ')';
return dbg.space();
}
示例14:
/*! \internal
Virtual function which is called when an error has occurred The
default implementation displays a warning message to the user with
information about the error.
*/
void Q3DataManager::handleError(QWidget* parent, const QSqlError& e)
{
#ifndef QT_NO_MESSAGEBOX
if (e.driverText().isEmpty() && e.databaseText().isEmpty()) {
QMessageBox::warning (parent, QLatin1String("Warning"), QLatin1String("An error occurred while accessing the database"));
} else {
QMessageBox::warning (parent, QLatin1String("Warning"), e.driverText() + QLatin1Char('\n') + e.databaseText(),
0, 0);
}
#endif // QT_NO_MESSAGEBOX
}
示例15: 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();
}