比较两种SQL类型 [英] Comparing Two SQL Types

查看:99
本文介绍了比较两种SQL类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个if语句,其中有两个我要相互比较的SQL类型
声明......

 如果((< int  *)rowCount3> =( int  *)chval1)



rowCount3是一个SQLINTEGER
chval1是一个SQLCHAR chval1 [128]

我正在尝试强制演员表,以便将苹果与苹果进行比较.我想它们都必须是真实的可比数字.感谢您提供任何帮助,谢谢.

解决方案

大锤子(tm)不能解决所有问题.您无法打字以使事情正常进行的方式.仅当数据类型已经兼容时,类型转换才起作用. SQLINTEGER和SQLCHAR不兼容.

就是说,如果您有一个存储在数据库中的任意字符字符串(SQLCHAR),并且您认为这些字符只是数字,则可以在字符串上应用"_atoi()"函数以进行转换根据数字解释找到的字符.

然后,您将拥有两种兼容的类型,并且可以对其进行数学比较.

附带一提,似乎数据库记录本身设计不良.上面的注释似乎表明,SQLCHAR字段是地址的配额,是一个数字值,但该字段被定义为字符串而不是简单的整数(SQLINTEGER).而另一个字段是下载次数,并且已正确存储为整数(SQLINTEGER).

该数据库能够存储二进制值(SQLINTEGER),因此应该是存储这些数字的首选方式.这样,您不必在读取字段时执行从字符到整数"(_atoi())的转换,也不必在更新/写入字段时进行从整数到字符"(sprintf()/CString.Format())的转换. /blockquote>

使用strcmp函数进行比较

我的回答是完全错误的.

如果op期望 chvall 保存数字数据,则op可以使用atoi函数将数字的char数组转换为整数.


I have an if statement with two SQL types that I am comparing with each other
The statement....

if ((int*)rowCount3 >= (int*)chval1)



rowCount3 is an SQLINTEGER
chval1 is an SQLCHAR chval1[128]

I''m trying to force the cast so that I am comparing apples to apples. I imagine that they both have to be real comparable numbers. Any help appreciated, Thank you.

解决方案

The Big Hammer (tm) does not solve every problem. You cannot typecast your way to making things work. Typecasting only works if the datatypes are already compatible. SQLINTEGER and SQLCHAR are incompatible.

That said, if you have a string of arbitrary characters (SQLCHAR) that are stored in a database and you, in your mind, know that these characters are just numbers, you can apply the "_atoi()" function on the string to convert the characters found to their numeric interpretation.

Then you will have two compatible types and you can compare them mathematically.

On a side note, it seems that the database record is itself badly designed. Your comments above seem to say that the SQLCHAR field is the quota of addresses, a numeric value yet the field is defined as a character string instead of a simple intger (SQLINTEGER). While another field is the number of downloads and is stored properly as an integer (SQLINTEGER).

The database is capable of storing binary values (SQLINTEGER) so that should be the preferred way of storing these numbers. That way, you do not have to do "Character to Integer" (_atoi())conversions when reading the field nor "Integer to Character" (sprintf() / CString.Format()) conversions when updating / writing the field.


use strcmp function to compare

My answer is completely wrong.

if op expect chvall is holding numeric data then op can use atoi function to convert char array of number to integer.


这篇关于比较两种SQL类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆