注: 本文档主要根据原作者的英文文档protocol.en.txt写成,做了一些翻译工作和添加了一些例子以及一些需要注意的地方。如果本文档对你有所帮助,欢迎关注我的新浪微博:http://weibo.com/u/1857063732 如果有建议,欢迎发送到我的邮箱xiaoxuye1988@163.com 目前就职于 欢聚时代(YY), 从事于后台开发工作。
Openingindex
英文原文如下
Openingindex
The'open_index' request has the following syntax.
P <indexid><dbname> <tablename> <indexname> <columns>[<fcolumns>]
-<indexid> is a number in decimal.
-<dbname>, <tablename>, and <indexname> are strings. To openthe primary
key, use PRIMARY as <indexname>.
-<columns> is a comma-separated list of column names.
-<fcolumns> is a comma-separated list of column names. This parameter is
optional.
Oncean 'open_index' request is issued, the HandlerSocket plugin opens the
specifiedindex and keep it open until the client connection is closed. Each
openindex is identified by <indexid>. If <indexid> is already open, theold
openindex is closed. You can open the same combination of <dbname>
<tablename><indexname> multple times, possibly with different <columns>.
Forefficiency, keep <indexid> small as far as possible.
打开索引
‘open_index’有以下参数:
P <indexid><dbname> <tablename> <indexname> <columns>[<fcolumns>]
-<indexid>是一个十进制的数字。
-<dbname>, <tablename>, 和<indexname>都是string类型。如果要用主键,用‘PRIMARY’作为<indexname>的值。
-<columns>是以逗号分隔的一串列的名字。
-<fcolumns>是以逗号分隔的一串列的名字。这个参数是可选的。
当‘open_index’请求执行后,handlersocket插件就会打开所指定的索引并且一直保持打开状态直到这个客户端的连接关闭。每一个打开的索引都被一个<indexid>唯一标志。如果同一个<indexid>已经打开,那么之前所打开的索引会关闭。你可以打开同一个(<dbname><tablename> <indexname>) 多次,可能是不同的<columns>。考虑到效率,尽量保持<indexid>的数值较小。
Responsefor 'open_index'
If'open_index' is succeeded, HandlerSocket returns a line of the following
syntax.
0 1
‘open_index’请求的返回:
如果'open_index'请求发送成功,HandlerSocket 会返回0(成功)或1(失败);
所使用的成员函数的原型:
virtual void request_buf_open_index(size_t pst_id, const char *dbn,
const char *tbl, constchar *idx, const char *retflds,
const char *filflds = 0) =0;
举几个例子说明:
数据库中 add index index1 (col1,col2....)
hstcpcli_ptr cli =hstcpcli_i::create(sock_args);
cli->request_buf_open_index(indexid,"test", "test1", "index1","col1,col2,col3,col4");
do { //发送request_buf_open_index请求
if(cli->request_send() != 0) {
fprintf(stderr, "request_send:%s\n", cli->get_error().c_str());
break;
}
if ((code = cli->response_recv(numflds)) != 0) {
fprintf(stderr, "response_recv:%s\n", cli->get_error().c_str());
break;
}
}while (false);
cli->response_buf_remove();
也可以使用<fcolumns>
如:
cli->request_buf_open_index(indexid,"test", "test1", "index1","col1,col2,col3,col4","col5,col6");
(其中col1,col2...均为列名)