当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlError::nativeErrorCode方法代码示例

本文整理汇总了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;
}
开发者ID:Flash2307,项目名称:PlayGround,代码行数:32,代码来源:DatabaseFacade.cpp

示例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;
}
开发者ID:wakeofluna,项目名称:qlivestream,代码行数:27,代码来源:application.cpp

示例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
    }
}
开发者ID:1SpatialGroupLtd,项目名称:mapbox-gl-native,代码行数:10,代码来源:sqlite3.cpp

示例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();
    }
}
开发者ID:Flash2307,项目名称:PlayGround,代码行数:40,代码来源:DatabaseFacade.cpp

示例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();
    }

}
开发者ID:Flash2307,项目名称:PlayGround,代码行数:18,代码来源:DatabaseFacade.cpp


注:本文中的QSqlError::nativeErrorCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。