[SOLVED] LAMW - App crash with TMySQL57ConnectionBridge lazarus / 43-Android ---------------------------------------------------------------------- Alcatiz · 2024-05-12 08:27 Hi all! I'm trying to make a simple app to handle a MySQL/MariaDB database stored on my local network. The app can connect to the database but as soon as I try to activate the SQLTransaction the app crashes: 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 procedure TAndroidModule1.Button1Click(Sender: TObject);begin  MySQL57ConnectionBridge1.HostName := '192.168.1.40';  MySQL57ConnectionBridge1.Port := 3306;  MySQL57ConnectionBridge1.DatabaseName := 'xxx';  MySQL57ConnectionBridge1.UserName := 'xxx';  MySQL57ConnectionBridge1.Password := 'xxx';  if MySQL57ConnectionBridge1.Connect     then       begin         EditText1.AppendLn('Connected!');         if MySQL57ConnectionBridge1.SQLTransaction.Active            then            EditText1.AppendLn('Transaction is active!')            else            EditText1.AppendLn('Transaction is NOT active...');         // MySQL57ConnectionBridge1.SQLTransaction.Active := True;   (* CRASH *)       end     else       EditText1.AppendLn('Error...');end; When the last line is commented, the app returns "Connected!" and "Transaction is NOT active...", so it seems the SQLTransaction is correctly allocated. If I replace the TMySQL57ConnectionBridge component with SQLDB components (TMySQL57Connection, TSQLTransaction and TSQLQuery) the app also crashes. The same app compiled on Linux on another PC connected to the local network doesn't encounter any problem. Connection to the database on my smartphone with any MySQL client is successfull. So any ideas? Thx! ---------------------------------------------------------------------- biologic · 2024-05-12 18:17 Hi. Maybe you should put a begin-end statement around your instructions. Just a guess. Code: [Select]if MySQL57ConnectionBridge1.Connect      then        begin          EditText1.AppendLn('Connected!');          if MySQL57ConnectionBridge1.SQLTransaction.Active             then               EditText1.AppendLn('Transaction is active!')             else               begin                    EditText1.AppendLn('Transaction is NOT active...');                    MySQL57ConnectionBridge1.SQLTransaction.Active := True;   (* CRASH *)                end        end      else        EditText1.AppendLn('Error...'); ---------------------------------------------------------------------- jmpessoa · 2024-05-16 01:45 Hi, Alcatiz! TMySQL57ConnectionBridge  fail to connect.....  but I can't fix it. Can you help? ---------------------------------------------------------------------- Alcatiz · 2024-05-20 08:22 Just with tiny changes in the constructor and without allocating any transaction in the Connect() method, I could execute some queries on my database.  Here's my component version (I added error codes but they are certainly useless): 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 unit MySQLAndroidConnection; {$mode delphi} interface uses  Classes, SysUtils, LResources,  SQLDB, DB, MySQL57Conn; type   { TMySQL57ConnectionBridgeError }   TMySQL57ConnectionBridgeError = (err_NoError, err_CreateSQLConnection, err_CreateSQLTransaction, err_CreateSQLQuery);   { TMySQL57ConnectionBridge }   TMySQL57ConnectionBridge = class(TComponent)  private    FDataBaseName: String;    FHostName: String;    FPort: Integer;    FPassword: String;    FUserName: String;    FError: TMySQL57ConnectionBridgeError;    procedure SetDataBaseName(AValue: String);    procedure SetHostName(AValue: String);    procedure SetPassword(AValue: String);    procedure SetPort(AValue: Integer);  procedure SetUserName(AValue: String);  public    MySQL57Connection: TMySQL57Connection;    SQLQuery: TSQLQuery;    SQLTransaction: TSQLTransaction;    constructor Create(AOwner: TComponent); override;    destructor Destroy; override;    function Connect: Boolean;  published    property DataBaseName: String read FDataBaseName write SetDataBaseName;    property HostName: String read FHostName write SetHostName;    property Port: Integer read FPort write SetPort;    property Password: String read FPassword write SetPassword;    property UserName: String read FUserName write SetUserName;    property Error: TMySQL57ConnectionBridgeError read FError;  end; procedure Register; implementation procedure Register;begin  {$I mysqlandroidconnection_icon.lrs}  RegisterComponents('FCL Bridges', [TMySQL57ConnectionBridge]);end; { TMySQL57ConnectionBridge } procedure TMySQL57ConnectionBridge.SetDataBaseName(AValue: String);begin  if FDataBaseName = AValue then Exit;  FDataBaseName := AValue;end; procedure TMySQL57ConnectionBridge.SetHostName(AValue: String);begin  if FHostName = AValue then Exit;  FHostName := AValue;end; procedure TMySQL57ConnectionBridge.SetPassword(AValue: String);begin  if FPassword = AValue then Exit;  FPassword := AValue;end; procedure TMySQL57ConnectionBridge.SetPort(AValue: Integer);begin  if FPort = AValue then Exit;  FPort := AValue;end; procedure TMySQL57ConnectionBridge.SetUserName(AValue: String);begin  if FUserName = AValue then Exit;  FUserName := AValue;end; constructor TMySQL57ConnectionBridge.Create(AOwner: TComponent);(* Allocates SQLDB components *)begin  inherited Create(AOwner);  FError := err_NoError;  try    MySQL57Connection := TMySQL57Connection.Create(Nil);    MySQL57Connection.SkipLibraryVersionCheck := True;  except    FError := err_CreateSQLConnection;    Exit;  end;  try    SQLTransaction := TSQLTransaction.Create(Nil)  except    FError := err_CreateSQLTransaction;    Exit;  end;  try    SQLQuery := TSQLQuery.Create(Nil);  except    FError := err_CreateSQLQuery;  end;end; destructor TMySQL57ConnectionBridge.Destroy;(* Deallocates SQLDB components *)begin  if Assigned(SQLQuery)     then       begin       SQLQuery.Close;         SQLQuery.Free;       end;  if Assigned(SQLTransaction)     then       begin         SQLTransaction.Active := False;         SQLTransaction.Free;       end;  if Assigned(MySQL57Connection)     then       begin         MySQL57Connection.Connected := False;         MySQL57Connection.Free;       end;  inherited Destroy;end; function TMySQL57ConnectionBridge.Connect: Boolean;(* Tries to connect to database *)begin  Result := False;  MySQL57Connection.DatabaseName := FDataBaseName;  MySQL57Connection.HostName := FHostName;  MySQL57Connection.Port := FPort;  MySQL57Connection.Password := FPassword;  MySQL57Connection.UserName := FUserName;  MySQL57Connection.Transaction := SQLTransaction;  MySQL57Connection.CharSet := 'UTF8';  SQLQuery.DataBase := MySQL57Connection;  try    MySQL57Connection.Open;    MySQL57Connection.Connected := True;  except    MySQL57Connection.Connected := False;  end;  Result := MySQL57Connection.Connected;end; end. And this code worked: 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 procedure TAndroidModule1.btnConnectClick(Sender: TObject);(* Connection to the database *)begin  EditText1.Append('Creation result: ');  case MySQLAndroidConnection1.Error of    err_NoError: EditText1.AppendLn('no error');    err_CreateSQLConnection: EditText1.AppendLn('err_CreateSQLConnection');    err_CreateSQLTransaction: EditText1.AppendLn('err_CreateSQLTransaction';    err_CreateSQLQuery: EditText1.AppendLn('err_CreateSQLQuery');  end;  MySQLAndroidConnection1.HostName := '192.168.1.40';  MySQLAndroidConnection1.Port := 3306;  MySQLAndroidConnection1.DatabaseName := 'xxxxxxx';  MySQLAndroidConnection1.UserName := 'yyyyyyy';  MySQLAndroidConnection1.Password := 'zzzzzzz';  if MySQLAndroidConnection1.Connect     then       EditText1.AppendLn('Connected!');     else       EditText1.AppendLn('Error...');end; procedure TAndroidModule1.btnQueryClick(Sender: TObject);(* Lists a table *)begin  MySQLAndroidConnection1.SQLQuery.Close;  MySQLAndroidConnection1.SQLQuery.SQL.Text := 'SELECT * FROM T_CATEGORIES;';  MySQLAndroidConnection1.SQLQuery.Open;  MySQLAndroidConnection1.SQLQuery.Last;  EditText1.AppendLn('Number of records: ' + IntToStr(MySQLAndroidConnection1.SQLQuery.RecordCount));  MySQLAndroidConnection1.SQLQuery.First;  while not MySQLAndroidConnection1.SQLQuery.EOF do    begin      EditText1.Append Ln(MySQLAndroidConnection1.SQLQuery.FieldByName('F_CATEGORYNAME').AsSt ring);      MySQLAndroidConnection1.SQLQuery.Next;    end;end;