开发环境
Delphi 7.0
MySQL 5.0
MySQL Connector ODBC 3.51开发时采用了
ADOConnection 通过ODBC连接MySQL数据库
ADOQuery 用来查询数据库中表record里有一列ipv4_src_addr是UNSIGNED UINTEGER类型 sSql := 'select distinct ipv4_src_addr as signed as ip from record ';
qryIP.SQL.Clear;
qryIP.SQL.Add(sSql);
qryIP.Open;在访问qryIP.FieldByName('IP')的值的时候,不论我用.ASInteger,.AsVariant,还是.Value
都会报错
"Project ***** raised Exception class EVariantOverFlowError with Message 'Overflow while converting variant of type (LongWord) into Type (Integer)'"
Delphi 7.0
MySQL 5.0
MySQL Connector ODBC 3.51开发时采用了
ADOConnection 通过ODBC连接MySQL数据库
ADOQuery 用来查询数据库中表record里有一列ipv4_src_addr是UNSIGNED UINTEGER类型 sSql := 'select distinct ipv4_src_addr as signed as ip from record ';
qryIP.SQL.Clear;
qryIP.SQL.Add(sSql);
qryIP.Open;在访问qryIP.FieldByName('IP')的值的时候,不论我用.ASInteger,.AsVariant,还是.Value
都会报错
"Project ***** raised Exception class EVariantOverFlowError with Message 'Overflow while converting variant of type (LongWord) into Type (Integer)'"
--------------------
从来没有用过这个语法,楼主可以解释一下什么意思吗?还有,UNSIGNED UINTEGER类型是什么类型?我只记得int ,big int,没见过UINTEGER。
<===〉
UNSIGNED INT
qryIP.SQL.Clear;
qryIP.SQL.Add(sSql);
qryIP.Open; 而且错误的情况是在数字很大的情况下出现的
也就是说,在从32位无符号数,转成32位有符号数的情况下,出现了溢出但是为什么我用qryIP.FieldByName('IP').AsVariant 或者 qryIP.FieldByName('IP').Value 的时候也会报错呢?
两者都返回Variant类型啊。
为什么没有返回正确的类型呢
如果值比较大 例如
3741039308那么不论是qryIP.FieldByName('IP').AsVariant,qryIP.FieldByName('IP').Value,qryIP.FieldByName('IP').AsInteger都会发生溢出
var
a:Cardinal;
begin
with ADOQuery1 do
begin
Close;
SQL.Text := 'SET NAMES GB2312;';
ADOQuery1.ExecSQL();
SQL.Clear;
SQL.Add('select text as IP from a');
Open;
a:=ADOQuery1.fieldbyname('IP').AsInteger;
label3.Caption:=inttostr(a);
end;
end;我的表改成了这样了,上面的代码也没有出错。
ALTER TABLE `a` CHANGE `text` `text` INT( 4 ) UNSIGNED NOT NULL而且mysql数据库里,不管是int(10)还是int(4)最大也只能有2147483647,无符号可以有这个数的两倍,不会因为改了是10还是4就会增加范围的。
真的没办法了在数据库中用varchar存吧,拿出来后再转回来。
XFliangwh你的ConnectString是怎么写的?
ADOConnection1.ConnectionString:= 'Provider=MSDASQL.1;Persist Security Info=False;;User ID=root;Password=ababc;DATABASE=mytest;DRIVER={MySQL ODBC 3.51 Driver};OPTION=0;PORT=0;SERVER=localhost;';
http://www.ccrun.com/view.asp?id=446