return buffer;
}
/**************************************************************************
* PROCEDURE : readCol
* 返回一行数据
**************************************************************************/
char * readCol (struct sqlda *sqldaPointer, short sqlvarIndex, char * buffer){
short numBytes;
short idx, ind ; /* Array idx variables */
/* Variables for decoding packed decimal data */
short bottom, point ;
unsigned short top, precision, scale;
char tmpstr[1024];
short pos;
short collen;
char *dataptr;
/* 检查是否为null */
if ( sqldaPointer->sqlvar[sqlvarIndex].sqltype & 1 &&
*(sqldaPointer->sqlvar[sqlvarIndex].sqlind) < 0 )
{
buffer[0] = 0;
return buffer;
}
dataptr = (char *) sqldaPointer->sqlvar[ sqlvarIndex ].sqldata;
collen = sqldaPointer->sqlvar[ sqlvarIndex ].sqllen;
switch ( sqldaPointer->sqlvar[ sqlvarIndex ].sqltype ) {
case SQL_TYP_INTEGER: /* long */
case SQL_TYP_NINTEGER: /* long with null indicator */
sprintf(buffer, "%ld", * ( long *) dataptr ) ;
break ;
case SQL_TYP_SMALL: /* short */
case SQL_TYP_NSMALL: /* short with null indicator */
sprintf(buffer, "%d", * ( short *) dataptr ) ;
break ;
case SQL_TYP_DECIMAL: /* decimal */
case SQL_TYP_NDECIMAL: /* decimal with null indicator */
/* Determine the scale and precision */
precision = ((char *)&(collen))[0];
scale = ((char *)&(collen))[1];/*************************************************************************
*计算精度
*************************************************************************/
if ((precision %2) == 0) precision= 1;/* Calculate the total number of bytes */
idx = ( short ) ( precision2 ) / 2 ;
point = precision - scale ;pos = 0;
/* Determine the sign */
bottom = *(dataptridx -1) & 0x000F ; /* sign */
if ( (bottom == 0x000D) || (bottom == 0x000B) ) {
buffer[pos]="-";
}
/* Decode and print the decimal number */
for (pos=0, ind=0; ind < idx; ind) {
top = *(dataptrind) & 0x00F0 ;
top = (top >> 4 ) ;
bottom = *(dataptrind) & 0x000F ;
if ( point-- == 0 ) buffer[pos]="." ;
buffer[pos]="0"top ;
/*************************************************************************/
/*忽略最后一位(符号位) */
/*************************************************************************/
if ( ind < idx - 1 ) { /* sign half byte ? */
if ( point-- == 0 ) buffer[pos] = ".";
buffer[pos] = "0"bottom;
}
}
buffer[pos] = 0;
break ;
case SQL_TYP_FLOAT: /* double */
case SQL_TYP_NFLOAT: /* double with null indicator */
sprintf(buffer, "%e", * (double *) dataptr) ;
break ;
case SQL_TYP_CHAR: /* fixed length character string */
case SQL_TYP_NCHAR: /* fixed length character string with null
indicator */
strncpy(buffer, dataptr, collen);
buffer[collen] = 0;
collen--;
while ((collen >=0) && (buffer[collen] == " "))
buffer[collen--] = 0;
break;
case SQL_TYP_LSTR: /* varying length character string, 1-byte length */
case SQL_TYP_NLSTR: /* varying length character string, 1-byte length,
with null indicator *//* Initialize blen to the value the length field in the varchar data structure. */
collen = *dataptr;
/* Advance the data pointer beyond the length field */
dataptr =sizeof(char);
strncpy(buffer, dataptr, collen);
buffer[collen] = 0;
break ;
case SQL_TYP_CSTR: /* null terminated varying length character string */
case SQL_TYP_NCSTR: /* null terminate varying length character
string with null indicator */
strcpy(buffer, dataptr);
break ;
default:
buffer[0] = 0;
}return buffer;
}
/* COMMENT OUT OFF */
推荐阅读
- 坚果pro2哪个版本值得买?坚果pro2各版本有什么区别?
- F4版与D2版相比有何特点
- 坚果Pro 2有几个版本?坚果Pro 2各版本价格多少?
- 墨者写作中查看历史版本具体操作步骤
- 完全版 ESQL/C资料三
- kha苹果是什么版本
- 荒野乱斗九游版激活码在哪
- HTC U11国行版系统更新了什么?HTC U11国行版系统更新内容
- 小米MIX2黑色陶瓷版和全陶瓷尊享版哪个好?哪个更划算?
- 增补版 SCO UNIX快速入门
