Method ExecuteReader
ExecuteReader(String, IDictionary, Boolean, Int32)
Performs search on the Cache based on the query specified. Also you can specify the chunkSize and flag for specifying if you want data with keys.
Declaration
public virtual ICacheReader ExecuteReader(string query, IDictionary values, bool getData, int chunkSize)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | simple SQL like query syntax to query objects from cache |
System.Collections.IDictionary | values | The IDictionary of attribute names and values. |
System.Boolean | getData | Flag to receive the values/data along with keys |
System.Int32 | chunkSize | Size of data/keys packets received after search, default value is 512 * 1024 kb's |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache= NCache.InitializeCache("myCache");
Hashtable values = new Hashtable();
values.Add("ProductName", "Chai");
values.Add("UnitsInStock", 250);
// Instead of Product, specify fully qualified name of your custom class.
string query = "SELECT Product where this.ProductName = ?";
try
{
ICacheReader reader = cache.ExecuteReader(query, values, true, 50);
if (reader.FieldCount > 0)
{
while (reader.Read())
{
object category = reader.GetValue(0);
//perform operations
}
}
else
{
//perform operations
}
reader.Close();
}
catch
{
//handle exception
}
ExecuteReader(String, IDictionary)
Performs search on the Cache based on the query specified.
Declaration
public virtual ICacheReader ExecuteReader(string query, IDictionary values)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | simple SQL like query syntax to query objects from cache |
System.Collections.IDictionary | values | The IDictionary of attribute names and values. |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache = NCache.InitializeCache("myCache");
Hashtable values = new Hashtable();
values.Add("Name", "Paul Jones");
string query="select Test.Application.Employee where this.Name = ?";
ICacheReader reader=_cache.ExecuteReader(query,values);
values.Clear();
values.Add("Salary", 2000);
query="select Test.Application.Employee where this.Salary > ?";
result=_cache.ExecuteReader(query,values);
values.Clear();
values.Add("Name", "Paul jones");
values.Add("Salary", 2000);
query="select Test.Application.Employee where this.Name = ? and this.Salary > ?";
result=_cache.ExecuteReader(query,values);
values.Clear();
values.Add("Name", "Paul Jones");
values.Add("Salary", 2000);
query="select Test.Application.Employee where Not(this.Name = 'Paul Jones' and this.Salary > 2000)";
reader=_cache.ExecuteReader(query,values);
if (reader.FieldCount > 0)
{
while (reader.Read())
{
object category = reader.GetValue(0);
//perform operations
}
}
else
{
//perform operations
}
reader.Close();
ExecuteReader(String, IDictionary, Boolean)
Performs search on the Cache based on the query specified. Also getData flag can be set that specifies if you want to receive values with keys.
Declaration
public virtual ICacheReader ExecuteReader(string query, IDictionary values, bool getData)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | simple SQL like query syntax to query objects from cache |
System.Collections.IDictionary | values | The IDictionary of attribute names and values. |
System.Boolean | getData | Flag to receive the values/data along with keys |
Returns
Type | Description |
---|---|
ICacheReader | Returns a cache data reader |
Examples
These operators are supported by NCache Queries.
- Comparison Operators = , == , != , <> , < , > , <=, >=, IN
- Logical Operators AND , OR , NOT
- Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Cache _cache= NCache.InitializeCache("myCache");
product1 = new Product(3, "Tunnbr?d", "", 4, 2);
product2 = new Product(4, "Tunnbr?d", "", 5, 9);
_cache.Add("2202", product1);
_cache.Add("2203", product2);
string query="SELECT Product WHERE this.ProductName = ? and this.UnitsInStock > ?";
Hashtable values = new Hashtable();
values.Add("ProductName", "Chai");
values.Add("UnitsInStock", 250);
try
{
ICacheReader reader = cache.ExecuteReader(query, values, true);
if (reader.FieldCount > 0)
{
while (reader.Read())
{
object category = reader.GetValue(0);
//perform operations
}
}
else
{
//perform operations
}
reader.Close();
}
catch
{
//handle exception
}