-
Notifications
You must be signed in to change notification settings - Fork 0
/
uDM.pas
62 lines (52 loc) · 1.67 KB
/
uDM.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
53
54
55
56
57
58
59
60
61
62
unit uDM;
interface
uses
SysUtils, Classes, DB, ADODB, Dialogs;
type
TDBTypes = (DBMSAccess, DBSQLServer);
TExecutes = (eOpen, eExecute);
TDM = class(TDataModule)
cnn1: TADOConnection;
qry1: TADOQuery;
cnn2: TADOConnection;
qry2: TADOQuery;
cnn3: TADOConnection;
qry3: TADOQuery;
private
{ Private declarations }
public
{ Public declarations }
function runQuery(Connection:TADOConnection; Query:TADOQuery; SQLString:string; Executed:TExecutes=eOpen; DBType:TDBTypes=DBMSAccess):Boolean;
end;
var
DM: TDM;
implementation
{$R *.dfm}
function TDM.runQuery(Connection:TADOConnection; Query:TADOQuery; SQLString:string; Executed:TExecutes=eOpen; DBType:TDBTypes=DBMSAccess):Boolean;
begin
try
Connection.Close;
Connection.ConnectionString:= '';
if DBType = DBMSAccess then Connection.ConnectionString:= 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=irma.mdb;Persist Security Info=False';
if DBType = DBSQLServer then Connection.ConnectionString:= 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=master.mdb;Persist Security Info=False';
//if DBType = SQLServer then Connection.ConnectionString:= 'Provider=MSDASQL;Persist Security Info=False;Data Source=PB;Initial Catalog=SIRUS PB';
Connection.Open;
except
ShowMessage('Tidak dapat terkoneksi dengan database!');
Result:= False;
Exit;
end;
try
Connection.BeginTrans;
Query.Close;
Query.SQL.Clear;
Query.SQL.Add(SQLString);
if Executed = eExecute then Query.ExecSQL
else Query.Open;
Connection.CommitTrans;
except
Connection.RollbackTrans;
end;
if Query.Active then if Query.RecordCount > 0 then Result:= True;
end;
end.