四.Getting data
英文原文如下
Getting data
The'find' request has the following syntax.
LIMis a sequence of the following parameters.
INis a sequence of the following parameters.
@
FILETERis a sequence of the following parameters.
-
'open_index' request executed previously onthe same connection.
-
HandlerSocket supports '=', '>', '>=','<', and '<='.
-
must be smaller than or equal to the numberof index columns specified by
the
-
-LIM is optional.
as if 1 and 0 are specified. These parameterworks like LIMIT of SQL.
These values don't include the number ofrecords skipped by a filter.
-IN is optional. It works like WHERE ... IN syntax ofSQL.
smaller than the number of index columnsspecified by the
parameter of the corresponding 'open_index'request. If IN is specified in
a find request, the
-FILTERs are optional. A FILTER specifies a filter.
(filter) or 'W' (while).
filters can be specified, and work as thelogical AND of them. The
difference of 'F' and 'W' is that, when arecord does not meet the
specified condition, 'F' simply skips therecord, and 'W' stops the loop.
‘find’请求有以下参数:
‘LIM’是以下参数的一个序列
‘IN’是一项参数的一个序列
@
‘FILETER’是以下参数的一个序列
-
-
-
-
-
-IN是可选的。它的作用和SQL语句中的WHERE....IN相似。
-FILTERs是可选参数。一个FILTER指定了一个过滤条件。
Responsefor 'find'
If'find' is succeeded, HandlerSocket returns a line of the following
syntax.
0
-
'open_index' request.
-
...
'find'请求的返回:
如果'find'请求成功发送,HandlerSocket 将会返回以下形式:
0
-
-
主要所使用的成员函数的原型:
virtual void request_buf_exec_generic(size_t pst_id, conststring_ref& op,
const string_ref *kvs,size_t kvslen, uint32_t limit, uint32_t skip,
const string_ref&mod_op, const string_ref *mvs, size_t mvslen,
const hstcpcli_filter*fils = 0, size_t filslen = 0,
int invalues_keypart = -1,const string_ref *invalues = 0,
size_t invalueslen =0) = 0;
下面举几个例子详细说明:
1.找到索引等于某一组特定值的查找
vector
......
const stringkTestEqualOp("=");
const string_refkTestEqualOpRef(kTestEqualOp.data(), kTestEqualOp.size());
cli->request_buf_exec_generic(indexid,kTestEqualOpRef, &vec[0], vec_length, limit, offset, 0, 0, 0);
a.如果索引的列为(col2,col3),vec只为赋了一个值,则第二个值将被忽略,结果为(col2,?)的limit行,并且按第二个值排序(升序)。
若索引为多列,则根据上述类推即可,即为(col2,col3....,,?,?,?)。
2. Where.......in的用法
cli->request_buf_exec_generic(indexid, kTestEqualOpRef, &vec[0],vec_length, limit ,offset, 0, 0, 0, 0, 0, icol, &vec_in[0], vec_in_length);
其中vec[icol]的值将被忽略,其所取值在vec_in中
注意:使用这个用法是,对于vec_in中的每个值,只能找到第一个结果。
3可选参数FILTERs 的用法
首先在’open_index’请求中要指定
cli->request_buf_open_index(indexid,"test","test1", "index1", "col1,col2,col3,col4","col5,col6");
中的"col5,col6"
在根据索引寻找行的时候,可以另外根据col5和col6指定额外的匹配条件。
FILETER的结构
struct hstcpcli_filter {
string_ref filter_type; ///////
string_ref op; ///
size_t ff_offset; /////
string_ref val; //////
hstcpcli_filter() :ff_offset(0) { }
};
op可以为比较操作符
举个例子说明:
vector
hstcpcli_filter filter;
stringkey_F("F");
filter.filter_type =string_ref(key_F.data(), key_F.size());
string key_op("<=");
filter.op =string_ref(key_op.data(), key_op.size());
uid = 600;
snprintf(key_buf, 32,"%u", uid);
string key_val(key_buf);
filter.val =string_ref(key_val.data(), key_val.size());
filter.ff_offset = 0;
vec_filter.push_back(filter);
.....
cli->request_buf_exec_generic(indexid, kTestEqualOpRef,&vec[0], vec_length, limit, offset, 0, 0, 0, &vec_filter[0],vec_filter_length, -1, 0, 0);
注意情况看前文中的翻译。
注意:
astring_ref的值是string的引用,若在string_ref构造后修改string,仍然会再次修改string_ref