On a form, I had a TSQLite3Connection, TSQLTransaction, TSQLTransaction, and a TSQLQuery. Life was good. I got it wired up and it was rolling. But then I decided to show off a little. So I added the TSQLite3Connection and the TSQLTransaction to a TDataModule, named DM1. On Unit1, I added
Made all the necessary changes to the prior uses of TSQLite3Connection and TSQLite3Connection on Unit1, i.e.:
DM1.SQLite3Connection1.Connected := True;
DM1.SQLTransaction1.Active := True;
But now, when I run it, I get an error:
Project ProjectName raised exception class 'External SIGSEGV'
and references this line, which is also the first line in Unit1 that makes reference to my DM1 of Unit2:
DM1.SQLite3Connection1.DatabaseName := 'data.db';
Again, all of this worked until I started using the DataModule. I don't mind putting it all back on one form, but the DataModule seems kind of handy.
Here's all the code on Unit1:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, db, sqldb, sqlite3conn, Forms, Controls, Graphics, Dialogs,
DBGrids, DBCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
SQLQuery1 : TSQLQuery ;
procedure DBNavigator1Click(Sender: TObject; Button: TDBNavButtonType);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
Unit2;
{ TForm1 }
procedure TForm1.DBNavigator1Click(Sender: TObject; Button: TDBNavButtonType);
begin
case Button of
nbPost:
begin
SQLQuery1.ApplyUpdates;
DM1.SQLTransaction1.CommitRetaining;
end;
nbDelete:
begin
SQLQuery1.ApplyUpdates;
DM1.SQLTransaction1.CommitRetaining;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DM1.SQLite3Connection1.DatabaseName := 'data.db';
SQLQuery1.SQL.Text := 'PRAGMA foreign_keys = ON';
SQLQuery1.ExecSQL;
DM1.SQLTransaction1.Commit;
SQLQuery1.SQL.Text :=
'CREATE TABLE IF NOT EXISTS customers(' +
'cust_id INTEGER PRIMARY KEY AUTOINCREMENT, ' +
'cust_name VARCHAR(30) NOT NULL)';
DM1.SQLite3Connection1.Connected := True;
DM1.SQLTransaction1.Active := True;
SQLQuery1.ExecSQL;
DM1.SQLTransaction1.Commit;
SQLQuery1.SQL.Text :=
'CREATE TABLE IF NOT EXISTS sites(' +
'site_id INTEGER PRIMARY KEY AUTOINCREMENT, ' +
'site_name VARCHAR(30) NOT NULL, ' +
'site_cust VARCHAR(30) NOT NULL, ' +
'FOREIGN KEY (site_cust) REFERENCES customers(cust_id) ' +
'ON UPDATE CASCADE ON DELETE CASCADE)';
SQLQuery1.ExecSQL;
DM1.SQLTransaction1.Commit;
SQLQuery1.SQL.Text := 'select * from customers';
SQLQuery1.Open;
DBGrid1.Columns[0].Visible := False;
end;
end.
What am I doing wrong?