[SOLVED]TlargeIntField set filter error lazarus / 16-Databases ---------------------------------------------------------------------- zhangshelly · 2025-02-04 14:43 var   Fdb:Tbufdataset; begin   Fdb:=Tbufdataset.Create(nil);   Fdb.FieldDefs.Add('prjid',ftlargeint);   Fdb.FieldDefs.Add('no',ftstring,10);   Fdb.CreateDataset;   Fdb.AppendRecord([3556856671915480078,'1']);   Fdb.AppendRecord([3556856671915480078,'2']);   Fdb.AppendRecord([3556856671915480017,'3']);   Fdb.Filter:='prjid=3556856671915480078';                    -- raise Exception   Fdb.Filtered:=True;  end; ---------------------------------------------------------------------- zhangshelly · 2025-02-04 14:58 var   Fdb:TmemDataset; begin   Fdb:=TmemDataset.Create(nil);   Fdb.FieldDefs.Add('prjid',ftlargeint);   Fdb.FieldDefs.Add('no',ftstring,10);   Fdb.CreateDataset;   Fdb.AppendRecord([3556856671915480078,'1']);   Fdb.AppendRecord([3556856671915480078,'2']);   Fdb.AppendRecord([3556856671915480017,'3']);   Fdb.Filter:='prjid=3556856671915480078';                    Fdb.Filtered:=True;                                           --no filter end; ---------------------------------------------------------------------- cdbc · 2025-02-04 15:24 Hi 'ftLargeInt' = int64; NOT QWord. That means, your integer is prolly too large! Regards Benny ---------------------------------------------------------------------- zhangshelly · 2025-02-04 15:28 it can save  3556856671915480078 as value and display right, only can't  filter the same code change to Tadodataset in delphi,the result is right ---------------------------------------------------------------------- zhangshelly · 2025-02-04 15:34 Quote from: zhangshelly on February 04, 2025, 04:28:32 pmit can save  3556856671915480078 as value and display right, only can't  filter the same code change to Tadodataset in delphi,the result is right uses  VirtualTable(unidac) can get right result   var   Fdb:TVirtualTable; begin   Fdb:=TVirtualTable.Create(nil);   Fdb.FieldDefs.Add('prjid',ftlargeint);   Fdb.FieldDefs.Add('no',ftstring,10);   Fdb.active:=True;   Fdb.AppendRecord([3556856671915480078,'1']);   Fdb.AppendRecord([3556856671915480078,'2']);   Fdb.AppendRecord([3556856671915480017,'3']);   Fdb.Filter:='prjid=3556856671915480078';   Fdb.Filtered:=True;   ds.DataSet:=fdb;  end; ---------------------------------------------------------------------- BrunoK · 2025-02-04 17:07 Probably a bug, see following program. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program a; {$mode objfpc}{$H+} uses  Classes,  SysUtils,  DB,  BufDataset; var  Fdb: Tbufdataset;begin  Fdb := Tbufdataset.Create(nil);  Fdb.FieldDefs.Add('prjid', ftlargeint);  Fdb.FieldDefs.Add('no', ftstring, 10);  Fdb.CreateDataset;  Fdb.AppendRecord([0, '0']);  Fdb.AppendRecord([High(Int64), '1']);  Fdb.AppendRecord([3556856671915480078, '2']); // ~bk is within range of ftLargeInt  Fdb.AppendRecord([3556856671915480017, '3']);  WriteLn('RecordCount=', Fdb.RecordCount, ' UNFILTERED');  with Fdb do begin    First;    while not EOF do begin      WriteLn(FieldByName('prjid').AsString, ' ', FieldByName('no').AsString: 4);      Next;    end;  end;  Fdb.Filter := 'prjid=3556856671915480078'; // 'prjid=0' -> works  WriteLn('Filtered with ''', Fdb.Filter, '''');  Fdb.Filtered := True;  with Fdb do begin    First;    while not EOF do begin      WriteLn(FieldByName('prjid').AsString, ' ', FieldByName('no').AsString: 4);      Next;    end;  end;   ReadLn;end. ---------------------------------------------------------------------- cdbc · 2025-02-04 18:02 Hi @BrunoK: I copy pasted your example and compiled it with trunk and ran it... Screenshot attached... Regards Benny ---------------------------------------------------------------------- BrunoK · 2025-02-04 18:22 Quote from: cdbc on February 04, 2025, 07:02:42 pmHi @BrunoK: I copy pasted your example and compiled it with trunk and ran it... Screenshot attached... Regards Benny Interesting, will take a look tomorrow. Me is fpc 3.2.2 but with more recent package db from trunk. ---------------------------------------------------------------------- zhangshelly · 2025-03-24 10:01 mey be error locate in   dbf_prscore.pas ---------------------------------------------------------------------- Zvoni · 2025-03-24 11:07 Acc. to the callstack (i can confirm TS' issue): the culprit is a Call to SysUtils.StrToInt in dbf_prscore TCustomExpressionParser.ParseString (line 968 in dbf_prscore for fpc3.2.2 on my installation). In TS' case we would need a Call to StrToInt64 instead At first glance i'd consider it a bug, which would need to be reported on bugtracker. EDIT: I don't have Trunk/Main. Could someone compare in Trunk/Main " dbf_prscore --> TCustomExpressionParser.ParseString"? Inside that Procedure there are 2 calls to StrToInt, but my money is on the second one (the first appearance of StrToint has to do with hexadecimal). EDIT2: Nother stumbling block inside ParseString is probably the whole line 968 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TempWord := TIntegerConstant.Create(StrToInt(W)); "TIntegerConstant" and in dbf_prsdef the Value is an "Integer". Notabene: in dbf_prsdef there is also a "TLargeIntConstant"...... ---------------------------------------------------------------------- BrunoK · 2025-03-24 11:38 I submitted a patch in issue : https://gitlab.com/freepascal.org/fpc/source/-/issues/41139 Maybe you might test it. ---------------------------------------------------------------------- Zvoni · 2025-03-24 12:13 Quote from: BrunoK on March 24, 2025, 12:38:38 pmI submitted a patch in issue : https://gitlab.com/freepascal.org/fpc/source/-/issues/41139 Maybe you might test it. Cannot test (Company-Laptop with restrictions), but just reading the patch, i'd say it looks very good. The only thing i don't like in your patch, are these 2 lines Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i +      false: Result := TIntegerConstant.Create(lInt64);......+    Result := TIntegerConstant.Create(StrToInt64(aIntStr));because you pass an Int64 to the "regular" TIntegerConstant, which has an Integer for its Constructor-Argument. I'd gone for a solution using the "correct" DataType and conversion (StrToInt) Something along the lines of (Aircode!!) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i +  function IntegerExprCreate(aIntStr: string): TExprWord;+  {$ifdef SUPPORT_INT64}+  var+    lInt32: Integer;+    lIsI64: boolean = False;+    lInt64: Int64;+  begin+    lInt64:= StrToInt64(aIntStr);+  lIsI64 := (lInt64High(Integer));+    case lIsI64 of+      false: Begin+               lInt32:=StrToInt(aIntStr);  //Could be coalesced into one line+               Result := TIntegerConstant.Create(lInt32);+             End;+      true:  Result := TLargeIntConstant.Create(lInt64);+    end;+  {$else}+  begin+    Result := TIntegerConstant.Create(StrToInt(aIntStr));+  {$endif}+  end;+ ---------------------------------------------------------------------- BrunoK · 2025-03-24 13:15 Quote from: Zvoni on March 24, 2025, 01:13:12 pmbecause you pass an Int64 to the "regular" TIntegerConstant, which has an Integer for its Constructor-Argument. I'd gone for a solution using the "correct" DataType and conversion (StrToInt) The compiler converts the Int64 to Int32 when calling create in its 32 bit version. Doing a lInt64 = StrToInt64(aIntStr); and then testing  if it is 32 bit or 64 bit seems Ok to me. ---------------------------------------------------------------------- Zvoni · 2025-03-24 13:32 Quote from: BrunoK on March 24, 2025, 02:15:40 pmQuote from: Zvoni on March 24, 2025, 01:13:12 pmbecause you pass an Int64 to the "regular" TIntegerConstant, which has an Integer for its Constructor-Argument. I'd gone for a solution using the "correct" DataType and conversion (StrToInt) The compiler converts the Int64 to Int32 when calling create in its 32 bit version. Doing a lInt64 = StrToInt64(aIntStr); and then testing  if it is 32 bit or 64 bit seems Ok to me. No worries. as i wrote i like your patch. It's just that i'm a proponent of "use the correct Datatype wherever possible. Don't rely on implicit conversion." ---------------------------------------------------------------------- BrunoK · 2025-03-24 13:48 What takes time is converting a string to an integer value. Redoing StrToInt to satisfy super correct DataType uselessly slows things. (Of course, not very significant). What I agree on is that Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i +  {$else}+  begin+    Result := TIntegerConstant.Create(StrToInt(aIntStr));+  {$endif}Should use StrToInt so an error gets raised early instead of counting on overflow checking of the conversion to the target parameter type.