Witam,
korzystałem z artykułu (SQLite w Delphi) na 4programmers.net odnośnie SQLite w Delphi (korzystam z wersji Turbo) i mam kłopot przy wprowadzaniu danych do tabeli. Program mi się cały czas wywala z krytyczną wiadomością. Projekt programu załączam do wiadomości natomiast kod wklejam poniżej:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SQLiteTable3, StdCtrls;
type
TForm1 = class(TForm)
zapisTabela: TEdit;
Label1: TLabel;
zapisRekord1: TEdit;
zapisRekord2: TEdit;
Memo1: TMemo;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
odczytTabela: TEdit;
Label7: TLabel;
odczytRekord1: TEdit;
odczytRekord2: TEdit;
Memo2: TMemo;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
SQLBaza: TSQLiteDataBase;
SQLTabela: TSQLiteTable;
sciezka: string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not SQLBaza.TableExists(zapistabela.Text) then
begin
SQLBaza.ExecSQL('CREATE TABLE "' + zapisTabela.Text + '" (id INTEGER PRIMARY KEY, imie VARCHAR, nazwysko VARCHAR, dane TEXT)'); //tworzy tabele o kolumnach id, imie i nazwisko
end;
SQLBaza.ExecSQL('INSERT INTO "' + zapisTabela.Text + '" VALUES( "' + zapisRekord1.Text + ' ", " ' + zapisRekord2.Text + ' ", " ' + memo1.Text + ' ")');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SQLBaza := nil;
sciezka := ExtractFilePath(Application.ExeName);
if not FileExists(sciezka + 'baza.dat') then //Sprawdzamy czy w katalogu z programem NIE istnieje baza danych
begin
SQLBaza := TSQLiteDataBase.Create(sciezka + 'baza.dat'); // Łączymy się z bazą
end
else
SQLBaza := TSQLiteDataBase.Create(sciezka + 'baza.dat');
end;
end.
Domyślam się, że może chodzić o parametr id jednak Autor w swoim artykule nie zamieścił tego w kodzie. Dodam, że dopiero zaczynam "lizać" temat SQLite w Delphi.
Pozdrawiam!