Recent

Author Topic: IBX 2.7.2, What's wrong with my codes?  (Read 3233 times)

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: Lazarus 4, What's wrong with my codes?
« Reply #45 on: June 19, 2025, 02:10:42 pm »
What about your, could you share your version of ibx, ibcontrol and fbintf so I can download these files from github. Have trouble also to get the old IBX to work.
I just used the latest OPM version.
On a new Lazarus 4 install on Windows 64bit.

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #46 on: June 19, 2025, 03:38:23 pm »
What about your, could you share your version of ibx, ibcontrol and fbintf so I can download these files from github. Have trouble also to get the old IBX to work.
I just used the latest OPM version.
On a new Lazarus 4 install on Windows 64bit.
Installed many time in VM with Lazarus 2.2.2 and 4 and firebird 3, none works for me.

Tried using IBConnection from Lazarus 2.2.2 and it worked OK!

My guess is, this is caused by nrw version of IBX.

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: Lazarus 4, What's wrong with my codes?
« Reply #47 on: June 20, 2025, 01:46:25 am »
Finally, I was able to get back to old Lazarus 2.2.2 and old ver of IBX and test this code.

With Firebird 3 and IBX 2.5, it worked just expected.
I suspect it will also work in Lazarus 4.

It is confirmed that IBX 2.7.2, won't work, may be it is a bug?



egsuh

  • Hero Member
  • *****
  • Posts: 1623
Re: [SOLVED] Lazarus 4, What's wrong with my codes?
« Reply #48 on: June 20, 2025, 07:54:13 am »
I remember Firebird 4? 5? was not processed properly in my application (the same issue you have experienced), which used to have no problem with Firebird 3. I have posted the issue here --- recalled now.

https://forum.lazarus.freepascal.org/index.php/topic,61144.msg459164.html#msg459164

As it was a development program, I kept using Firebird 3 in my main application (practically the same one as development program).

Later I upgraded to Lazarus 4 and Firebird 5 and have no problem in running the development program now. 

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: [SOLVED] Lazarus 4, What's wrong with my codes?
« Reply #49 on: June 20, 2025, 08:25:46 am »
I have tried it with Lazarus 4 with Firebird 5.02, with IBX 2.5 - OK, IBX->2.7.2, problem

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: [SOLVED] Lazarus 4, What's wrong with my codes?
« Reply #50 on: June 20, 2025, 08:35:41 am »
Are you still using the same database?
I already asked if you could share it?

If not create a new database with that take, check it and if problem persist, share it here.

The problem was also with Firebird 3 and 4 with latest IBX?

I'm trying to see if we can recreate this.
As long as we can't recreate it, is almost impossible to find the bug

I'll try again later this morning but having a database where this problem occurs could be useful.

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: [SOLVED] Lazarus 4, What's wrong with my codes?
« Reply #51 on: June 20, 2025, 08:55:27 am »
Are you still using the same database?
I already asked if you could share it?

If not create a new database with that take, check it and if problem persist, share it here.

The problem was also with Firebird 3 and 4 with latest IBX?

I'm trying to see if we can recreate this.
As long as we can't recreate it, is almost impossible to find the bug

I'll try again later this morning but having a database where this problem occurs could be useful.
Real project use firebird 5, test project use firebird 3.

IBX 2.5 works OK with FB3 and FB5, IBX 2.7.2 was not.

Attached is test dba with FB3.

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: [SOLVED] Lazarus 4, What's wrong with my codes?
« Reply #52 on: June 20, 2025, 10:34:58 am »
I can FINALLY confirm the problem.

But... I think the problem may be in the 32 bit.

When trying on Windows 64 bit with 64 bit Lazarus it gave me no problems.

In a VM Windows 10 32 bit with 32 bit Lazarus I could confirm this problem.

I would nee to dive in deeper to find the exact problem but maybe it's time to call in the expert  :D

Any ideas @tonyw ?


incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: [SOLVED] Lazarus 4, What's wrong with my codes?
« Reply #53 on: June 20, 2025, 11:06:01 am »
I can FINALLY confirm the problem.

But... I think the problem may be in the 32 bit.

When trying on Windows 64 bit with 64 bit Lazarus it gave me no problems.

In a VM Windows 10 32 bit with 32 bit Lazarus I could confirm this problem.

I would nee to dive in deeper to find the exact problem but maybe it's time to call in the expert  :D

Any ideas @tonyw ?
I have to admire you to go such length to find out the problem 👍

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: [SOLVED] Lazarus 4, What's wrong with my codes?
« Reply #54 on: June 20, 2025, 11:37:31 am »
I have to admire you to go such length to find out the problem 👍
Yeah, those bugs really irk me.

I even wonder if it's really a IBX problem. But it does only happen when using Firebird 3 or higher.
(Maybe a big memory overwrite in IBX ?)

The variable seems to contain the correct value, it's just that with showmessage and concatenation, it doesn't show.

Code: Pascal  [Select][+][-]
  1.   while not(Q.EOF) do
  2.   begin
  3.     S1 := Q.FieldByName('s1').AsString;
  4.     ShowMessage(S1);
  5.     ShowMessage('Header : ' + S1);
  6.     Q.Next;
  7.   end;

On line 5 S1 stills contains the correct value but doesn't show.
That does indicate the problem is not in AsString from IBX.
But if I hardcode a string on line 3 then it works fine.

Really weird.




rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: IBX 2.7.2, What's wrong with my codes?
« Reply #55 on: June 20, 2025, 11:43:57 am »
Now I can also reproduce in Lazarus 4 64 bit.
The problem was that I tried it with Firebird 5 on a Linux server and there is works fine.

I now have Firebird 3 64 bit in a Sandbox and use Lazarus 4 64 bit on the host and the same problem.

When entering the Showmessage, the aMsg parameter is missing the content of the concatenated variable.
(But only happens when using that FieldByName)

When S2 is a String it craps out. When it's a ShortString it works fine.

Code: Pascal  [Select][+][-]
  1.     S1 := Q.FieldByName('s1').AsString;
  2.     ShowMessage(S1);
  3.     S2 := 'Header1 : ' + S1;
  4.     ShowMessage(S2);

And using this... only shows 3 (length of S1).
Code: Pascal  [Select][+][-]
  1.     S1 := Q.FieldByName('s1').AsString;
  2.     ShowMessage(S1 + length(S1).ToString);
« Last Edit: June 20, 2025, 11:47:59 am by rvk »

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: IBX 2.7.2, What's wrong with my codes?
« Reply #56 on: June 20, 2025, 12:21:13 pm »
This doesn't even work:
Code: Pascal  [Select][+][-]
  1.     S2 := Q.FieldByName('s1').AsString;
  2.     S1 := Copy(S2,2);
  3.     ShowMessage(S1 + ' ' + length(s1).ToString);
  4.     S2 := 'Header1 : ' + S1;
  5.     ShowMessage(S2);
S2 contains the content "One".
I thought I would copy the string to a new string (by using Copy but making sure a new copy was made).
S1 contains "ne".

But still the Showmessages fail when concatenating.

I'm kinda out of ideas.

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: IBX 2.7.2, What's wrong with my codes?
« Reply #57 on: June 20, 2025, 01:26:23 pm »
Just relax.
The problem is only there when filling a string with Fieldbyname.asString from IBX.
Even slqdb works fine.

So there is a memory problem in combination with IBX 2.7.2.

rvk

  • Hero Member
  • *****
  • Posts: 6802
Re: IBX 2.7.2, What's wrong with my codes?
« Reply #58 on: June 20, 2025, 03:30:12 pm »
@incendio, I think I figured it out (partly).

Because when I created a table in my own existing database, there was no problem.
When creating a new database with Lazarus/IBX, even with Firebird 2.5, it began having the problem.

I found out the CHARACTER SET of the database is the problem. If set to NONE, this problem occurs.

Here is a DDL of a problem database.
Code: SQL  [Select][+][-]
  1. SET SQL DIALECT 3;
  2.  
  3. /* CREATE DATABASE '127.0.0.1:C:\Temp\TTT.FDB' PAGE_SIZE 4096 DEFAULT CHARACTER SET NONE */
  4.  
  5. /* Table: TBL, Owner: SYSDBA */
  6. CREATE TABLE TBL (ID BIGINT NOT NULL,
  7.         S1 VARCHAR(32),
  8. PRIMARY KEY (ID));

Same database without a problem:
Code: SQL  [Select][+][-]
  1. SET SQL DIALECT 3;
  2.  
  3. /* CREATE DATABASE '127.0.0.1:C:\Temp\TTT2.FDB' PAGE_SIZE 4096 DEFAULT CHARACTER SET ISO8859_1 */
  4.  
  5. /* Table: TBL, Owner: SYSDBA */
  6. CREATE TABLE TBL (ID BIGINT NOT NULL,
  7.         S1 VARCHAR(32),
  8. PRIMARY KEY (ID));

(You can get the DDL with: isql -ex -u sysdba -p masterkey 127.0.0.1:C:\Temp\TTT.FDB )

Try to recreate your database with (or change) the CHARACTER SET ISO8859_1, and see if you still have the problem.

Now... it still remains a question for @tonyw why a database with CHARACTER SET NONE will exibit this behavior, but at least we are a step closer.

Simple console app to select the data (and create the database if not found). Note, if run inside the IDE you need to click CONTINUE on the exception, to let it create the database (or you need to disable debugging or run outside the IDE).

Project > New Project > Simple project.
Ctrl + A (to select all) and paste in code below.
Project > Project Inspector and add ibnongui
(nothing else is required)

Code: Pascal  [Select][+][-]
  1. program simple_fb;
  2.  
  3. uses DB, IBDatabase, IBQuery, IB;
  4.  
  5. procedure foo;
  6. const
  7.   Db = '127.0.0.1:C:\TEMP\TTT2.FDB';
  8.   Fld = 'S1';
  9.   Sql = 'SELECT S1 FROM TBL';
  10. var
  11.   IB: TIBDatabase;
  12.   IbSql: TIBQuery;
  13.  
  14.   procedure Exec(Str: String);
  15.   begin
  16.     IbSql.SQL.Text := Str;
  17.     IB.DefaultTransaction.Active := true;
  18.     IbSql.ExecSQL;
  19.     if IB.DefaultTransaction.Active then IB.DefaultTransaction.Commit;
  20.   end;
  21.  
  22. begin
  23.   IB := TIBDatabase.Create(nil);
  24.   IbSql := TIBQuery.Create(nil);
  25.   try
  26.     IB.DatabaseName := DB;
  27.     IB.DefaultTransaction := TIBTransaction.Create(IB);
  28.     IB.DefaultTransaction.DefaultDatabase := IB;
  29.     IB.LoginPrompt := false;
  30.     IbSql.Database := IB;
  31.     try
  32.  
  33.       IB.Params.Clear;
  34.       IB.Params.Values['user_name'] := 'SYSDBA';
  35.       IB.Params.Values['password'] := 'masterkey';
  36.       IB.Params.Values['lc_ctype'] := 'NONE';
  37.       IB.Connected := True;
  38.  
  39.     except
  40.       on E: EDatabaseError do
  41.       begin
  42.         if (E is EIBInterBaseError) and (EIBInterBaseError(E).IBErrorCode = 335544344) then
  43.         begin
  44.           IB.Params.Clear;
  45.           IB.Params.Add('USER ''SYSDBA''');
  46.           IB.Params.Add('PASSWORD ''masterkey''');
  47.           IB.Params.Add('PAGE_SIZE 4096');
  48.           IB.Params.Add('DEFAULT CHARACTER SET ISO8859_1');
  49.           IB.Params.Values['user_name'] := 'SYSDBA';
  50.           IB.Params.Values['password'] := 'masterkey';
  51.           IB.Params.Values['lc_ctype'] := 'ISO8859_1';
  52.           IB.SQLDialect := 3;
  53.           IB.CreateDatabase;
  54.           IB.Connected := false;
  55.  
  56.           IB.Params.Clear;
  57.           IB.Params.Values['user_name'] := 'SYSDBA';
  58.           IB.Params.Values['password'] := 'masterkey';
  59.           IB.Params.Values['lc_ctype'] := 'ISO8859_1';
  60.           IB.Connected := True;
  61.  
  62.           Exec('CREATE TABLE TBL (ID BIGINT PRIMARY KEY, S1 VARCHAR(32) );');
  63.           Exec('INSERT INTO TBL VALUES (1, ''One'');');
  64.           Exec('INSERT INTO TBL VALUES (2, ''Two'');');
  65.           Exec('INSERT INTO TBL VALUES (3, ''Three'');');
  66.           Exec('INSERT INTO TBL VALUES (4, ''Four'');');
  67.         end;
  68.       end;
  69.     end;
  70.  
  71.     IB.DefaultTransaction.Active := true;
  72.     IbSql.SQL.Text := SQL;
  73.     IbSql.Open;
  74.     while not IbSql.EOF do
  75.     begin
  76.       writeln(IbSql.FieldByName(Fld).AsString);
  77.       writeln('Test: ' + IbSql.FieldByName(Fld).AsString);
  78.       writeln;
  79.       IbSql.Next;
  80.     end;
  81.     IbSql.Close;
  82.  
  83.   finally
  84.     IbSql.Free;
  85.     IB.Free;
  86.   end;
  87.  
  88. end;
  89.  
  90. begin
  91.   foo;
  92.   ReadLn;
  93. end.
  94.  

When using DEFAULT CHARACTER SET NONE in above code... the problem creeps up again.

incendio

  • Sr. Member
  • ****
  • Posts: 358
Re: IBX 2.7.2, What's wrong with my codes?
« Reply #59 on: June 20, 2025, 04:21:15 pm »
Wow, congratulation, you found the solution 👍

I never touch character set. Is it safe to change character set for an active database?

Used IBX for active database, not just for testing.
Will be a disaster if there are problems by changing its character set.

Btw, now for real use, I am back to Lazarus 2.2.2 and IBX 2.5.

Using Lazarus 4 in VM, but it also used IBX 2.5.

Will try again on VM to create database with character set other than none.

Thanks again for your efforts, appreciate it.

 

TinyPortal © 2005-2018