码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 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::operator>>(otl_long_string&) [clone .part.49] ()
    #7  0x000000000097ac06 in otl_tmpl_lob_stream::operator>>(otl_long_string&) ()
    #8  0x0000000000a59aac in testlongtext(int) ()
    #9  0x000000000094fde3 in main ()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    未作深究,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环境进行测试

  • 相关阅读:
    【云原生 | Kubernetes 实战】06、Pod高级实战:基于污点、容忍度、亲和性的多种调度策略(下)
    BI-SQL丨SNAPSHOT
    Kotlin基础——接口和类
    面试题:海量数据处理利器,布隆过滤器
    《安富莱嵌入式周报》第278期:基于RUST编程语言RTOS,固态继电器芯片,微软发布物联网组件框架,支持多款蜂窝,LoRa和WiFi芯片工业物联网4.0书籍
    物联网开发零基础教程
    MMDet3D——报错解决:KeyError: ‘XXX is not in the models registry‘
    国产麒麟V10系统如何运行exe文件,麒麟系统运行windows软件
    vioovi的ECRS工时分析软件:食品加工行业的生产效率提升利器
    Python实现人脸识别
  • 原文地址:https://blog.csdn.net/qq_42896627/article/details/126560101
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号