- 论坛徽章:
- 0
|
/****声明一个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:
请帮助 |
|