zoukankan      html  css  js  c++  java
  • MySQL C API的一个让我头疼的问题,获得一行记录中包括NULL

     遇到过几次错误,通过gdb来查看错误对战,发现错误居然是atoi调用出错,除非atoi(NULL) 才会报这种错误.说明 row[0]==NULL.


    (gdb) bt #
    0 0x00007f82c6629132 in ____strtoll_l_internal () from /lib64/libc.so.6 #1 0x00007f82c6625ee0 in atoi () from /lib64/libc.so.6 #2 0x0000000000438c7b in MySQL_Util::select_one ( sql_string=0x7f82c4544190 "select sum(pointcoupon_added) from tb_recharge_records where user_id=214873 and status=0 and method=0 ", get_data=0x7f82c4544598, length=4, data_type=MYSQL_INT, pmysql=0x7f82c4545210) at MySQL_Util.hpp:177

     好无语啊,SQL语句中包括 sum() max() count(),及时没有返回值,也会执行到 这里面:

                MYSQL_RES *res = NULL;
                MYSQL_ROW row = NULL;
                res=mysql_store_result(pmysql);
                if( (row=mysql_fetch_row(res) )!=NULL )
                {
                                      // atoi(row[0])
                }else{
                    nReturn=MYSQL_SQL_FAILED;
                }
                mysql_free_result(res);
                row=NULL;

    NULL也会返回一行记录,真是够恶心的啊!只能判断 if(row[0]!=NULL) XXX=atoi(row[0]);

    或许 atoi重新定义下 就好了:

    static inline int mystrlen(char *str){//const 
        if(str==NULL)
            return 0;
        else
            return strlen(str);
    }
    static inline int myatoi(char * str){
        if(str==NULL)
            return 0;
        else
            return atoi(str);
    }

    类似的还有strlen(NULL)也会报错,一起改了.

  • 相关阅读:
    登录及注册页面
    多方式登录
    git笔记
    后台主页模块设计
    auth模块迁移后需新增字段
    使用idea构建SpringBoot源码
    Springboot相关面试问题
    Springboot自动加载工具-devtools的理解与使用
    SpringBoot项目的一些简单常用配置
    Java线程池及Executor框架的理解
  • 原文地址:https://www.cnblogs.com/ayanmw/p/3650187.html
Copyright © 2011-2022 走看看