handlersocket使用 第六章 Inserting data

注: 本文档主要根据原作者的英文文档protocol.en.txt写成,做了一些翻译工作和添加了一些例子以及一些需要注意的地方。如果本文档对你有所帮助,欢迎关注我的新浪微博:http://weibo.com/u/1857063732 如果有建议,欢迎发送到我的邮箱xiaoxuye1988@163.com 目前就职于 欢聚时代(YY), 从事于后台开发工作


Insertingdata

英文原文如下

Insertingdata

        

The'insert' request has the following syntax.

 

    <indexid> + <vlen> <v1>... <vn>

 

-<vlen> indicates the length of the trailing parameters <v1> ...<vn>. This

  must be smaller than or equal to the lengthof <columns> specified by the

  corresponding 'open_index' request.

-<v1> ... <vn> specify the column values to set. For columns not in

  <columns>, the default values for eachcolumn are set.

 

‘insert’请求有以下参数:

 

<indexid>+ <vlen> <v1> ... <vn>

 

-<vlen>是接下来参数<v1> ... <vn>的个数。这个数字必须不大于那个在其相对于的‘open_index’请求中指定的参数<columns>的的列数。

 

-<v1>... <vn>指定了要被插入的列值。对于那些不在<columns>中的列,将被设为默认的值。

 

 

Response for 'insert'

英文原文如下

If'insert' is succeeded, HandlerSocket returns a line of the following

syntax.

 

   0 1

 

如果‘insert’请求发送成功,Handlersocket将会返回以下返回值0(插入成功)或1(插入失败)。

 

 

下面发给例子:

cli->request_buf_open_index(1, "test","test1", "index1", "col1,col2,col3"); 

........

vector<string_ref> vec;

vec.push(..)

.....

const string kTestInsertOp("+");

const string_ref kTestInsertOpRef(kTestInsertOp.data(),kTestInsertOp.size());

 

cli->request_buf_exec_generic(indexid,kTestInsertOpRef,&vec[0],vec_length,0,0,0, 0, 0, 0);

int res = cli->request_send();

.....

 

a.当表的主键是自增的一个值时,如上例中col0为主键,则将会把新建行的主键的值以类似‘find’请求的结果返回。

 

b.注意:当某一个列的类型为timestamp default CURRENT_TIMESTAMP时,插入的值将为

0000-00-00 00:00:00(无论在request_buf_open_index中是否打开)。

1.可以使用的间接解决方法,insert之后update,如:

cli->request_buf_exec_generic(1,kTestInsertOpRef,&vec[0],vec_size,0,0,0, 0, 0, 0);      

 cli->request_buf_exec_generic(1,kTestEqualOpRef,&vec[0],vec_size,limit,offset,kTestUpdateOpRef,&vec_in[0],vec_in_szie);

 

cli->request_send()......

 

2.把timestamp时间类型改为datetime类型。但是datetime类型不支持default,好像得写触发器实现。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值