Seeks a record with key values
Class EasycomFile
Syntax
public Boolean EasycomFile.ReadKey(object keyValues)
public Boolean EasycomFile.ReadKey object keyValues, Integer lastFieldPartialLen)
public Boolean EasycomFile.ReadKey(object keyValues, keyReadOp op)
public Boolean EasycomFile.ReadKey(object keyValues, keyReadOp op, Integer lastFieldPartialLen)
Description
These functions seek a record using the specified values for the key. The function returns true if the record was found and false otherwise.
Parameter |
Description |
|
Type |
keyValues |
Specifies the key values. If there is only one key field or if the seek must be done only on the first field, the value can be a simple CLR type (like string, integer, …). If several key values need to be specified, the keyValues object must be an array of CLR types. |
|
object |
lastFieldPartialLen
|
Allows partial key search. This represents the length, in bytes, of the significant part for the last key value specified. |
|
Integer |
Op |
Specifies the key operation verb. The possible values are : • Eq: must be equal (totally or partially depending on other parameters). • Ge: must be greater or equal (>= • Le: must be less or equal (<= • Gt: must be strictly greater (>) • Lt: must be strictly less (<) • NextEq: must follow current record and be equal • PrevEq: must precede current record and be equal • NextUnEq: must follow current record and be not equal • PrevUnEq: must precede current record and be not equal |
|
keyReadOp |
This function allows real native usage of the key that is in the logical or physical file. The application must open the correct logical file in order to use a specified key (then it is possible to use EasycomDataSet.GetPosition/EasycomDataSet.GotoPosition to synchronise different logical files).
The "lastFieldPartialKeyLen" allows partial key search. If n key values are specified in the keyValues parameters, "lastFieldPartialKeyLen" represents the size of the nth key field. In other words, the key search will ignore the rest of the key.
If "lastFieldPartialKeyLen" is omitted the read will be performed on all key fields specified (ignoring others).
Examples (VB.NET)
Suppose that you have a logical file that has a key with Country ID has Packed Decimal 4 digits, and customer name. If you want to seek the first customer that begins with "LA" string in a specified country, you will have a code like:
Dim my_cnx As EasycomConnection
Dim my_file As EasycomFile
Dim result As String
Dim s_values() As Object = {"US", "P"}
my_cnx = New EasycomConnection
my_cnx.ConnectionString = "Server=194.206.160.111;User Id=
my_cnx.Open()
my_file = my_cnx.OpenFile("s_cust_cnfn")
' A search with a compound key
If my_file.ReadKey(s_values, 1) Then
MessageBox.Show("Customer ID: " + my_file.GetValue("CUST_ID").ToString())
MessageBox.Show("Customer Name: " + my_file.GetValue("FIRSTNAME").ToString())
MessageBox.Show("Country: " + my_file.GetValue("COUNTRY").ToString())
End If
'To seek the first "US" country:
my_file.ReadKey("US")
'To seek first customer beginning with "Jo":
my_file = my_cnx.OpenFile("s_cust_na")
my_file.ReadKey("Jo", 2)
Examples (C#)
Suppose that you have a logical file that has a key with Country ID has Packed Decimal 4 digits, and customer name. If you want to seek the first customer that begins with "LA" string in a specified country, you will have a code like:
EasycomConnection my_cnx;
EasycomFile my_file;
string result;
object s_values[] = {"US", "P"}
my_cnx = new EasycomConnection();
my_cnx.ConnectionString = "Server=194.206.160.111;User Id=
my_cnx.Open();
my_file = my_cnx.OpenFile("s_cust_cnfn");
' A search with a compound key
if my_file.ReadKey(s_values, 1)
{
MessageBox.Show("Customer ID: " + my_file.GetValue("CUST_ID").ToString());
MessageBox.Show("Customer Name: " + my_file.GetValue("FIRSTNAME").ToString());
MessageBox.Show("Country: " + my_file.GetValue("COUNTRY").ToString());
}
'To seek the first "US" country:
my_file.ReadKey("US");
'To seek first customer beginning with "Jo":
my_file = my_cnx.OpenFile("s_cust_na");
my_file.ReadKey("Jo", 2);
See also