OTL Select with MySQL LONGTEXT in stream mode注意事项

因为业务需求,web方面将字段text修改为mediumtext,同时也需要server方面来适配。server业务是查询这个字段

我们内部有封装代码,不过也是根据官网文档来的,链接:http://otl.sourceforge.net/otl3_ex128.htm
有几点说明:
1 需要设置set_lob_stream_mode(true)
2 open接口的buffsize需要设置为1
3 官网文档给的例子,select这里没有设置set_commit(0),但是insert是有设置的。但是如果select如果没有设置,程序运行会报错的,如下图
在这里插入图片描述
在这里插入图片描述

4 此外还需注意的点,无论text/mediumtext/longtext类型的都需要将该字段放在语句的最后。
ex:
a(int),b(int),c(text/mediumtext/longtext)

上述字段类型,sql语句应该这么写
select a,b,c from tbl_test;
如果是不是放在最后
select c,a,b from tbl_test;这么些,otl内部会直接抛异常。

堆栈有抓到

(gdb) bt
#0  0x00007f9f06625207 in raise () from /lib64/libc.so.6
#1  0x00007f9f066268f8 in abort () from /lib64/libc.so.6
#2  0x00007f9f071507d5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3  0x00007f9f0714e746 in ?? () from /lib64/libstdc++.so.6
#4  0x00007f9f0714e773 in std::terminate() () from /lib64/libstdc++.so.6
#5  0x00007f9f0714e993 in __cxa_throw () from /lib64/libstdc++.so.6
#6  0x000000000093e0c6 in otl_tmpl_lob_stream<otl_exc, otl_conn, otl_cur, otl_var>::operator>>(otl_long_string&) [clone .part.49] ()
#7  0x000000000097ac06 in otl_tmpl_lob_stream<otl_exc, otl_conn, otl_cur, otl_var>::operator>>(otl_long_string&) ()
#8  0x0000000000a59aac in testlongtext(int) ()
#9  0x000000000094fde3 in main ()

未作深究,otl的代码看着有点费劲对于现在的我来说。。。

官网说明:

The ODBC as well as DB2 CLI standards recommend that LOBs should be put at the end of INSERT/SELECT statements. For example:
INSERT INTO my_tab (f1,f2,f3_lob,f4_lob)…
SELECT f1,f2,f3_lob,f4_lob FROM my_tab…

The recommendation applies especially in the case of piece-wise data operations, that is, in the OTL LOB stream mode. At the same time, the standards say that it is up to the ODBC drivers/database APIs to either enforce or not to enforce that rule. The LOB’s part of OCI8 in Oracle does not require that kind of thing, so it is really up to the developer to decide what to do. However, the general recommendation for writing portable code, that uses the LOB stream mode, would be to put LOBs at the end of the column lists in INSERT or SELECT statements.
大致意思,为了兼容,建议使用lob的对应字段放在sql语句的最后面

以上测试均在mysql环境进行测试

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值