-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuDatabaseRelatedFunctions.pas
52 lines (39 loc) · 1.02 KB
/
uDatabaseRelatedFunctions.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
unit uDatabaseRelatedFunctions;
interface
uses FireDAC.Comp.Client, System.SysUtils;
function isConnected: Boolean;
function getNextFreedId(_table: String): Integer;
implementation
uses uDM, uVariables;
function isConnected: Boolean;
begin
DM.FDConnection1.Params.UserName := 'postgres'; //postgres
DM.FDConnection1.Params.Password := 'admin'; //admin
DM.FDConnection1.Params.Database := 'db_system'; //db_system
try
DM.FDConnection1.Connected := True;
Result := True;
except
Result := False;
end;
end;
function getNextFreedId(_table: String): Integer;
begin
if isConnected then
begin
db_table := TFDQuery.Create(nil);
db_table.Connection := DM.FDConnection1;
db_table.SQL.Add('SELECT MAX(id) AS id FROM ' + _table);
db_table.Open;
if db_table.FieldByName('id').IsNull then
Result := 1
else
Result := db_table.FieldByName('id').Value + 1;
db_table.Close;
FreeAndNil(db_table);
end
else
Result := 0;
DM.FDConnection1.Connected := False;
end;
end.