本文整理汇总了C++中QSqlError::nativeErrorCode方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlError::nativeErrorCode方法的具体用法?C++ QSqlError::nativeErrorCode怎么用?C++ QSqlError::nativeErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlError
的用法示例。
在下文中一共展示了QSqlError::nativeErrorCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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
}
}
示例4: addUserStat
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();
}
}
示例5: openConnexion
void DatabaseFacade::openConnexion()
{
db.setHostName( DATABASE_IP );
db.setDatabaseName( DATABASE_NAME );
db.setUserName( DATABASE_USER );
db.setPassword( DATABASE_PASS );
connected = db.open();
if(!connected)
{
qDebug() << "Connexion to database failed";
QSqlError err = db.lastError();
if(err.isValid())
qDebug() << err.databaseText() << "\n" << err.driverText() << "\n" << err.nativeErrorCode();
}
}