unit Unit1; {$mode objfpc}{$H+}interfaceuses Classes, SysUtils, OracleConnection, sqldb, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Spin;type { TForm1 } TForm1 = class(TForm) ApplicationProperties1: TApplicationProperties; btnPolacz: TButton; btnAnuluj: TButton; edtAdres: TEdit; edtUser: TEdit; edtHaslo: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; conn: TOracleConnection; sql: TSQLQuery; transaction: TSQLTransaction; procedure ApplicationProperties1Exception(Sender: TObject; E: Exception); procedure btnAnulujClick(Sender: TObject); procedure btnPolaczClick(Sender: TObject); private { private declarations } public { public declarations } end; var Form1: TForm1; implementation{ TForm1 }procedure TForm1.btnAnulujClick(Sender: TObject);begin if conn.Connected then conn.Close; Close;end;procedure TForm1.ApplicationProperties1Exception(Sender: TObject; E: Exception);begin ShowMessage('Błąd: ' + E.Message);end;procedure TForm1.btnPolaczClick(Sender: TObject);var tex: boolean;begin conn.HostName := edtAdres.Text; conn.UserName := edtUser.Text; conn.Password := edtHaslo.Text; try conn.Open; tex := false; sql.SQL.Text := 'SELECT COUNT(*) FROM all_tables WHERE table_name = ''OSVC_PRACOWNICY'''; try sql.Open; if sql.FieldByName('COUNT(*)').AsInteger > 0 then begin tex := true; if MessageDlg('', 'Tabela OSVC_PRACOWNICY już istnieje. Czy chcesz ją usunąć?', mtConfirmation, mbYesNo, 0) = mrYes then begin sql.Close; sql.SQL.Text := 'DROP TABLE OSVC_PRACOWNICY'; sql.ExecSQL; tex := false; end; end; finally sql.Close; end; if not tex then begin sql.SQL.Text := 'CREATE TABLE OSVC_PRACOWNICY (' + 'prac_id INT NOT NULL PRIMARY KEY, ' + 'imie VARCHAR(20) NOT NULL, ' + 'nazwisko VARCHAR(40) NOT NULL)'; sql.ExecSQL; end; sql.SQL.Text := 'CREATE SEQUENCE IN NOT EXISTS prac_id_inc INCREMENT BY 1 START WITH 1'; sql.ExecSQL; finally conn.Close; end;end;initialization {$I unit1.lrs}end.
sql.SQL.Text := 'CREATE SEQUENCE IN NOT EXISTS prac_id_inc INCREMENT BY 1 START WITH 1';