Recent

Author Topic: Firebird 2.5 TIBConnection TSQLTransaction and Error Operator is not overloaded  (Read 6662 times)

rc.1990

  • Jr. Member
  • **
  • Posts: 54
I am using Windows 7 64 bit, Firebird 2.5.6 64 bit server, Lazarus 1.6.0 32 bit, FPC 3.0.0 32 bit.
fbclient.dll (Firebird 2.5.6 32 bit) and test.fdb are on the the same folder of project1.exe.

Connection to local database file is tested and working correctly.

Why does line 32 "SQLTransaction1 := TSQLTransaction.Create(nil);" shows error "project1.lpr(32,19) Error: Operator is not overloaded: - 'TSQLTransaction' "?

----------------------------
Compile Project, Target: project1.exe: Exit code 1, Errors: 6, Warnings: 2
project1.lpr(32,3) Warning: Variable "SQLTransaction1" does not seem to be initialized
project1.lpr(32,19) Error: Operator is not overloaded: - "TSQLTransaction"
project1.lpr(48,3) Warning: Variable "SQLQuery1" does not seem to be initialized
project1.lpr(48,13) Error: Operator is not overloaded: - "TSQLQuery"
project1.lpr(63,18) Error: Incompatible types: got "untyped" expected "LongInt"
project1.lpr(63,25) Error: Illegal expression
project1.lpr(67,16) Error: Incompatible types: got "untyped" expected "LongInt"
project1.lpr(67,21) Error: Illegal expression
----------------------------


Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}
  4.  
  5. uses
  6.   Classes, SysUtils, IBConnection, sqldb;
  7.  
  8. var
  9.   IBConnection1: TIBConnection;
  10.   SQLTransaction1: TSQLTransaction;
  11.   SQLQuery1: TSQLQuery;
  12.  
  13. begin
  14.   IBConnection1 := TIBConnection.Create(nil);
  15.   IBConnection1.HostName := 'localhost';
  16.   IBConnection1.DatabaseName := 'test.fdb';
  17.   IBConnection1.UserName := 'SYSDBA';
  18.   IBConnection1.Password := 'masterkey';
  19.   // IBConnection1.CharSet := 'UTF8';
  20.   IBConnection1.CharSet := 'ISO8859_1';
  21.   IBConnection1.Dialect := 3;
  22.   IBConnection1.Params.Add('port=3050');
  23.   IBConnection1.LoginPrompt := False;
  24.   IBConnection1.Connected := True;
  25.  
  26.   if IBConnection1.Connected then
  27.     WriteLn('Connected.')
  28.   else
  29.     WriteLn('Not connected.');
  30.  
  31.   ----------------------------
  32.   SQLTransaction1 :=  TSQLTransaction.Create(nil);
  33.   // SQLTransaction1.Params.Add('read_committed');;
  34.   // SQLTransaction1.Params.Add('rec_version');;
  35.   // SQLTransaction1.Params.Add('nowait');;
  36.   SQLTransaction1.Database := IBConnection1;
  37.   SQLTransaction1.Params.Add('isc_tpb_read_committed');;
  38.   SQLTransaction1.Params.Add('isc_tpb_rec_version ');;
  39.   SQLTransaction1.Params.Add('isc_tpb_nowait');;
  40.   SQLTransaction1.StartTransaction;
  41.  
  42.   if SQLTransaction1.Active then
  43.     WriteLn('Transaction started.')
  44.   else
  45.     WriteLn('Transaction not started.');
  46.  
  47.   ------------
  48.   SQLQuery1 := TSQLQuery.Create(nil);
  49.   SQLQuery1.Database := IBConnection1;
  50.   SQLQuery1.Transaction := SQLTransaction1;
  51.   SQLQuery1.SQL.Text := 'Select ID, Name From People;';
  52.   SQLQuery1.Open;
  53.   while not SQLQuery1.Eof do
  54.   begin
  55.     WriteLn('ID: ', SQLQuery1.FieldByName('ID').AsInteger,
  56.             'Name: ' + SQLQuery1.FieldByName('Name').AsString);
  57.     SQLQuery1.Next;
  58.   end;
  59.   SQLQuery1.Close;
  60.   SQLQuery1.Free;
  61.   ------------
  62.  
  63.   SQLTransaction1.Commit;
  64.   SQLTransaction1.Free;
  65.   ----------------------------
  66.  
  67.   IBConnection1.Free;
  68. end.
  69.  

wp

  • Hero Member
  • *****
  • Posts: 11858
What if you comment the dividing lines?
Code: Pascal  [Select][+][-]
  1. ....
  2.   if IBConnection1.Connected then
  3.     WriteLn('Connected.')
  4.   else
  5.     WriteLn('Not connected.');
  6.  
  7.   //----------------------------                         <-- add comment slashes here
  8.   SQLTransaction1 :=  TSQLTransaction.Create(nil);
  9. ....

rc.1990

  • Jr. Member
  • **
  • Posts: 54
Thanks wp.
I have removed them all and now the program is working.

Now I have a small problem on character encoding (code page or UTF) in WriteLn on command line (CMD) of Windows 7.

The Firebird database is encoded as ISO8859_1 not UTF8 and its information is showed correctly.

The database information is correct: "Teste Soluções", but the WriteLn information is wrong: "ID/C├│digo: 1   Name/Razão Social:". It should be "ID/Código: 1  Name/Razão Social:".
------------------
Microsoft Windows [versão 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Todos os direitos reservados.


C:\test>project1.exe
Connected.
Transaction started.
ID/C├│digo: 1       Name/Razão Social: Teste Soluções

C:\test>
------------------

wp

  • Hero Member
  • *****
  • Posts: 11858
Use the conversion routines in lconvencoding and lazutf8:

- ISO_8859_1ToUtf8() for conversion from IS8869-1 to UTF8
- UTF8ToConsole() for conversion from UTF8 to codepage used by console

Code: Pascal  [Select][+][-]
  1.  WriteLn('ID: ', SQLQuery1.FieldByName('ID').AsInteger,
  2.          'Name: ' + UTF8ToConsole(ISO_8859_1ToUTF8(SQLQuery1.FieldByName('Name').AsString)));

rc.1990

  • Jr. Member
  • **
  • Posts: 54
Thanks wp.

I can't use UTF8ToConsole() and ISO_8859_1ToUTF8(). It seems that I missing something in the USES clause, but I don't know which unit is still missing.

-------------
Compile Project, Target: project1.exe: Exit code 1, Errors: 1
project1.lpr(7,3) Fatal: Cannot find LazUtils used by project1. Check if package LazUtils is in the dependencies of the Project Inspector.
-------------


Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}
  4. {$apptype console}
  5.  
  6. uses
  7.   LazUtils, LazUTF8, LConvEncoding, Classes, SysUtils, IBConnection, sqldb;
  8.  

wp

  • Hero Member
  • *****
  • Posts: 11858
Read the error message: "Check if package LazUtils is in the dependencies of the Project Inspector" - this means: open the project inspector. The package "LazUtils" should be mentioned in the tree underneath "Required packages". If it is not right-click on "Required packages", "Add...", and select "LazUtils" from the list.

And remove "LazUtils" from the uses list - this is a package (a collection of units), not a unit.
« Last Edit: September 24, 2016, 03:39:13 pm by wp »

rc.1990

  • Jr. Member
  • **
  • Posts: 54
Thanks wp.
Now, everything is working perfectly.

I am releasing the final version here just in case it might help anyone else. I am also attaching the final images of the Project Inspector.

file: project1.lpr:
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}
  4. {$apptype console}
  5.  
  6. uses
  7.   LazUtils, LazUTF8, LConvEncoding, Classes, SysUtils, IBConnection, sqldb;
  8.  
  9. var
  10.   IBConnection1: TIBConnection;
  11.   SQLTransaction1: TSQLTransaction;
  12.   SQLQuery1: TSQLQuery;
  13. begin
  14.   IBConnection1 := TIBConnection.Create(nil);
  15.   IBConnection1.HostName := 'localhost';
  16.   IBConnection1.DatabaseName := 'test.fdb';
  17.   IBConnection1.UserName := 'SYSDBA';
  18.   IBConnection1.Password := 'masterkey';
  19.   // IBConnection1.CharSet := 'UTF8';
  20.   IBConnection1.CharSet := 'ISO8859_1';
  21.   IBConnection1.Dialect := 3;
  22.   IBConnection1.Params.Add('port=3050');
  23.   IBConnection1.LoginPrompt := False;
  24.   IBConnection1.Connected := True;
  25.  
  26.   if IBConnection1.Connected then
  27.     WriteLn('Connected.')
  28.   else
  29.     WriteLn('Not connected.');
  30.  
  31.   SQLTransaction1 :=  TSQLTransaction.Create(nil);
  32.   // SQLTransaction1.Params.Add('read_committed');;
  33.   // SQLTransaction1.Params.Add('rec_version');;
  34.   // SQLTransaction1.Params.Add('nowait');;
  35.   SQLTransaction1.Database := IBConnection1;
  36.   SQLTransaction1.Params.Add('isc_tpb_read_committed');;
  37.   SQLTransaction1.Params.Add('isc_tpb_rec_version ');;
  38.   SQLTransaction1.Params.Add('isc_tpb_nowait');;
  39.   SQLTransaction1.StartTransaction;
  40.  
  41.   if SQLTransaction1.Active then
  42.     WriteLn('Transaction started.')
  43.   else
  44.     WriteLn('Transaction not started.');
  45.  
  46.   SQLQuery1 := TSQLQuery.Create(nil);
  47.   SQLQuery1.Database := IBConnection1;
  48.   SQLQuery1.Transaction := SQLTransaction1;
  49.   SQLQuery1.SQL.Text := 'Select ID, Name From People;';
  50.   SQLQuery1.Open;
  51.   while not SQLQuery1.Eof do
  52.   begin
  53.     WriteLn(UTF8ToConsole('ID/Código: '), SQLQuery1.FieldByName('ID').AsInteger, '   ',
  54.             UTF8ToConsole('Name/Razão Social: ') + ISO_8859_1ToUTF8(SQLQuery1.FieldByName('Name').AsString));
  55.     SQLQuery1.Next;
  56.   end;
  57.   SQLQuery1.Close;
  58.   SQLQuery1.Free;
  59.  
  60.   SQLTransaction1.Commit;
  61.   SQLTransaction1.Free;
  62.  
  63.   IBConnection1.Connected := False;
  64.   IBConnection1.Free;
  65. end.
  66.  

file: project1.lpi:
Code: XML  [Select][+][-]
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <CONFIG>
  3.   <ProjectOptions>
  4.     <Version Value="9"/>
  5.     <PathDelim Value="\"/>
  6.     <General>
  7.       <Flags>
  8.         <MainUnitHasCreateFormStatements Value="False"/>
  9.         <MainUnitHasTitleStatement Value="False"/>
  10.       </Flags>
  11.       <SessionStorage Value="InProjectDir"/>
  12.       <MainUnit Value="0"/>
  13.       <Title Value="project1"/>
  14.       <UseAppBundle Value="False"/>
  15.       <ResourceType Value="res"/>
  16.     </General>
  17.     <i18n>
  18.       <EnableI18N LFM="False"/>
  19.     </i18n>
  20.     <VersionInfo>
  21.       <StringTable ProductVersion=""/>
  22.     </VersionInfo>
  23.     <BuildModes Count="1">
  24.       <Item1 Name="Default" Default="True"/>
  25.     </BuildModes>
  26.     <PublishOptions>
  27.       <Version Value="2"/>
  28.     </PublishOptions>
  29.     <RunParams>
  30.       <local>
  31.         <FormatVersion Value="1"/>
  32.       </local>
  33.     </RunParams>
  34.     <RequiredPackages Count="1">
  35.       <Item1>
  36.         <PackageName Value="LazUtils"/>
  37.       </Item1>
  38.     </RequiredPackages>
  39.     <Units Count="1">
  40.       <Unit0>
  41.         <Filename Value="project1.lpr"/>
  42.         <IsPartOfProject Value="True"/>
  43.       </Unit0>
  44.     </Units>
  45.   </ProjectOptions>
  46.   <CompilerOptions>
  47.     <Version Value="11"/>
  48.     <PathDelim Value="\"/>
  49.     <Target>
  50.       <Filename Value="project1"/>
  51.     </Target>
  52.     <SearchPaths>
  53.       <IncludeFiles Value="$(ProjOutDir)"/>
  54.       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
  55.     </SearchPaths>
  56.   </CompilerOptions>
  57.   <Debugging>
  58.     <Exceptions Count="3">
  59.       <Item1>
  60.         <Name Value="EAbort"/>
  61.       </Item1>
  62.       <Item2>
  63.         <Name Value="ECodetoolError"/>
  64.       </Item2>
  65.       <Item3>
  66.         <Name Value="EFOpenError"/>
  67.       </Item3>
  68.     </Exceptions>
  69.   </Debugging>
  70. </CONFIG>
  71.  

 

TinyPortal © 2005-2018