unique_ptr<QueryResult> PostgreSQLConnection::query(const char* sql) { if(!_Query(sql)) return nullptr; //it will fetch the results in the constructor unique_ptr<QueryResult> queryResult(new QueryResultPostgre(this,sql)); return queryResult; }
unique_ptr<QueryResult> MySQLConnection::query(const char* sql) { MYSQL_RES* result = nullptr; MYSQL_FIELD* fields = nullptr; UInt64 rowCount = 0; size_t fieldCount = 0; if(!_Query(sql,result,fields,rowCount,fieldCount)) return nullptr; unique_ptr<QueryResult> queryResult(new QueryResultMysql(result, fields, rowCount, fieldCount)); return queryResult; }
CoverBling::CoverBling( QWidget* parent ) : QGLWidget( QGLFormat(QGL::DepthBuffer|QGL::SampleBuffers|QGL::AlphaChannel|QGL::DoubleBuffer), parent ) , m_xOffset( 0.0 ) , m_zOffset( M_PI / 2 ) { DEBUG_BLOCK setFixedHeight( 200 ); Amarok::Collection *coll = CollectionManager::instance()->primaryCollection(); QueryMaker *qm = coll->queryMaker(); qm->setQueryType( QueryMaker::Album ); qm->limitMaxResultSize( 10 ); connect( qm, SIGNAL( newResultReady( QString, Meta::AlbumList ) ), this, SLOT( queryResult( QString, Meta::AlbumList ) ) ); qm->run(); }
/** *@param A, queries: Given an integer array and an query list *@return: The result list */ vector<long long> intervalSum(vector<int> &nums, vector<Interval> &queries) { // write your code here // 构造线段树 SegmentTreeNodeWithCount * root = build(0, nums.size()-1); // 线段树-赋值 for (int i = 0; i < nums.size(); ++i) { modify(root, i, nums[i]); } // 统计查询结果 vector<long long> queryResult(queries.size(), 0); for (int i = 0; i < queries.size(); ++i) { queryResult[i] = query(root, queries[i].start, queries[i].end); } return queryResult; }
// --------------------------------------------------------- // CActiveDisconnectDlgPlugin::RunL() // --------------------------------------------------------- // void CActiveDisconnectDlgPlugin::RunL() { CLOG_ENTERFN( "CActiveDisconnectDlgPlugin::RunL " ); CLOG_WRITEF( _L( "iStatus.Int() : %d" ), iStatus.Int() ); CLOG_WRITEF( _L( "&iStatus : %d" ), &iStatus ); if( iStatus == KErrNone ) { TInt result( KErrNone ); CConnectionInfo* connectionInfo = CConnectionInfo::NewLC(); result = IsConnectionL( connectionInfo ); CLOG_WRITEF(_L( "result: %d" ), result ); if( result ) { TInt queryResult( KErrNotFound ); if( iPlugin->Prompt() ) { queryResult = iPlugin->AskDisconnectL(); } if( queryResult ) { // Modell will own connectionInfo iPlugin->InitializedL( connectionInfo ); CleanupStack::Pop( connectionInfo ); } else { CleanupStack::PopAndDestroy( connectionInfo ); } } else { CleanupStack::PopAndDestroy( connectionInfo ); iPlugin->SetStartedFlag( EFalse ); iPlugin->CompleteL( KErrNotFound ); } } CLOG_LEAVEFN( "CActiveDisconnectDlgPlugin::RunL " ); }
unique_ptr<QueryNamedResult> MySQLConnection::namedQuery(const char* sql) { MYSQL_RES* result = nullptr; MYSQL_FIELD* fields = nullptr; UInt64 rowCount = 0; size_t fieldCount = 0; if(!_Query(sql,result,fields,rowCount,fieldCount)) return nullptr; QueryFieldNames names(fieldCount); if (fields) { for (size_t i=0; i<fieldCount; i++) names[i] = fields[i].name; } unique_ptr<QueryResult> queryResult(new QueryResultMysql(result, fields, rowCount, fieldCount)); return unique_ptr<QueryNamedResult>(new QueryNamedResult(std::move(queryResult),names)); }
void SelectionQuery::process(const View& _view, const FrameBuffer& _framebuffer, const MarkerManager& _markerManager, const TileManager& _tileManager, const LabelManager& _labels, std::vector<SelectionColorRead>& _colorCache) const { float radius = m_radius * _view.pixelScale(); glm::vec2 windowCoordinates = _view.normalizedWindowCoordinates(m_position.x - radius, m_position.y + radius); glm::vec2 windowSize = _view.normalizedWindowCoordinates(m_position.x + radius, m_position.y - radius) - windowCoordinates; GLuint color = 0; auto it = std::find_if(_colorCache.begin(), _colorCache.end(), [=](const auto& _colorRead) { return (m_position == _colorRead.position) && (m_radius == _colorRead.radius); }); if (it == _colorCache.end()) { // Find the first non-zero color nearest to the position and within the selection radius. auto rect = _framebuffer.readRect(windowCoordinates.x, windowCoordinates.y, windowSize.x, windowSize.y); float minDistance = std::fmin(rect.width, rect.height); float hw = static_cast<float>(rect.width) / 2.f, hh = static_cast<float>(rect.height) / 2.f; for (int32_t row = 0; row < rect.height; row++) { for (int32_t col = 0; col < rect.width; col++) { uint32_t sample = rect.pixels[row * rect.width + col]; float distance = std::hypot(row - hw, col - hh); if (sample != 0 && distance < minDistance) { color = sample; minDistance = distance; } } } // Cache the resulting color for other queries. _colorCache.push_back({color, m_radius, m_position}); } else { color = it->color; } switch (type()) { case QueryType::feature: { auto& cb = m_queryCallback.get<FeaturePickCallback>(); if (color == 0) { cb(nullptr); return; } for (const auto& tile : _tileManager.getVisibleTiles()) { if (auto props = tile->getSelectionFeature(color)) { FeaturePickResult queryResult(props, {{m_position.x, m_position.y}}); cb(&queryResult); return; } } cb(nullptr); } break; case QueryType::marker: { auto& cb = m_queryCallback.get<MarkerPickCallback>(); if (color == 0) { cb(nullptr); return; } auto marker = _markerManager.getMarkerOrNullBySelectionColor(color); if (!marker) { cb(nullptr); return; } glm::dvec2 bbCenter = marker->bounds().center(); LngLat lngLat = MapProjection::projectedMetersToLngLat(bbCenter).wrapped(); MarkerPickResult markerResult(marker->id(), lngLat, {{m_position.x, m_position.y}}); cb(&markerResult); } break; case QueryType::label: { auto& cb = m_queryCallback.get<LabelPickCallback>(); if (color == 0) { cb(nullptr); return; } auto label = _labels.getLabel(color); if (!label.first || !label.second) { cb(nullptr); return; } auto props = label.second->getSelectionFeature(label.first->options().featureId); if (!props) { cb(nullptr); return; } auto coordinate = label.second->coordToLngLat(label.first->modelCenter()); LabelPickResult queryResult(label.first->renderType(), coordinate.wrapped(), FeaturePickResult(props, {{m_position.x, m_position.y}})); cb(&queryResult); } break; default: break; } }
ModelCommons::ReadyFlags TrackerContentModule::refreshModel_chain (LiveNodeModel::RefreshMode mode, InterfaceChain<ModelCommons> chain) { // << "TrackerContentModule(" << this << ")::" << __func__ // << "mode(" << mode << "), running(" << running() << ")" // << "completion_watcher(" << completion_watcher_ << ")"; if(!service_->resources.isValid()) { warning(service_.data()) << service_->resources.lastError(); return ReadyFlags(); } ReadyFlags ret = ContentModule_Simple::refreshModel_chain(mode, chain); // First step of refresh: flush the query if requested. // This is also how a new query is started, the entity creating the // TrackerContentModule passes the query in the constructor, and when the // module is attached(), a flushing refresh is initiated. if(mode & LiveNodeModel::Flush) { abort(); setRunning(true); PERF_EVENT("sequencing %d", query_id_); // will sequence the call to "sequencedStart" // should add sequencing by query_id as a quality, and possibly depend on a pending // query, if one cant be aborted for some reason QSharedPointer<TrackerContentModule> self = sharedFromThis<TrackerContentModule>(); sequenced_ = service_->query_sequencer_.addOperation ( tracker_access_->sequencingQualities() , tracker_access_->sequencingDependencies() , SequencerSlotCall::shared(self, "sequencedStart") , SequencerSignal::shared(self, SIGNAL(sequencedSuccess())) , SequencerSignal::shared(self, SIGNAL(sequencedFailure()))); ret = NothingReady; } // second step of refresh: if blocking, wait for all necessary steps for // query to complete if((mode & LiveNodeModel::Block) && running()) { if(sequenced_ && !pending_sequenced_) { pending_sequenced_ = true; QSharedPointer<SequencedOperation> seq = sequenced_; PERF_EVENT("before_sequence_wait %d", query_id_); // wait for sequencedStart to be called if not already so. // During the wait we might get aborted. Make as little assumptions // as possible seq->waitForStarted(); PERF_EVENT("after_sequence_wait %d", query_id_); if(seq->state() > SequencedOperation::Succeeded) // failed (typically aborted) model()->emitErrorImpl(seq->stateString(), 0, QModelIndex(), false); pending_sequenced_ = false; } // The wait is here because TrackerUpdateModule might have multi-step // completion cycle. tracker_access_->waitForQueryComplete(); } // third step of refresh: if a query has completed, process the results TrackerQueryResult queryResult(tracker_access_->takeQueryResult()); if(queryResult.isFinished()) { setRunning(false); sequenced_.clear(); if(queryResult.isError()) { QString error_message = queryResult.errorMessage(); if(RowStoreModel *m = model()) m->emitErrorImpl(error_message, 0, QModelIndex(), !(mode & LiveNodeModel::Block)); warning(service_.data()) << "error while modeling query (id =" << query_id_ << "):\n" << error_message; debug(4, service_.data()) << " query was:\n" << getQueryText() << "\n"; sharedFromThis(), Q_EMIT sequencedFailure(); ret = NothingReady; } else { ret = processResults(queryResult); } } return ret; }
bool GSMSerial::status() { modem.write("AT\r\n"); String str; return queryResult(str); }