Recent

Author Topic: [mORMot] Database connection error with ZEOS  (Read 2859 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 1113
[mORMot] Database connection error with ZEOS
« on: January 11, 2016, 09:14:40 am »


My real goal is to connect a databaseserver and get data remotely.
My own first example is working (both Delphi/Lazarus). I created a SQLite database and put some data in it.

My own second example connects to a database server (MariaDB 5.5). I looked in the manual and took the code from chapter 8.1  (Lazarus 1.6Rc1/ FPC 3.0):

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   SynCommons,  mORMot, mORMotSQLite3, SynSQLite3Static,
  10.   mORMotDB,  synDB,  
  11.   SynDBZeos, // needed for Zeos
  12.   ZDbcMySql; // needed for Zeos
  13.  
  14. type
  15.  
  16.   { TForm1 }
  17.  
  18.   TForm1 = class(TForm)
  19.     Button1: TButton;
  20.     Memo1: TMemo;
  21.     procedure Button1Click(Sender: TObject);
  22.   private
  23.     procedure UseProps(Props: TSQLDBConnectionProperties);
  24.     { private declarations }
  25.   public
  26.     { public declarations }
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36. { TForm1 }
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. var Props: TSQLDBConnectionProperties;
  40.     Server : string;
  41. begin
  42.   Server := 'zdbc:mysql://192.168.x.x:3306/test?username=xxx;password=xxx';
  43.   Props := TSQLDBZEOSConnectionProperties.Create(Server,'test','','');
  44.   try
  45.     UseProps(Props);
  46.   finally
  47.     Props.Free;
  48.   end;
  49. end;
  50.  
  51. procedure TForm1.UseProps(Props: TSQLDBConnectionProperties);
  52. var I: ISQLDBRows;
  53. begin
  54.   I := Props.Execute('select * from gebruikers where id = ?',['1']);
  55.   showmessage(I.Column['login']);
  56. end;
  57.  
  58. end.
  59.  
  60.  
Examples compiles without problem, but when I want to get data from the database, I get this error:
Quote
    Project voorbeeld2 raised exception class 'External: SIGSEGV'.

    In file 'C:\lazarus16RC1\components\zeoslib714\src\plain\ZPlainMySqlDriver.pas' at line 1240:
    Result := PMYSQL_ROW(ROW)[Offset];
It looks the database will not be connected. Is my code wrong or do I have to do something else?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

 

TinyPortal © 2005-2018