Pivotal GemFire® v8.2

Executing a Query from the Native Client

Executing a Query from the Native Client

C#/.NET and C++ examples show how to execute a query from the native client.

Note: In all queries that use the example data, it is assumed that the /portfolios region has javaobject.Portfolio objects on the cache server.
  1. If you are using the C++ native client, get a pointer to the QueryService method.
  2. Create a QueryPtr to a query (C++) or create a query instance (C# .NET) that is compatible with the OQL specification.
  3. Use the execute method for the Query interface to submit the query string to the cache server. The server remotely evaluates the query string and returns the results to the client.
  4. You can iterate through the returned objects as part of the query process.

C#/.NET Example

Query<Portfolio> qry = qrySvc.NewQuery("SELECT DISTINCT * FROM
ISelectResults<Portfolio> results = qry.Execute();
SelectResultsIterator<Portfolio> iter = results.GetIterator(); while
(iter.MoveNext()) {
Console.WriteLine( iter.Current.ToString()); }

C++ Example

Note: The C++ examples in this chapter all assume that you have already obtained a pointer to the QueryService.
QueryServicePtr qrySvcPtr =
QueryPtr qry = qrySvcPtr->newQuery(
"SELECT DISTINCT * FROM /Portfolios WHERE status = ‘active’");
SelectResultsPtr resultsPtr = qry->execute(10);
SelectResultsIterator iter = resultsPtr->getIterator();
PortfolioPtr portfolio = dynCast<PortfolioPtr > (;