unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, SQLite3Conn, SQLDB, DB, Forms, Controls, Graphics, Dialogs,
  DBGrids, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    DBGrid1: TDBGrid;
    SQLite3Connection1: TSQLite3Connection;
    SQLQuery1: TSQLQuery;
    SQLTransaction1: TSQLTransaction;
    DataSource1: TDataSource;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);


  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin

 // ShowMessage('Hello World!');
  SQLite3Connection1:= TSQLite3Connection.Create(nil);
  SqlTransaction1 := TSQLTransaction.Create(nil);
  SqlQuery1 := TSQLQuery.Create(nil);
  Datasource1 := TDataSource.create(nil);
  DBGrid1 := TDBGrid.create(nil);

  // Datenbankdatei festlegen
  SQLite3Connection1.DatabaseName := '/home/johannes/SQLITE Datenbanken/Vereinsbuchhaltung.SQLite3';
  SQLite3Connection1.Transaction := SQLTransaction1;
  SQLQuery1.Database := SQLite3Connection1;



  try


    // Daten abfragen

    SQLite3Connection1.Open;
    SQLite3Connection1.Connected := True;
    SQLTransaction1.DataBase := SQLite3Connection1;
    SQLQuery1.DataBase := SQLite3Connection1;
    SQLTransaction1.Active := True;
    SQLQuery1.SQL.Clear;
    Dbgrid1.Clear;
    SQLQuery1.SQL.Text := 'SELECT * FROM Beitragsarten';

    SQLQuery1.Open;
    DataSource1.DataSet := SQLQuery1;
    DataSource1.DataSet.Active := true;
    // while not Datasource1.Dataset.Eof do begin
       DBGrid1.DataSource := DataSource1;
       //showmessage(Datasource1.Dataset.FieldByName('Bezeichnung').AsString);
       DBGrid1.AutoFillColumns := True;


     //  Datasource1.Dataset.next;
    // end;

    Datasource1.free;
    SQLQuery1.Close;
    // Transaktion bestätigen
    SQLTransaction1.Commit;
    Showmessage('Ende');
  except
    on E: Exception do
      ShowMessage('Fehler: ' + E.Message);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Application.Terminate;
end;






end.

