static void get_refreshratelist(int device, int bitdepth, int width, int height) { DirectDrawModeList *mode; ValueList *value; char buff[256]; DestroyList(&refresh_rates); // We always need 'Default' as when support for different // Refreshrates exists, then it is not reported back value = lib_malloc(sizeof(ValueList)); value->value = 0; value->text = lib_stralloc("Default"); InsertInto(&refresh_rates, value); mode = modes; while (mode != NULL) { if ((mode->devicenumber == device) && (mode->bitdepth == bitdepth) && (mode->width == width) && (mode->height == height)) { if (GetIndexFromList(refresh_rates, mode->refreshrate) == -1) { value = lib_malloc(sizeof(ValueList)); value->value = mode->refreshrate; itoa(mode->refreshrate, buff, 10); value->text = lib_stralloc(buff); InsertInto(&refresh_rates, value); } } mode = mode->next; } }
IFilterElement* EffectsManager::RestoreFilter (const QList<EffectInfo>::const_iterator effectPos, const QByteArray& instanceId) { auto modelItem = new QStandardItem { effectPos->Name_ }; modelItem->setEditable (false); modelItem->setIcon (effectPos->Icon_); Model_->appendRow (modelItem); const auto elem = effectPos->EffectFactory_ (instanceId, Path_); elem->InsertInto (Path_); Filters_ << elem; return elem; }
void API::Switcher(SqlCommand* command){ SqlCommandType command_type = command->command_type(); Info info; // typedef std::chrono::high_resolution_clock Clock; // typedef std::chrono::milliseconds milliseconds; // Clock::time_point t0 = Clock::now(); switch(command_type){ case kSqlInvalid: { info = Info("Invalid Command, Please check your syntax."); break; } case kSqlCreateTable: { info = CreateTable(dynamic_cast<SqlCommandCreateTable *>(command)); break; } case kSqlCreateIndex: { info = CreateIndex(dynamic_cast<SqlCommandCreateIndex *>(command)); break; } case kSqlDeleteFrom: { info = DeleteFrom(dynamic_cast<SqlCommandDeleteFrom *>(command)); break; } case kSqlDropTable: { info = DropTable(dynamic_cast<SqlCommandDropTable *>(command)); break; } case kSqlDropIndex: { info = DropIndex(dynamic_cast<SqlCommandDropIndex *>(command)); break; } case kSqlInsertInto: { info = InsertInto(dynamic_cast<SqlCommandInsertInto *>(command)); break; } case kSqlSelectFrom: { info = SelectFrom(dynamic_cast<SqlCommandSelectFrom *>(command));break; } } info.PrintInfo(); // Clock::time_point t1 = Clock::now(); // milliseconds ms = std::chrono::duration_cast<milliseconds>(t1 - t0); // std::cout<<"time used:"<<ms.count()<<" ms."<<std::endl; }
static void get_resolutionlist(int device, int bitdepth) { DirectDrawModeList *mode; ValueList *value; char buff[256]; DestroyList(&resolutionlist); mode = modes; while (mode != NULL) { if ((mode->devicenumber == device) && (mode->bitdepth == bitdepth)) { if (GetIndexFromList(resolutionlist, ((mode->width << 16) + mode->height)) == -1) { value = lib_malloc(sizeof(ValueList)); value->value = (mode->width << 16) + mode->height; sprintf(buff, "%dx%d", mode->width, mode->height); value->text=lib_stralloc(buff); InsertInto(&resolutionlist, value); } } mode = mode->next; } }
static void get_bitdepthlist(int device) { DirectDrawModeList *mode; ValueList *value; char buff[256]; DestroyList(&bitdepthlist); mode = modes; while (mode != NULL) { if ((mode->devicenumber == device)) { if (GetIndexFromList(bitdepthlist, mode->bitdepth) == -1) { value = lib_malloc(sizeof(ValueList)); value->value = mode->bitdepth; itoa(mode->bitdepth, buff, 10); value->text = lib_stralloc(buff); InsertInto(&bitdepthlist, value); } } mode = mode->next; } }
//----------------------------------- /// \brief Create the database (when tables are not found) ///\param [in] pRequester : database requester object ///\throw CVersionException if create database failed //----------------------------------- void CVersion1::CreateDatabase(const boost::shared_ptr<IDatabaseRequester> & pRequester) const { try { //create transaction if supported if(pRequester->transactionSupport()) pRequester->transactionBegin(); //delete tables if(!pRequester->dropTableIfExists(CConfigurationTable::getTableName())) throw CVersionException("Failed to delete Configuration table"); if(!pRequester->dropTableIfExists(CDeviceTable::getTableName())) throw CVersionException("Failed to delete Device table"); if(!pRequester->dropTableIfExists(CPluginTable::getTableName())) throw CVersionException("Failed to delete Plugin table"); if(!pRequester->dropTableIfExists(CKeywordTable::getTableName())) throw CVersionException("Failed to delete Keyword table"); if(!pRequester->dropTableIfExists(CPageTable::getTableName())) throw CVersionException("Failed to delete Page table"); if(!pRequester->dropTableIfExists(CWidgetTable::getTableName())) throw CVersionException("Failed to delete Widget table"); if(!pRequester->dropTableIfExists(CPluginEventLoggerTable::getTableName())) throw CVersionException("Failed to delete PluginEventLogger table"); if(!pRequester->dropTableIfExists(CEventLoggerTable::getTableName())) throw CVersionException("Failed to delete EventLogger table"); if(!pRequester->dropTableIfExists(CAcquisitionTable::getTableName())) throw CVersionException("Failed to delete Acquisition table"); if(!pRequester->dropTableIfExists(CAcquisitionSummaryTable::getTableName())) throw CVersionException("Failed to delete AcquisitionSummary table"); if (!pRequester->dropTableIfExists(CRuleTable::getTableName())) throw CVersionException("Failed to delete rule table"); if (!pRequester->dropTableIfExists(CRecipientTable::getTableName())) throw CVersionException("Failed to delete Recipient table"); if (!pRequester->dropTableIfExists(CRecipientFieldTable::getTableName())) throw CVersionException("Failed to delete RecipientFields table"); boost::shared_ptr<ITableCreationScriptProvider> scriptProvider = pRequester->getTableCreationScriptProvider(); //create tables if(!pRequester->createTableIfNotExists(CConfigurationTable::getTableName(), scriptProvider->getTableConfiguration())) throw CVersionException("Failed to create Configuration table"); if(!pRequester->createTableIfNotExists(CDeviceTable::getTableName(), scriptProvider->getTableDevice())) throw CVersionException("Failed to create Device table"); if(!pRequester->createTableIfNotExists(CPluginTable::getTableName(), scriptProvider->getTablePlugin())) throw CVersionException("Failed to create Plugin table"); if(!pRequester->createTableIfNotExists(CKeywordTable::getTableName(), scriptProvider->getTableKeyword())) throw CVersionException("Failed to create Keyword table"); if(!pRequester->createTableIfNotExists(CPageTable::getTableName(), scriptProvider->getTablePage())) throw CVersionException("Failed to create Page table"); if(!pRequester->createTableIfNotExists(CWidgetTable::getTableName(), scriptProvider->getTableWidget())) throw CVersionException("Failed to create Widget table"); if(!pRequester->createTableIfNotExists(CPluginEventLoggerTable::getTableName(), scriptProvider->getTablePluginEventLogger())) throw CVersionException("Failed to create PluginEventLogger table"); if(!pRequester->createTableIfNotExists(CEventLoggerTable::getTableName(), scriptProvider->getTableEventLogger())) throw CVersionException("Failed to create EventLogger table"); if(!pRequester->createTableIfNotExists(CAcquisitionTable::getTableName(), scriptProvider->getTableAcquisition())) throw CVersionException("Failed to create Acquisition table"); if (!pRequester->createTableIfNotExists(CAcquisitionSummaryTable::getTableName(), scriptProvider->getTableAcquisitionSummary())) throw CVersionException("Failed to create AcquisitionSummary table"); if (!pRequester->createTableIfNotExists(CRuleTable::getTableName(), scriptProvider->getTableRule())) throw CVersionException("Failed to create Rule table"); if (!pRequester->createTableIfNotExists(CRecipientTable::getTableName(), scriptProvider->getTableRecipient())) throw CVersionException("Failed to create Recipient table"); if (!pRequester->createTableIfNotExists(CRecipientFieldTable::getTableName(), scriptProvider->getTableRecipientField())) throw CVersionException("Failed to create RecipientFields table"); std::vector<std::string> indexScripts; scriptProvider->getTableAcquisitionIndexes(indexScripts); //indexes for (std::vector<std::string>::const_iterator i = indexScripts.begin(); i != indexScripts.end(); ++i) { pRequester->createIndex(CAcquisitionTable::getTableName(), *i); } //set the database version auto qInsert = pRequester->newQuery(); qInsert.InsertInto(CConfigurationTable::getTableName(), CConfigurationTable::getSectionColumnName(), CConfigurationTable::getNameColumnName(), CConfigurationTable::getValueColumnName(), CConfigurationTable::getDescriptionColumnName()). Values("Database", "Version", m_version.toString(3), "Database version"); pRequester->queryStatement(qInsert); //set the developer mode qInsert.Clear().InsertInto(CConfigurationTable::getTableName(), CConfigurationTable::getSectionColumnName(), CConfigurationTable::getNameColumnName(), CConfigurationTable::getValueColumnName(), CConfigurationTable::getDefaultValueColumnName(), CConfigurationTable::getDescriptionColumnName()). Values( "system", "developerMode", "false", "false", "Developer mode"); pRequester->queryStatement(qInsert); //system plugin qInsert.Clear().InsertInto(CPluginTable::getTableName(), CPluginTable::getDisplayNameColumnName(), CPluginTable::getTypeColumnName(), CPluginTable::getAutoStartColumnName(), CPluginTable::getCategoryColumnName()). Values("System", "System", true, database::entities::EPluginCategory::kSystem); pRequester->queryStatement(qInsert); //commit transaction if (pRequester->transactionSupport()) pRequester->transactionCommit(); //compact database pRequester->vacuum(); } catch(CVersionException & ex) { YADOMS_LOG(fatal) << "Failed to upgrade database : " << ex.what(); YADOMS_LOG(fatal) << "Rollback transaction"; if (pRequester->transactionSupport()) pRequester->transactionRollback(); throw CVersionException("Failed to create database"); } }
void CKeyword::addKeyword(const entities::CKeyword& newKeyword) { auto qSelect = m_databaseRequester->newQuery(); qSelect.SelectCount(). From(CKeywordTable::getTableName()). Where(CKeywordTable::getDeviceIdColumnName(), CQUERY_OP_EQUAL, newKeyword.DeviceId()). And(CKeywordTable::getNameColumnName(), CQUERY_OP_EQUAL, newKeyword.Name()); if (m_databaseRequester->queryCount(qSelect) == 0) { //create the database entry with needed fields auto qInsert = m_databaseRequester->newQuery(); qInsert.InsertInto(CKeywordTable::getTableName(), CKeywordTable::getDeviceIdColumnName(), CKeywordTable::getCapacityNameColumnName(), CKeywordTable::getAccessModeColumnName(), CKeywordTable::getNameColumnName(), CKeywordTable::getTypeColumnName(), CKeywordTable::getMeasureColumnName()). Values(newKeyword.DeviceId(), newKeyword.CapacityName(), newKeyword.AccessMode(), newKeyword.Name(), newKeyword.Type(), newKeyword.Measure()); if (m_databaseRequester->queryStatement(qInsert) <= 0) throw shared::exception::CEmptyResult("Fail to insert keyword into table"); //update fields auto friendlyName = newKeyword.Name(); if (newKeyword.FriendlyName.isDefined()) friendlyName = newKeyword.FriendlyName(); auto update = m_databaseRequester->newQuery(); update.Update(CKeywordTable::getTableName()).Set(CKeywordTable::getFriendlyNameColumnName(), friendlyName). Where(CKeywordTable::getDeviceIdColumnName(), CQUERY_OP_EQUAL, newKeyword.DeviceId()). And(CKeywordTable::getNameColumnName(), CQUERY_OP_EQUAL, newKeyword.Name()); if (m_databaseRequester->queryStatement(update) <= 0) throw shared::exception::CEmptyResult("Fail to update FriendlyName field"); if (newKeyword.Details.isDefined()) { auto updateDetails = m_databaseRequester->newQuery(); updateDetails.Update(CKeywordTable::getTableName()).Set(CKeywordTable::getDetailsColumnName(), newKeyword.Details()). Where(CKeywordTable::getDeviceIdColumnName(), CQUERY_OP_EQUAL, newKeyword.DeviceId()). And(CKeywordTable::getNameColumnName(), CQUERY_OP_EQUAL, newKeyword.Name()); if (m_databaseRequester->queryStatement(updateDetails) <= 0) throw shared::exception::CEmptyResult("Fail to update Details field"); } if (newKeyword.Units.isDefined()) { auto updateUnits = m_databaseRequester->newQuery(); updateUnits.Update(CKeywordTable::getTableName()).Set(CKeywordTable::getUnitsColumnName(), newKeyword.Units()). Where(CKeywordTable::getDeviceIdColumnName(), CQUERY_OP_EQUAL, newKeyword.DeviceId()). And(CKeywordTable::getNameColumnName(), CQUERY_OP_EQUAL, newKeyword.Name()); if (m_databaseRequester->queryStatement(updateUnits) <= 0) throw shared::exception::CEmptyResult("Fail to update Units field"); } if (newKeyword.TypeInfo.isDefined()) { auto updateValues = m_databaseRequester->newQuery(); updateValues.Update(CKeywordTable::getTableName()).Set(CKeywordTable::getTypeInfoColumnName(), newKeyword.TypeInfo()). Where(CKeywordTable::getDeviceIdColumnName(), CQUERY_OP_EQUAL, newKeyword.DeviceId()). And(CKeywordTable::getNameColumnName(), CQUERY_OP_EQUAL, newKeyword.Name()); if (m_databaseRequester->queryStatement(updateValues) <= 0) throw shared::exception::CEmptyResult("Fail to update Values field"); } } else { //already exist, do nothing } }