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


C++ DataModel::load方法代码示例

本文整理汇总了C++中DataModel::load方法的典型用法代码示例。如果您正苦于以下问题:C++ DataModel::load方法的具体用法?C++ DataModel::load怎么用?C++ DataModel::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataModel的用法示例。


在下文中一共展示了DataModel::load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: stmt

void
UpdateScreen::slotUpdate()
{
    QString from = _fromVersion->text();
    QString to = _toVersion->currentText();

    if (from == to) {
	qApp->beep();
	QString message = tr("Versions must be different");
	QMessageBox::critical(this, tr("Error"), message);
	return;
    }

    // Connect to company database
    Driver* driver = Driver::getDriver(_company.dbType());
    if (driver == NULL) {
	qApp->beep();
	QString message = tr("Get driver failed: %1").arg(driver->lastError());
	QMessageBox::critical(this, tr("Error"), message);
	return;
    }

    _connection = driver->allocConnection();
    if (!_connection->dbaConnect(_company.database())) {
	qApp->beep();
	QString message = tr("Open company failed: %1")
	    .arg(_connection->lastError());
	QMessageBox::critical(this, tr("Error"), message);
	return;
    }

    ServerConfig config;
    config.load();

    QString dataDir = parseDir(config.dataDir);
    QString version = to;

    QValueVector<DataModel> models;
    while (true) {
	QString filePath = dataDir + "/models/" + version + ".xml";
	DataModel model;
	if (!model.load(filePath)) {
	    qApp->beep();
	    QString message = tr("Failed loading model: %1").arg(filePath);
	    QMessageBox::critical(this, tr("Error"), message);
	    return;
	}

	if (model.fromVersion.isEmpty()) {
	    qApp->beep();
	    QString message = tr("Didn't find version: " + from);
	    QMessageBox::critical(this, tr("Error"), message);
	    return;
	}

	models.push_back(model);
	version = model.fromVersion;
	if (version == from) break;
    }

    if (models.size() == 0) {
	qApp->beep();
	QString message = tr("No models found for update use");
	QMessageBox::critical(this, tr("Error"), message);
	return;
    }

    QString dbType = _company.dbType();
    for (int i = models.size() - 1; i >= 0; --i) {
	DataModel& model = models[i];
	bool good = true;

	QValueVector<UpdateDefn> completed;
	for (unsigned int j = 0; j < model.updates.size(); ++j) {
	    UpdateDefn& update = model.updates[j];

	    // Only run update if its for All or the right type
	    if (!update.databases.contains("All"))
		if (!update.databases.contains(dbType))
		    continue;

	    // Run update commands catching errors
	    for (unsigned int k = 0; k < update.updateCmds.size(); ++k) {
		QString cmd = update.updateCmds[k];
		Stmt stmt(_connection, cmd);
		if (!stmt.execute()) {
		    qWarning(stmt.lastError());
		    good = false;
		    break;
		}
	    }

	    completed.push_back(update);
	}

	// If good then try to run cleanup commands
	if (good) {
	    for (unsigned int j = 0; j < completed.size(); ++j) {
		UpdateDefn& update = completed[j];

//.........这里部分代码省略.........
开发者ID:cwarden,项目名称:quasar,代码行数:101,代码来源:update_screen.cpp


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