蛋疼直接用sql判断大小,更蛋疼的是比较结果是错的,不知道是不是用SQLBindParameter的时候有参数有问题.到底是怎么回事???
测试程序主要部分如下: HSTMT hstmt;
SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hstmt);
hr=SQLPrepare(hstmt,(SQLCHAR *)"select ?<=?",SQL_NTS);
char a[10],b[]="99999.9";
SQLUINTEGER ok;
SQLLEN lenbuf1=SQL_NTS,lenbuf2;
hr=SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_DECIMAL,8,1,a,sizeof(a)/sizeof(*a),&lenbuf1);
hr=SQLBindParameter(hstmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_DECIMAL,8,1,b,sizeof(b)/sizeof(*b),&lenbuf1);
hr=SQLBindCol(hstmt,1,SQL_C_ULONG,&ok,0,&lenbuf2);
while(cin>>a)
{
if(SQL_SUCCEEDED(SQLExecute(hstmt)))
if(SQL_SUCCEEDED(SQLFetch(hstmt)))
{
cout<<"result is "<<ok<<endl;
SQLCloseCursor(hstmt);
continue;
}
cout<<"something wrong"<<endl;
}测试结果如下:
1234
result is 1
99999.9
result is 1
100000
result is 1
1000000
result is 1
100000.1
result is 1
9999999
result is 0
9999991
result is 0
1111111
result is 1
测试程序主要部分如下: HSTMT hstmt;
SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hstmt);
hr=SQLPrepare(hstmt,(SQLCHAR *)"select ?<=?",SQL_NTS);
char a[10],b[]="99999.9";
SQLUINTEGER ok;
SQLLEN lenbuf1=SQL_NTS,lenbuf2;
hr=SQLBindParameter(hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_DECIMAL,8,1,a,sizeof(a)/sizeof(*a),&lenbuf1);
hr=SQLBindParameter(hstmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_DECIMAL,8,1,b,sizeof(b)/sizeof(*b),&lenbuf1);
hr=SQLBindCol(hstmt,1,SQL_C_ULONG,&ok,0,&lenbuf2);
while(cin>>a)
{
if(SQL_SUCCEEDED(SQLExecute(hstmt)))
if(SQL_SUCCEEDED(SQLFetch(hstmt)))
{
cout<<"result is "<<ok<<endl;
SQLCloseCursor(hstmt);
continue;
}
cout<<"something wrong"<<endl;
}测试结果如下:
1234
result is 1
99999.9
result is 1
100000
result is 1
1000000
result is 1
100000.1
result is 1
9999999
result is 0
9999991
result is 0
1111111
result is 1
如果把?替换成相应的数字的话在命令行里是没问题的,忘了说了一点,用printf硬编码sql语句的话就不会出问题
mysql> select 100000<=99999.9;
+-----------------+
| 100000<=99999.9 |
+-----------------+
| 0 |
+-----------------+
这个测试用程序测却不对
你说的正好反了吧,是吧decimal换成string进行比较的吧。
SQLBindParameter(
SQLHSTMT
StatementHandle,
SQLUSMALLINT
ParameterNumber,
SQLSMALLINT
InputOutputType,
SQLSMALLINT
ValueType,
SQLSMALLINT
ParameterType,
SQLULEN
ColumnSize,
SQLSMALLINT
DecimalDigits,
SQLPOINTER
ParameterValuePtr,
SQLLEN
BufferLength,
SQLLEN *
StrLen_or_IndPtr);
其中
ValueType [Input] The C data type of the parameter. For more information, see " ValueType Argument" in "Comments."
ParameterType [Input] The SQL data type of the parameter. For more information, see " ParameterType Argument" in "Comments."
貌似没反吧