ll qry(nd *n,int l,int r) { if(!n or n->mn > r or n->mx < l) return 0; if(l <= n->mn and n->mx <= r) return n->res; ll ret = l<=n->i.first and n->i.first<=r ? n->val : 0; ret = gcd(gcd(qry(n->ch[0],l,r),qry(n->ch[1],l,r)),ret); return ret; }
ll qry(int ql,int qr,int l,int r,int ind){ if(ql==l&&qr==r) return st[ind]; if(lz[ind]) pshd(ind); int mid=l+r>>1; if(qr<=mid) return qry(ql,qr,l,mid,ind<<1); else if(ql>mid) return qry(ql,qr,mid+1,r,ind<<1|1); else return qry(ql,mid,l,mid,ind<<1)|qry(mid+1,qr,mid+1,r,ind<<1|1); }
bool TreeLeaf::updateName_DB() { DBAcccessSafe db_safe; // QSqlDatabase* ptr_db = db_safe.getDB(); if (NULL == ptr_db) return false; // QSqlQuery qry(*ptr_db); // QString str_update_string = QString("UPDATE node_tbl SET node_name = :NAME WHERE id_node = :ID;"); // if(! qry.prepare( str_update_string ) ) { Logger::getInstance().logIt( en_LOG_ERRORS, qry.lastError().text(), &str_update_string ); return false; }; // qry.bindValue(":NAME", this->text(0)); qry.bindValue(":ID", m_iID); // if( !qry.exec() ) { Logger::getInstance().logIt( en_LOG_ERRORS, qry.lastError().text(), &str_update_string ); return false; }; // m_strDatabaseNodeName = this->text(0); return true; }
AddCustomerAddLocationAddContactAddEmail::AddCustomerAddLocationAddContactAddEmail(QWidget *parent, stringMatrix * newEmails, const std::string & contact) : QDialog(parent), ui(new Ui::AddCustomerAddLocationAddContactAddEmail) { ui->setupUi(this); ui->addButton->setDefault(true); this->emails = newEmails; this->contact = contact.c_str(); std::stringstream qryss; qryss << "select id, kind from email_phone_kinds"; Query qry(qryss.str()); if (qry.failed) { emit CloseUponConnectionFailure(); this->close(); } else { for (int i = 0; i < (int)qry.r.size(); ++i){ std::vector<std::string> newKind; newKind.push_back(qry.r[i][0].as<std::string>()); newKind.push_back(qry.r[i][1].as<std::string>()); kinds.push_back(newKind); } QStringList kindOptions; for (std::vector<std::vector<std::string>>::iterator tuple = kinds.begin(); tuple != kinds.end(); tuple++){ kindOptions << (*tuple)[1].c_str(); } ui->kindComboBox->addItems(kindOptions); } }
/*! Selects a new database name \a dbname for the connection. If the * connection is already using the named database, nothing happens. * For those database backends which do not support the \c USE statement, * the connection will be closed and reopened as needed. This name is \i not * the same as the connection's name. * \warning Every effort is made to avoid leaving the connection in a closed * (or otherwise unusable state) but all bets are off when a non-existant * database name is requested. */ void QxtSqlThreadManager::selectDatabase(const QString &dbname) { QSqlDatabase conn = database(); if(conn.isOpen()){ // We're already open -- check to see if we can avoid a close if(conn.databaseName() == dbname) return; // No need to do anything regardless if(conn.driverName().startsWith("QMYSQL", Qt::CaseInsensitive)){ // Database supports "USE" -- so do it that way QSqlQuery qry(conn); if(!qry.exec("USE "+conn.driver()->escapeIdentifier(dbname, QSqlDriver::TableName))) qWarning() << Q_FUNC_INFO << "Failed to change database to" << dbname << ", error:" << qry.lastError().text(); // Set name so we'll see it next time (then we're done here) conn.setDatabaseName(dbname); return; } // Couldn't swap names on the current connection -- so close it conn.close(); } // Reaching here means we've got to set the database name & open it conn.setDatabaseName(dbname); if(!conn.open()) qWarning() << Q_FUNC_INFO << "Failed to open connection to database" << dbname << ", error: " << conn.lastError().text(); }
AddCustomerAddContactAddEmail::AddCustomerAddContactAddEmail(QWidget * parent, stringMatrix * emails, std::string contact) : QDialog(parent), ui(new Ui::AddCustomerAddContactAddEmail) { ui->setupUi(this); ui->addButton->setDefault(true); this->emails = emails; this->contact = contact; std::stringstream qryss; qryss << "select id, kind " << "from email_phone_kinds"; Query qry(qryss.str()); if (qry.failed) { emit CloseUponConnectionFailure(); this->close(); } else { QStringList comboBoxTexts; for (int i = 0; i < (int)qry.r.size(); ++i) { stringVector newKind; newKind.push_back(qry.r[i][0].as<std::string>()); newKind.push_back(qry.r[i][1].as<std::string>()); kinds.push_back(newKind); comboBoxTexts << qry.r[i][1].as<std::string>().c_str(); } ui->kindComboBox->addItems(comboBoxTexts); } }
bool CharacterNameLocator::locateObjects(DB::Session *session, const std::string &schema, int &objectsLocated) { int rowsFetched; DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("Loading character names.\n")); CharacterNameQuery qry(schema); if (! (session->exec(&qry))) { objectsLocated = 0; return false; } while ((rowsFetched = qry.fetch()) > 0) { size_t numRows = qry.getNumRowsFetched(); size_t count = 0; const std::vector<CharacterNameRow> &data = qry.getData(); for (std::vector<CharacterNameRow>::const_iterator i=data.begin(); i!=data.end(); ++i) { if (++count > numRows) break; m_characterIds.push_back(i->character_id.getValue()); m_stationIds.push_back(i->character_station_id.getValue()); m_characterNames.push_back(i->character_name.getValueASCII()); m_characterFullNames.push_back(i->character_full_name.getValueASCII()); m_characterCreateTime.push_back(i->character_create_time.getValue() + (7 * 60 * 60)); m_characterLastLoginTime.push_back(i->character_last_login_time.getValue() + (7 * 60 * 60)); DEBUG_REPORT_LOG(ConfigServerDatabase::getLogObjectLoading(),("\t%s:%s\n", i->character_id.getValue().getValueString().c_str(), i->character_name.getValueASCII().c_str())); } } objectsLocated = 0; return (rowsFetched >= 0); }
void SyncStartFiSvrNet( CTcpIo& net, u32 port, bool bSvr, bool bClt) { assert(bSvr || bClt); if (bSvr && bClt){ net.Start(port); }else if (bSvr){ net.StartServer(port); }else if (bClt){ net.StartClient(port); } FicsConnQuery qry(net, ServerIpBook::GetInstance(), _T("../FicsConfig.xml")); while (true) { set<NodeConnInfo> connInfo; bool isFicsNetOk; qry.getNodeConnState(connInfo, isFicsNetOk); if (!isFicsNetOk){ FiSleep(1000); continue; } break; } }
void TreeLeaf::updateExpandState_DB() { // DBAcccessSafe db_safe; // QSqlDatabase* ptr_db = db_safe.getDB(); if (NULL == ptr_db) return; // QSqlQuery qry(*ptr_db); // unsigned int ui_expanded_actually = 0; if (m_bIsExpandedActually) { ui_expanded_actually = 1; }; // QString str_update_string = QString ("UPDATE node_tbl SET expanded = %1 WHERE id_node = %2;").arg(ui_expanded_actually).arg(m_iID); // if (! qry.prepare( str_update_string ) ) { Logger::getInstance().logIt( en_LOG_ERRORS, qry.lastError().text(), &str_update_string ); return; }; // if( !qry.exec() ) { Logger::getInstance().logIt( en_LOG_ERRORS, qry.lastError().text(), &str_update_string ); }; }
bool AddCustomerWindow::verifyNameUniqueness(const std::string & rfc){ std::stringstream qryss; qryss << "select id from entity_kinds where kind='Customer'"; Query qry(qryss.str()); if (qry.failed) { ui->statusbar->showMessage(connectionError.c_str()); } else { std::string customerKindId = qry.r[0][qry.r.column_number("id")].as<std::string>(); qryss.str(""); qryss << "select id from entities " << "where entity_name=" << pg::quote(rfc) << " and kind=" << customerKindId; qry.setQuery(qryss.str()); qry.run(); if (qry.failed) { ui->statusbar->showMessage(connectionError.c_str()); } else { if (qry.r.size() > 0) ui->statusbar->showMessage(nameexistscustomer.c_str()); else { ui->statusbar->showMessage(nnameexistscustomer.c_str()); return true; } } } return false; }
int main() { int Case; read(Case); for(int i = 1; i <= N; ++i) tr[i] = new node; while(Case--) { read(n); assert(n <= N); init(); for(int i = 1; i < n; ++i) { int u, v; read(u), read(v); g.addedge(++u, ++v); } dfs(1, 0); build(); read(qn); while(qn--) { char s[3]; scanf("%s", s); int u; read(u), u++; if(s[0] == 'O') tr[u]->access(); else printf("%.6lf\n", qry(u)); } } return 0; }
void auth::check_db() { try { sqlite3pp::query qry(m_db, "SELECT value FROM settings WHERE key = 'schema_version'"); sqlite3pp::query::iterator i = qry.begin(); if( i == qry.end() ) { // unusual - table exists but doesn't contain this row. // could have been created wrongly cerr << "Error, settings table missing schema_version key!" << endl << "Maybe you created the database wrong, or it's corrupt." << endl << "Try deleting the auth database" << endl; throw; // not caught here. } string val = (*i).get<string>(0); cout << "Auth database schema detected as version " << val << endl; // check the schema version is what we expect // TODO auto-upgrade to newest schema version as needed. if( val != "2" ) { throw; // not caught here } // OK. } catch(sqlite3pp::database_error err) { // probably doesn't exist yet, try and create it // cout << "database_error: " << err.what() << endl; create_db_schema(); } }
bool MyClient::logincheckf(QString name, QString pass){ if(!this->logincheck){ //Connect to Database and check for the user if(this->db->isOpen()){ }else{ this->db->open(); } if(this->db->open()){ QSqlQuery qry(*this->db); QString query_1 = "select * from user_main where name='" + name + "' and pass='******' and code='-1';"; if(qry.exec(query_1)){ while(qry.next()){ this->cname = name; this->cpass = pass; return true; } } } return false; } return false; }
void MyClient::disconnected(){ if(this->db->isOpen()){ }else{ this->db->open(); } QSqlQuery qry(*db); QString query_1; query_1 = "DELETE FROM `online_user` WHERE `name`='"+this->cname+"'"; qry.exec(query_1); qDebug()<<"Client disconnected"; this->socket->close(); this->msgchekertimer->stop(); if(this->socket->isOpen()){ qDebug()<<"socket open"; }else{ qDebug()<<"socket close"; } if(!del_timestarted){ deletetimer->start(30000); del_timestarted = true; } }
DBFileDialog::DBFileDialog(QWidget* parent, Qt::WindowFlags fl) : QDialog(parent, fl) { setupUi(this); // signals and slots connections connect(_btnOk, SIGNAL(clicked()), this, SLOT(accept())); connect(_btnCancel, SIGNAL(clicked()), this, SLOT(reject())); connect(_list, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(sSelectedReport())); connect(_name, SIGNAL(textChanged(const QString&)), this, SLOT(sNameChanged(const QString&))); connect(_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(accept())); connect(_grade, SIGNAL(valueChanged(int)), this, SLOT(sGradeChanged(int))); _list->setColumnCount(2); QStringList cnames; cnames << tr("Name") << tr("Grade"); QTreeWidgetItem * item = new QTreeWidgetItem(_list, cnames); item->setData(1, Qt::TextAlignmentRole, Qt::AlignLeft); item->setData(2, Qt::TextAlignmentRole, Qt::AlignRight); XSqlQuery qry(getSqlFromTag("fmt12", QSqlDatabase::database().driverName())); while(qry.next()) { QTreeWidgetItem * item = new QTreeWidgetItem(_list, QStringList() << qry.value("report_name").toString() << qry.value("report_grade").toString()); item->setData(0, Qt::UserRole, qry.value("report_id")); } }
bool TreeLeaf::updateDescriptor_DB() { DBAcccessSafe db_safe; // QSqlDatabase* ptr_db = db_safe.getDB(); if (NULL == ptr_db) return false; // QSqlQuery qry(*ptr_db); // const QString str_html_string = m_docDescriptor.toHtml(); QString str_update_string = QString("UPDATE node_tbl SET node_descriptor = :DESCRIPTOR WHERE id_node = :ID;"); // if ( !qry.prepare( str_update_string ) ) { Logger::getInstance().logIt( en_LOG_ERRORS, qry.lastError().text(), &str_update_string ); return false; }; // qry.bindValue(":DESCRIPTOR", str_html_string ); qry.bindValue(":ID", m_iID ); // if( !qry.exec() ) { Logger::getInstance().logIt( en_LOG_ERRORS, qry.lastError().text(), &str_update_string ); return false; }; // return true; }
QJsonObject DiceAPI::getJobsList(const QString& query) { QUrlQuery qry(apiUrl); qry.addQueryItem("fields", "id, company, position"); qry.addQueryItem("q",query); QUrl url(apiUrl); url.setQuery(qry); QNetworkRequest request(url); request.setRawHeader(QByteArray("Authorization"), QByteArray((APIUserName + " " + token).toStdString().c_str())); QNetworkReply* reply = mgr.get(request); QEventLoop loop; connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); //check if reply is valid if(reply->error() == QNetworkReply::NoError) { //parsing JSON reply to get access_token QJsonDocument parsedReply = QJsonDocument::fromJson(QString(reply->readAll()).toUtf8()); QJsonObject jsonObj = parsedReply.object(); return jsonObj; } else { throw; } }
bool QgsOracleConn::tableInfo( bool geometryColumnsOnly, bool userTablesOnly, bool allowGeometrylessTables ) { QgsDebugMsg( "Entering." ); mLayersSupported.clear(); QString sql, delim; QString prefix( userTablesOnly ? "user" : "all" ), owner( userTablesOnly ? "user AS owner" : "c.owner" ); sql = QString( "SELECT %1,c.table_name,c.column_name,%2,o.object_type AS type" " FROM %3_%4 c" " JOIN %3_objects o ON c.table_name=o.object_name AND o.object_type IN ('TABLE','VIEW','SYNONYM')%5%6" ) .arg( owner ) .arg( geometryColumnsOnly ? "c.srid" : "NULL AS srid" ) .arg( prefix ) .arg( geometryColumnsOnly ? "sdo_geom_metadata" : "tab_columns" ) .arg( userTablesOnly ? "" : " AND c.owner=o.owner" ) .arg( geometryColumnsOnly ? "" : " WHERE c.data_type='SDO_GEOMETRY'" ); if ( allowGeometrylessTables ) { sql += QString( " UNION SELECT %1,object_name,NULL AS column_name,NULL AS srid,object_type AS type" " FROM %2_objects c WHERE c.object_type IN ('TABLE','VIEW','SYNONYM')" ) .arg( owner ).arg( prefix ); } // sql = "SELECT * FROM (" + sql + ")"; // sql += " ORDER BY owner,isview,table_name,column_name"; QSqlQuery qry( mDatabase ); if ( !exec( qry, sql ) ) { QgsMessageLog::logMessage( tr( "Querying available tables failed.\nSQL:%1\nerror:%2\n" ).arg( qry.lastQuery() ).arg( qry.lastError().text() ), tr( "Oracle" ) ); return false; } while ( qry.next() ) { QgsOracleLayerProperty layerProperty; layerProperty.ownerName = qry.value( 0 ).toString(); layerProperty.tableName = qry.value( 1 ).toString(); layerProperty.geometryColName = qry.value( 2 ).toString(); layerProperty.types = QList<QGis::WkbType>() << ( qry.value( 2 ).isNull() ? QGis::WKBNoGeometry : QGis::WKBUnknown ); layerProperty.srids = QList<int>() << qry.value( 3 ).toInt(); layerProperty.isView = qry.value( 4 ) != "TABLE"; layerProperty.pkCols.clear(); mLayersSupported << layerProperty; } if ( mLayersSupported.size() == 0 ) { QgsMessageLog::logMessage( tr( "Database connection was successful, but the accessible tables could not be determined." ), tr( "Oracle" ) ); } return true; }
void TreeLeaf::setActiveStatus_DB(bool b_active) { // DBAcccessSafe db_safe; // QSqlDatabase* ptr_db = db_safe.getDB(); if (NULL == ptr_db) return; // QSqlQuery qry(*ptr_db); // QString str_update_string; // unsigned int ui_is_active = 0; if (b_active) ui_is_active = 1; // //update node_tbl set active = 0 where id_node = 10; // str_update_string = QString ("update node_tbl set active = %1 WHERE id_node = %2;").arg(ui_is_active).arg(m_iID); // if( !qry.prepare( str_update_string ) ) { Logger::getInstance().logIt( en_LOG_ERRORS, qry.lastError().text(), &str_update_string ); return; }; // if( !qry.exec() ) Logger::getInstance().logIt( en_LOG_ERRORS, qry.lastError().text(), &str_update_string ); };
void Task2::run(){ try{ // qDebug() <<"Task Start"; this->db = new QSqlDatabase(*db); if(this->db->isOpen()){ }else{ this->db->open(); } QSqlQuery qry(*this->db); QString query_1; query_1 = "SELECT * FROM `msg_store` WHERE `to_name`='"+to+"' and `deliverd`='0' order by `date`, `time`"; qry.exec(query_1); while (qry.next()) { emit Result(1, "a"+this->splitstring+"a"+this->splitstring); break; } //qDebug()<<"Task Done"; //emit Result(1,"Task Result = "+QString::number(num)+splitstring+"Altair"+splitstring); // emit Result(1,msg+splitstring+"Altair"+splitstring); //emit Result(1,"Task Result = "+QString::number(num)+splitstring+"waat"+splitstring); delete this->db; }catch(...){ } }
int StatPayment::GetCycle() { static int iResult=0; char sTemp[9],sSql[256]; if (iResult!=0) return iResult; sprintf(sSql,"SELECT TO_CHAR(SYSDATE,'YYYYMMDD') NOWDATE FROM DUAL"); try{ TOCIQuery qry(&gpDBLink); qry.close(); qry.setSQL(sSql); qry.open(); qry.next(); strcpy( sTemp,qry.field("NOWDATE").asString() ); strcpy( sStatDate,sTemp); sTemp[6]='\0'; iResult=atoi(sTemp); return iResult; } catch(TOCIException &oe){ cout<<"[ERROR]:"<<oe.getErrMsg()<<endl; cout<<"[SQL]:"<<oe.getErrSrc()<<endl; throw oe; } }
float MountMg42::GetPriority() { if ( IsActive() || GetClient()->HasEntityFlag( ETQW_ENT_FLAG_MOUNTED ) ) return GetLastPriority(); BitFlag64 entFlags; GoalManager::Query qry( 0xe1a2b09c /* MOUNTMG42 */, GetClient() ); System::mInstance->mGoalManager->GetGoals( qry ); for ( uint32_t i = 0; i < qry.mList.size(); ++i ) { if ( BlackboardIsDelayed( qry.mList[ i ]->GetSerialNum() ) ) continue; GameEntity gunOwner = InterfaceFuncs::GetMountedPlayerOnMG42( GetClient(), qry.mList[ i ]->GetEntity() ); int gunHealth = InterfaceFuncs::GetGunHealth( GetClient(), qry.mList[ i ]->GetEntity() ); bool bBroken = InterfaceFuncs::IsMountableGunRepairable( GetClient(), qry.mList[ i ]->GetEntity() ); if ( bBroken ) continue; EntityInfo entInfo; if ( !IGame::GetEntityInfo( qry.mList[ i ]->GetEntity(), entInfo ) || !entInfo.mFlags.CheckFlag( ETQW_ENT_FLAG_ISMOUNTABLE ) ) continue; // Make sure nobody has it mounted. if ( ( !gunOwner.IsValid() || !GetClient()->IsAllied( gunOwner ) ) && ( gunHealth > 0 ) ) { mMapGoal = qry.mList[ i ]; break; } } return mMapGoal ? mMapGoal->GetPriorityForClient( GetClient() ) : 0.f; }
std::deque<chunk_coordinates> get_visible_queries() { boost::mutex::scoped_lock l (lock); std::deque<chunk_coordinates> result; for (auto& l : occlusion_queries) { for (auto& p : l) { occlusion_query& qry (p.second); if ( qry.state() == occlusion_query::cancelled || qry.state() == occlusion_query::air) { //trace("OQ %1% is canceled/air", world_rel_coordinates(p.first - world_chunk_center)); result.push_back(p.first); } else if ( qry.state() == occlusion_query::busy && qry.is_result_available()) { if (qry.result() > 8) { //trace("OQ %1% is visible", world_rel_coordinates(p.first - world_chunk_center)); qry.set_state(occlusion_query::visible); result.push_back(p.first); } else { qry.set_state(occlusion_query::occluded); } } } } return result; }
float DefuseDynamite::GetPriority() { if ( IsActive() ) return GetLastPriority(); mMapGoal.reset(); GoalManager::Query qry( 0x1899efc7 /* DEFUSE */, GetClient() ); System::mInstance->mGoalManager->GetGoals( qry ); for ( uint32_t i = 0; i < qry.mList.size(); ++i ) { if ( BlackboardIsDelayed( qry.mList[ i ]->GetSerialNum() ) ) continue; if ( qry.mList[ i ]->GetSlotsOpen( MapGoal::TRACK_INPROGRESS ) < 1 ) continue; if ( InterfaceFuncs::GetExplosiveState( GetClient(), qry.mList[ i ]->GetEntity() ) == XPLO_ARMED ) { mMapGoal = qry.mList[ i ]; break; } else { qry.mList[ i ]->SetDeleteMe( true ); } } return mMapGoal ? mMapGoal->GetPriorityForClient( GetClient() ) : 0.f; }
float BuildConstruction::GetPriority() { if ( IsActive() ) return GetLastPriority(); mMapGoal.reset(); GoalManager::Query qry( 0xc39bf2a3 /* BUILD */, GetClient() ); System::mInstance->mGoalManager->GetGoals( qry ); for ( uint32_t i = 0; i < qry.mList.size(); ++i ) { if ( BlackboardIsDelayed( qry.mList[ i ]->GetSerialNum() ) ) continue; if ( qry.mList[ i ]->GetSlotsOpen( MapGoal::TRACK_INPROGRESS ) < 1 ) continue; ConstructableState cState = InterfaceFuncs::GetConstructableState( GetClient(), qry.mList[ i ]->GetEntity() ); if ( cState == CONST_UNBUILT ) { mMapGoal = qry.mList[ i ]; break; } } return mMapGoal ? mMapGoal->GetPriorityForClient( GetClient() ) : 0.f; }
/* Function: void Admin::create() * Purpose : create new admin user and add his info into Database */ void Admin::create() { QSqlQuery qry(Database::getInstance().db()); qry.prepare("SELECT max(id) FROM user"); if(!qry.exec()) { qDebug() << qry.lastError(); } else { qry.next(); User::setId(qry.value(0).toInt() + 1); qDebug() << User::_id; } qry.prepare("INSERT INTO user(id, username, display_name, student_id) VALUES (:id, :un, :dn, NULL)"); qry.bindValue(":id", User::_id); qry.bindValue(":un", User::_userName); qry.bindValue(":dn", User::_displayName); if(!qry.exec()) { qDebug() << qry.lastError(); } else { qDebug() << "New admin is added"; } }
void VirtualSearch::sFillList() { if (! _parent) return; _listTab->clear(); _search->setText(_search->text().stripWhiteSpace().upper()); if (_search->text().length() == 0) return; QString search; if (_searchNumber->isChecked()) search = QString("number~'%1'").arg(_search->text()); if (_parent->_hasName && (_searchName->isChecked())) search = QString("name~'%1'").arg(_search->text()); if (_parent->_hasDescription && (_searchDescrip->isChecked())) search = QString("description~'%1'").arg(_search->text()); XSqlQuery qry(_parent->_query + (_parent->_extraClause.isEmpty() ? "" : " AND " + _parent->_extraClause) + search + QString(" ORDER BY ") + QString((_parent->_hasName) ? "name" : "number")); _listTab->populate(qry); }
void ReloadPreviews() { Freeze(); m_ScrolledPanel->DestroyChildren(); m_ItemSizer->Clear(); m_LastTerrainSelection = NULL; // clear any reference to deleted button AtlasMessage::qGetTerrainGroupPreviews qry((std::wstring)m_Name.wc_str(), imageWidth, imageHeight); qry.Post(); std::vector<AtlasMessage::sTerrainTexturePreview> previews = *qry.previews; bool allLoaded = true; for (size_t i = 0; i < previews.size(); ++i) { if (!previews[i].loaded) allLoaded = false; wxString name = previews[i].name.c_str(); // Construct the wrapped-text label wxStaticText* label = new wxStaticText(m_ScrolledPanel, wxID_ANY, FormatTextureName(name), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER); label->Wrap(imageWidth); unsigned char* buf = (unsigned char*)(malloc(previews[i].imageData.GetSize())); // imagedata.GetBuffer() gives a Shareable<unsigned char>*, which // is stored the same as a unsigned char*, so we can just copy it. memcpy(buf, previews[i].imageData.GetBuffer(), previews[i].imageData.GetSize()); wxImage img (imageWidth, imageHeight, buf); wxButton* button = new wxBitmapButton(m_ScrolledPanel, wxID_ANY, wxBitmap(img)); // Store the texture name in the clientdata slot button->SetClientObject(new wxStringClientData(name)); wxSizer* imageSizer = new wxBoxSizer(wxVERTICAL); imageSizer->Add(button, wxSizerFlags().Center()); imageSizer->Add(label, wxSizerFlags().Proportion(1).Center()); m_ItemSizer->Add(imageSizer, wxSizerFlags().Expand().Center()); } m_ScrolledPanel->Fit(); Layout(); Thaw(); // If not all textures were loaded yet, run a timer to reload the previews // every so often until they've all finished if (allLoaded && m_Timer.IsRunning()) { m_Timer.Stop(); } else if (!allLoaded && !m_Timer.IsRunning()) { m_Timer.Start(2000); } }
QString getShapeClause(QString shapeConstraint,QSqlDatabase db) { //ShapeDataSet:shapeID,ShapeID, if (shapeConstraint.count(":") != 1) { gbtLog(QObject::tr("Error in shape constraint")); return QString(); } int pos; pos = shapeConstraint.indexOf(":"); QString dataset = shapeConstraint.left(pos); QSqlQuery qry(db); QString sql; sql = "SELECT count(*) FROM datasetinfo WHERE dataset_id = '" + dataset + "' and dataset_type = 2"; if (qry.exec(sql)) { if (qry.first()) { if (qry.value(0).toInt() == 0) { gbtLog(dataset + QObject::tr(" is not a shape dataset")); return QString(); } } else return QString(); } else return QString(); sql = "SELECT geokey FROM " + dataset + "_raster WHERE "; QString shapes = shapeConstraint.mid(pos+1,shapeConstraint.length()-pos+1); QString shape; pos =0; while (pos <= shapes.length()-1) { if (shapes[pos] != ',') { shape = shape + shapes[pos]; pos++; } else { sql = sql + " shapeid = " + shape + " OR "; shape = ""; shapes = shapes.mid(pos+1,shapes.length()-pos+1); pos = 0; } } sql = sql + "shapeid = " + shape; return sql; }
void startmenu::CreateAccount(const QString Username, const QString Password) { QString queryString = "INSERT INTO user (username, password) VALUES (?,?)"; QSqlQuery qry(queryString); qry.addBindValue(Username); qry.addBindValue(Password); qry.exec(); }