免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2421 | 回复: 0
打印 上一主题 下一主题

esqlc 动态sql问题,打印不出所有数据来 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-06 09:06 |只看该作者 |倒序浏览
/****声明一个SQLDA结构,来存放查询的数据  ********/
        /****声明一个SQLVA结构,来存放列信息  ********/
        struct sqlda *data_ptr;
        struct sqlvar_struct *column_ptr;
        static char data_buff[10240];
       
        int pos, cnt, size;
       
        EXEC SQL BEGIN DECLARE SECTION;
                int2 i, desc_count;
                char query_string[1024];
        EXEC SQL END DECLARE SECTION;
       
/*        EXEC SQL connect to 'stores7';*/
       
        /* These next four lines have hard-wired both the query and
        * the value for the parameter. This information could have
        * been entered from the terminal and placed into the strings
        * query_string and a query value string (queryvalue), respectively.
        */
        sprintf(query_string, "%s %s",        "select * from engineer_set","";
       
        EXEC SQL prepare sql_id from :query_string;
        EXEC SQL declare sql_cursor cursor for sql_id;
        EXEC SQL describe sql_id into data_ptr;
       
        desc_count = data_ptr->sqld;
       
        writelogfile(modelname,"[%s,%d]There are %d returned columns:\n",__FILE__,__LINE__,desc_count);       
       
        /* Print out what DESCRIBE returns */
        for (i = 1; i <= desc_count; i++)
                printsqlda(i, data_ptr->sqlvar[i-1]);
       
        for(column_ptr=data_ptr->sqlvar, cnt=pos=0; cnt < desc_count; cnt++, column_ptr++)
        {
                /* Allow for the trailing null character in C character arrays */
                if(column_ptr->sqltype==SQLCHAR)
                        column_ptr->sqllen += 1;
                /* Get next word boundary for column data and assign buffer position to sqldata */
                pos = (int)rtypalign(pos, column_ptr->sqltype);
                column_ptr->sqldata = &data_buff[pos];
               
                /* Determine size used by column data and increment        buffer position */
                size = rtypmsize(column_ptr->sqltype, column_ptr->sqllen);
                pos += size;
        }
       
        EXEC SQL open sql_cursor;
        for (;
        {
                EXEC SQL fetch sql_cursor using descriptor data_ptr;

                if (strncmp(SQLSTATE, "00", 2) != 0)
                        break;

                /* Print out the returned values */
                for (i=0; i<desc_count; i++)
                        writelogfile(modelname,"[%s,%d]Column: %s\tValue:%s\n",__FILE__,__LINE__, data_ptr->sqlvar[i].sqlname,data_ptr->sqlvar[i].sqldata);       
        }

        if (strncmp(SQLSTATE, "02", 2) != 0)
                writelogfile(modelname,"[%s,%d]SQLSTATE after fetch is %s\n",__FILE__,__LINE__,SQLSTATE);       
        EXEC SQL close sql_cursor;
       
        EXEC SQL free sql_id;
        EXEC SQL free sql_cursor;
        /* No need to explicitly free data buffer in this case because
        * it wasn't allocated with malloc(). Instead, it is a static char
        * buffer
        */
        /* Free memory assigned to sqlda pointer. */
        free(data_ptr);


//--------------------------------------------------------------------
出现的问题,打印的时候,字符串以外的数据,打印不出来
我想把sqlda中,所有的sqlvar信息类型都转化为字符输出可以吗
//--------------------------------------------------------------------

以下为日志

08:49:37!16129.1:[tuxsql.ec,109]Column: serialno        Value:

08:49:37!16129.1:[tuxsql.ec,109]Column: ne_name        Value:JI7C

08:49:37!16129.1:[tuxsql.ec,109]Column: user_name        Value:root

08:49:37!16129.1:[tuxsql.ec,109]Column: machine_ip        Value:10.19.64.187

08:49:37!16129.1:[tuxsql.ec,109]Column: insert_time        Value:


08:49:37!16129.1:[tuxsql.ec,109]Column: start_time        Value:


08:49:37!16129.1:[tuxsql.ec,109]Column: end_time        Value:

08:49:37!16129.1:[tuxsql.ec,109]Column: city_id        Value:

08:49:37!16129.1:[tuxsql.ec,109]Column: manufactory_id        Value:

08:49:37!16129.1:[tuxsql.ec,109]Column: object_class        Value:


请帮助
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP