-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMiniREST.SQL.SQLDb.pas
645 lines (575 loc) · 19.7 KB
/
MiniREST.SQL.SQLDb.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
{$mode DELPHI}
unit MiniREST.SQL.SQLDb;
interface
uses Classes, SysUtils, MiniREST.SQL.Intf, MiniREST.SQL.Base, MiniREST.SQL.Common, DB,
sqldb, IBConnection, pqconnection, sqlite3conn, fgl;
type
TLogEvent = procedure (Sender : TSQLConnection; EventType : TDBEventType; Const Msg : String);
IMiniRESTSQLConnectionFactoryParamsSQLDb = interface(IMiniRESTSQLConnectionFactoryParams)
['{F2FB358A-6369-4FCE-AA9B-75FFECA18E88}']
function GetConnectionString: string;
procedure SetConnectionString(const AConnectionString: string);
function GetUserName: string;
procedure SetUserName(const AUserName: string);
function GetPassword: string;
procedure SetPassword(const APassword: string);
function GetDatabaseName: string;
procedure SetDatabaseName(const ADatabaseName: string);
function GetLogEvent: TLogEvent;
procedure SetLogEvent(const ALogEvent: TLogEvent);
function GetServerHostName: string;
procedure SetServerHostName(const AServerHostName: string);
function GetServerPort: Integer;
procedure SetServerPort(const AServerPort: Integer);
end;
TMiniRESTSQLConnectionParamsSQLDb = class(TMiniRESTSQLConnectionFactoryParams, IMiniRESTSQLConnectionFactoryParamsSQLDb)
private
FConnectionString: string;
FUserName: string;
FPassword: string;
FDatabaseType: TMiniRESTSQLDatabaseType;
FDatabaseName: string;
FLogEvent: TLogEvent;
FServerHostName: string;
FPort: Integer;
public
function GetConnectionString: string;
procedure SetConnectionString(const AConnectionString: string);
function GetUserName: string;
procedure SetUserName(const AUserName: string);
function GetPassword: string;
procedure SetPassword(const APassword: string);
function GetDatabaseName: string;
procedure SetDatabaseName(const ADatabaseName: string);
function GetLogEvent: TLogEvent;
procedure SetLogEvent(const ALogEvent: TLogEvent);
function GetServerHostName: string;
procedure SetServerHostName(const AServerHostName: string);
function GetServerPort: Integer;
procedure SetServerPort(const AServerPort: Integer);
end;
TMiniRESTSQLConnectionFactorySQLDb = class(TMiniRESTSQLConnectionFactoryBase)
protected
FConnectionString: string;
FConnectionParams: IMiniRESTSQLConnectionFactoryParamsSQLDb;
procedure ReleaseConnection(AConnection: IMiniRESTSQLConnection); override;
function InternalGetconnection: IMiniRESTSQLConnection; override;
public
constructor Create(AParams: IMiniRESTSQLConnectionFactoryParamsSQLDb); reintroduce;
function GetConnectionsCount: Integer; override;
function GetQueueCount: Integer; override;
end;
{ TMiniRESTSQLConnectionSQLDb }
TMiniRESTSQLConnectionSQLDb = class(TMiniRESTSQLConnectionBase)
private
FOnOpenQueryException: TMiniRESTOnOpenQueryException;
function GetConnectorType(const ADatabaseType: TMiniRESTSQLDatabaseType): String;
procedure OnBeforeConnect(Sender: TObject);
protected
FSQLConnection: TSQLConnector;
//FTransaction: TDBXTransaction;
FConnectionParams: IMiniRESTSQLConnectionFactoryParamsSQLDb;
FTransaction: TSQLTransaction;
FInExplicitTransaction: Boolean;
FLogEvent: TLogEvent;
function GetObject: TObject; override;
function GetDriverName(const ADatabaseType: TMiniRESTSQLDatabaseType): string;
procedure Log(Sender : TSQLConnection; EventType : TDBEventType; Const Msg : String);
procedure SetMiniRESTSQLParamToSQLParam(AMiniRESTSQLParam: IMiniRESTSQLParam; ASQLParam: TParam);
procedure CheckConnectionIsValid;
procedure SetConnectionParams;
public
constructor Create(AOwner: IMiniRESTSQLConnectionFactory; AParams: IMiniRESTSQLConnectionFactoryParamsSQLDb);
destructor Destroy; override;
procedure Connect; override;
procedure StartTransaction; override;
procedure Commit; override;
procedure Rollback; override;
function GetQuery: IMiniRESTSQLQuery; override;
function GetQuery(const ASQL: string;
AParams: array of IMiniRESTSQLParam): IMiniRESTSQLQuery; override;
function GetQuery(const ASQL: string): IMiniRESTSQLQuery; override;
function Execute(const ACommand: string; AParams: array of IMiniRESTSQLParam): Integer; override;
function GetDatabaseInfo: IMiniRESTSQLDatabaseInfo; override;
function InTransaction: Boolean; override;
procedure Invalidate; override;
end;
{ TMiniRESTSQLQuerySQLDb }
TMiniRESTSQLQuerySQLDb = class(TInterfacedObject, IMiniRESTSQLQuery)
protected
FConnection: IMiniRESTSQLConnection;
FQry: TSQLQuery;
FTransaction: TSQLTransaction;
FSQL: string;
//FParams: TFPGInterfacedObjectList<string, IMiniRESTSQLParam>;
FParams: TFPGInterfacedObjectList<IMiniRESTSQLParam>;
FOnOpenQueryException: TMiniRESTOnOpenQueryException;
procedure BeforeOpenMiniRESTDataSet(DataSet: TDataSet);
public
constructor Create(AConnection: IMiniRESTSQLConnection);
destructor Destroy; override;
procedure Open;
procedure Close;
function GetSQL: string;
procedure SetSQL(const ASQL: string);
function ParamByName(const AParamName: string): IMiniRESTSQLParam;
function AddParam(AParam: IMiniRESTSQLParam): IMiniRESTSQLQuery;
function ApplyUpdates(const AMaxErrors: Integer): Integer;
function GetDataSet: TDataSet;
function GetParams: TArray<IMiniRESTSQLParam>;
end;
implementation
uses MiniREST.SQL.Firebird;
type
TMiniRESTSQLConnectionBaseCrack = class(TMiniRESTSQLConnectionBase);
{ TSQLQuery }
TSQLQueryMiniREST = class(TSQLQuery)
private
FInternalMiniRESTSQLBeforeOpenDataSet: TDataSetNotifyEvent;
protected
procedure DoBeforeOpen; override;
end;
{ TSQLQueryMiniREST }
procedure TSQLQueryMiniREST.DoBeforeOpen;
begin
inherited DoBeforeOpen;
if Assigned(FInternalMiniRESTSQLBeforeOpenDataSet) then
FInternalMiniRESTSQLBeforeOpenDataSet(Self);
end;
function TMiniRESTSQLConnectionParamsSQLDb.GetConnectionString: string;
begin
Result := FConnectionString;
end;
procedure TMiniRESTSQLConnectionParamsSQLDb.SetConnectionString(const AConnectionString: string);
begin
FConnectionString := AConnectionString;
end;
function TMiniRESTSQLConnectionParamsSQLDb.GetUserName: string;
begin
Result := FUserName;
end;
procedure TMiniRESTSQLConnectionParamsSQLDb.SetUserName(const AUserName: string);
begin
FUserName := AUserName;
end;
function TMiniRESTSQLConnectionParamsSQLDb.GetPassword: string;
begin
Result := FPassword;
end;
procedure TMiniRESTSQLConnectionParamsSQLDb.SetPassword(const APassword: string);
begin
FPassword := APassword;
end;
function TMiniRESTSQLConnectionFactorySQLDb.InternalGetconnection: IMiniRESTSQLConnection;
var
LConn: TMiniRESTSQLConnectionSQLDb;
begin
LConn := TMiniRESTSQLConnectionSQLDb.Create(Self, FConnectionParams);
LConn.FOnOpenQueryException := GetOnOpenQueryException;
Result := LConn;
end;
constructor TMiniRESTSQLConnectionFactorySQLDb.Create(AParams: IMiniRESTSQLConnectionFactoryParamsSQLDb);
begin
inherited Create(AParams);
FConnectionParams := AParams;
FConnectionsCount := AParams.GetConnectionsCount;
end;
constructor TMiniRESTSQLConnectionSQLDb.Create(AOwner: IMiniRESTSQLConnectionFactory; AParams: IMiniRESTSQLConnectionFactoryParamsSQLDb);
begin
if AParams = nil then
raise Exception.Create('Não foram passados os parâmetros');
FSQLConnection := TSQLConnector.Create(nil);
FTransaction := TSQLTransaction.Create(nil);
if (AParams.GetDatabaseType = dbtFirebird) then
FTransaction.Params.Text := 'isc_tpb_read_committed';
//FTransaction.Options := [stoUseImplicit];
FSQLConnection.Transaction := FTransaction;
FSQLConnection.OnLog := Log;
FTransaction.Action := caCommit;
FConnectionParams := AParams;
FInExplicitTransaction := False;
FLogEvent := AParams.GetLogEvent;
FSQLConnection.BeforeConnect := OnBeforeConnect;
inherited Create(AOwner);
end;
destructor TMiniRESTSQLConnectionSQLDb.Destroy;
begin
FSQLConnection.Free;
FTransaction.Free;
inherited Destroy;
end;
procedure TMiniRESTSQLConnectionSQLDb.Connect;
begin
CheckConnectionIsValid;
if FSQLConnection.Connected then
Exit;
FSQLConnection.Connected := True;
end;
procedure TMiniRESTSQLConnectionSQLDb.StartTransaction;
begin
CheckConnectionIsValid;
if FTransaction.Active then
FTransaction.Rollback;
FTransaction.StartTransaction;
FInExplicitTransaction := True;
end;
procedure TMiniRESTSQLConnectionSQLDb.Commit;
begin
CheckConnectionIsValid;
FTransaction.Commit;
FInExplicitTransaction := False;
end;
procedure TMiniRESTSQLConnectionSQLDb.Rollback;
begin
CheckConnectionIsValid;
FTransaction.Rollback;
FInExplicitTransaction := False;
end;
function TMiniRESTSQLConnectionSQLDb.GetQuery: IMiniRESTSQLQuery;
var
LQry: TMiniRESTSQLQuerySQLDb;
begin
CheckConnectionIsValid;
LQry := TMiniRESTSQLQuerySQLDb.Create(Self);
LQry.FOnOpenQueryException := FOnOpenQueryException;
Result := LQry;
end;
function TMiniRESTSQLConnectionSQLDb.GetQuery(const ASQL: string; AParams: array of IMiniRESTSQLParam): IMiniRESTSQLQuery;
var
LParam: IMiniRESTSQLParam;
begin
Result := GetQuery(ASQL);
for LParam in AParams do
begin
Result.AddParam(LParam);
end;
end;
function TMiniRESTSQLConnectionSQLDb.GetQuery(const ASQL: string): IMiniRESTSQLQuery;
begin
Result := GetQuery();
Result.SQL := ASQL;
end;
function TMiniRESTSQLConnectionSQLDb.Execute(const ACommand: string; AParams: array of IMiniRESTSQLParam): Integer;
var
LQry: TSQLQuery;
LParam: TParam;
LMiniRESTSQLParam: IMiniRESTSQLParam;
begin
CheckConnectionIsValid;
Self.Connect;
LQry := TSQLQuery.Create(nil);
try
LQry.Options := [sqoAutoCommit];
LQry.SQLConnection := FSQLConnection;
LQry.SQL.Text := ACommand;
try
for LMiniRESTSQLParam in AParams do
begin
LParam := LQry.ParamByName(LMiniRESTSQLParam.GetParamName);
SetMiniRESTSQLParamToSQLParam(LMiniRESTSQLParam, LParam);
end;
LQry.ExecSQL;
except
on E: Exception do
begin
FTransaction.Rollback;
raise;
end;
end;
Result := LQry.RowsAffected;
finally
LQry.Free;
end;
end;
function TMiniRESTSQLConnectionSQLDb.GetDatabaseInfo: IMiniRESTSQLDatabaseInfo;
begin
CheckConnectionIsValid;
Result := nil;
case FConnectionParams.GetDatabaseType of
dbtFirebird: Result := TMiniRESTSQLDatabaseInfoFirebird.Create(Self);
else
raise Exception.Create('TMiniRESTSQLConnectionSQLDb.GetDatabaseInfo: ' +
'DatabaseType not implemented');
end;
end;
function TMiniRESTSQLConnectionSQLDb.GetObject: TObject;
begin
Result := Self;
end;
function TMiniRESTSQLConnectionSQLDb.GetDriverName(const ADatabaseType: TMiniRESTSQLDatabaseType): string;
begin
case ADatabaseType of
dbtFirebird: Result := 'Firebird';
dbtPostgreSQL: Result := 'PostgreSQL';
dbtSqlite: Result := 'SQLite3';
end;
end;
procedure TMiniRESTSQLConnectionSQLDb.Log(Sender: TSQLConnection;
EventType: TDBEventType; const Msg: String);
begin
if Assigned(FLogEvent) then
FLogEvent(Sender, EventType, Msg);
end;
procedure TMiniRESTSQLQuerySQLDb.Open;
var
LRaiseException: Boolean;
begin
LRaiseException := True;
try
FQry.Open;
except
on E: Exception do
begin
if not Assigned(FOnOpenQueryException) then
raise;
FOnOpenQueryException(FConnection, Self, E, LRaiseException);
if LRaiseException then
raise;
end;
end;
end;
procedure TMiniRESTSQLQuerySQLDb.Close;
begin
FQry.Close;
end;
function TMiniRESTSQLQuerySQLDb.GetSQL: string;
begin
Result := FSQL;
end;
procedure TMiniRESTSQLQuerySQLDb.SetSQL(const ASQL: string);
begin
FParams.Clear;
FSQL := ASQL;
FQry.SQL.Text := ASQL;
end;
function TMiniRESTSQLQuerySQLDb.ParamByName(const AParamName: string): IMiniRESTSQLParam;
var
LParam: IMiniRESTSQLParam;
LParamName: string;
begin
LParamName := UpperCase(AParamName);
for LParam in FParams do
begin
if SameText(LParamName, LParam.GetParamName) then
Exit(LParam);
end;
LParam := TMiniRESTSQLParam.Create;
LParam.SetParamName(LParamName);
FParams.Add(LParam);
Result := LParam;
end;
function TMiniRESTSQLQuerySQLDb.AddParam(AParam: IMiniRESTSQLParam): IMiniRESTSQLQuery;
var
LParam: IMiniRESTSQLParam;
begin
//FParams.AddOrSetData(AParam.GetParamName, AParam);
for LParam in FParams do
begin
if SameText(LParam.GetParamName, AParam.GetParamName) then
begin
FParams.Extract(LParam);
Break;
end;
end;
FParams.Add(AParam);
Result := Self;
end;
function TMiniRESTSQLQuerySQLDb.ApplyUpdates(const AMaxErrors: Integer): Integer;
var
LConnectionInExplicitTransaction: Boolean;
begin
LConnectionInExplicitTransaction := TMiniRESTSQLConnectionSQLDb(FConnection.GetObject).FInExplicitTransaction;
FQry.ApplyUpdates;
if not LConnectionInExplicitTransaction then
FConnection.Commit;
Result := 0;
{TODO: Tratar o retorno. Transformar em procedure?}
end;
function TMiniRESTSQLQuerySQLDb.GetDataSet: TDataSet;
begin
Result := FQry;
end;
function TMiniRESTSQLQuerySQLDb.GetParams: TArray<IMiniRESTSQLParam>;
var
I: Integer;
begin
SetLength(Result, FParams.Count);
for I := 0 to FParams.Count -1 do
Result[I] := FParams.Items[I];
end;
procedure TMiniRESTSQLQuerySQLDb.BeforeOpenMiniRESTDataSet(DataSet: TDataSet);
var
LMiniRESTSQLParam: IMiniRESTSQLParam;
LParam: TParam;
I: Integer;
begin
Assert(Assigned(FConnection), 'Não está definida a conexão');
if not Assigned(FConnection) then
raise Exception.Create('Não está definida a conexão');
FConnection.Connect;
for I := 0 to FParams.Count - 1 do
begin
//LMiniRESTSQLParam := FParams.Data[I];
LMiniRESTSQLParam := FParams.Items[I];
LParam := FQry.ParamByName(LMiniRESTSQLParam.GetParamName);
if LMiniRESTSQLParam.GetParamSize > 0 then
LParam.Size := LMiniRESTSQLParam.GetParamSize;
TMiniRESTSQLConnectionSQLDb(FConnection.GetObject).SetMiniRESTSQLParamToSQLParam(LMiniRESTSQLParam, LParam);
end;
end;
constructor TMiniRESTSQLQuerySQLDb.Create(AConnection: IMiniRESTSQLConnection);
begin
FConnection := AConnection;
FQry := TSQLQueryMiniREST.Create(nil);
FQry.Options := [sqoKeepOpenOnCommit];
TSQLQueryMiniREST(FQry).FInternalMiniRESTSQLBeforeOpenDataSet := BeforeOpenMiniRESTDataSet;
//FTransaction := TSQLTransaction.Create(nil);
//FTransaction.Action := caNone;
//FTransaction.Options := [stoUseImplicit];
//FTransaction.Database := TMiniRESTSQLConnectionSQLDb(AConnection.GetObject).FSQLConnection;
//FQry.Transaction := FTransaction;
FQry.SQLConnection := TMiniRESTSQLConnectionSQLDb(AConnection.GetObject).FSQLConnection;
//FParams := TFPGMapInterfacedObjectData<string, IMiniRESTSQLParam>.Create();
FParams := TFPGInterfacedObjectList<IMiniRESTSQLParam>.Create();
end;
destructor TMiniRESTSQLQuerySQLDb.Destroy;
begin
FQry.Free;
FParams.Free;
//FTransaction.Free;
inherited Destroy;
end;
function TMiniRESTSQLConnectionSQLDb.GetConnectorType(const ADatabaseType: TMiniRESTSQLDatabaseType): String;
begin
case ADatabaseType of
dbtUnknown: raise Exception.Create('Database Type not supported');
dbtFirebird: Result := 'Firebird';
dbtPostgreSQL: Result := 'PostgreSQL';
dbtSqlite: Result := 'SQLite3';
end;
end;
procedure TMiniRESTSQLConnectionSQLDb.OnBeforeConnect(Sender: TObject);
begin
SetConnectionParams;
end;
function TMiniRESTSQLConnectionParamsSQLDb.GetDatabaseName: string;
begin
Result := FDatabaseName;
end;
procedure TMiniRESTSQLConnectionParamsSQLDb.SetDatabaseName(const ADatabaseName: string);
begin
FDatabaseName := ADatabaseName;
end;
procedure TMiniRESTSQLConnectionFactorySQLDb.ReleaseConnection(AConnection: IMiniRESTSQLConnection);
begin
RTLeventWaitFor(FConnectionGetEvent);
try
FQueue.Add(AConnection);
TMiniRESTSQLConnectionBaseCrack(AConnection.GetObject).FEstaNoPool := True;
Inc(FAvailableConnections);
LogConnectionPoolEvent(Format('RELEASE CONNECTION %d - %s', [AConnection.GetConnectionID,
AConnection.GetName]));
finally
RTLeventSetEvent(FConnectionReleaseEvent);
RTLeventSetEvent(FConnectionGetEvent);
end;
end;
function TMiniRESTSQLConnectionParamsSQLDb.GetLogEvent: TLogEvent;
begin
Result := FLogEvent;
end;
procedure TMiniRESTSQLConnectionParamsSQLDb.SetLogEvent(const ALogEvent: TLogEvent);
begin
FLogEvent := ALogEvent;
end;
procedure TMiniRESTSQLConnectionSQLDb.SetMiniRESTSQLParamToSQLParam(AMiniRESTSQLParam: IMiniRESTSQLParam; ASQLParam: TParam);
begin
case AMiniRESTSQLParam.GetParamType of
stString: ASQLParam.AsString := AMiniRESTSQLParam.AsString;
stFloat: ASQLParam.AsFloat := AMiniRESTSQLParam.AsFloat;
stInteger: ASQLParam.AsInteger := AMiniRESTSQLParam.AsInteger;
stDate: ASQLParam.AsDate := AMiniRESTSQLParam.AsDate;
stDateTime: ASQLParam.AsDateTime := AMiniRESTSQLParam.AsDateTime;
stBoolean: ASQLParam.AsBoolean := AMiniRESTSQLParam.AsBoolean;
stVariant, stUndefined: ASQLParam.Value := AMiniRESTSQLParam.GetAsVariant;
end;
if (AMiniRESTSQLParam.GetParamType = stString) and (AMiniRESTSQLParam.GetParamSize > 0) then
ASQLParam.AsString := Copy(ASQLParam.AsString, 1, AMiniRESTSQLParam.GetParamSize);
end;
function TMiniRESTSQLConnectionSQLDb.InTransaction: Boolean;
begin
CheckConnectionIsValid;
Result := FInExplicitTransaction and FSQLConnection.Transaction.Active;
end;
function TMiniRESTSQLConnectionFactorySQLDb.GetConnectionsCount: Integer;
begin
Result := FConnectionsCount;
end;
function TMiniRESTSQLConnectionFactorySQLDb.GetQueueCount: Integer;
begin
Result := FAvailableConnections;
if Result < 0 then
Result := 0;
end;
procedure TMiniRESTSQLConnectionSQLDb.Invalidate;
begin
SetValid(False);
FreeAndNil(FSQLConnection);
FreeAndNil(FTransaction);
end;
procedure TMiniRESTSQLConnectionSQLDb.CheckConnectionIsValid;
begin
if not IsValid then
raise Exception.Create('A conexão foi invalidada.');
end;
procedure TMiniRESTSQLConnectionSQLDb.SetConnectionParams;
var
LStringList: TStringList;
LName: string;
I: Integer;
begin
LStringList := TStringList.Create;
try
FSQLConnection.ConnectorType := GetConnectorType(FConnectionParams.GetDatabaseType);
if FConnectionParams.GetCharSet <> '' then
FSQLConnection.CharSet := FConnectionParams.GetCharSet;
FSQLConnection.LoginPrompt := False;
FSQLConnection.UserName := FConnectionParams.GetUserName;
FSQLConnection.Password := FConnectionParams.GetPassword;
FSQLConnection.DatabaseName := FConnectionParams.GetDatabaseName;
FSQLConnection.HostName := FConnectionParams.GetServerHostName;
if (FConnectionParams.GetServerPort > 0) and (FConnectionParams.GetDatabaseType = dbtFirebird) then
begin
FSQLConnection.HostName := '';
FSQLConnection.DatabaseName := FConnectionParams.GetServerHostName + '/' + IntToStr(FConnectionParams.GetServerPort) + ':' +
FConnectionParams.GetDatabaseName;
end;
LStringList.Text := FConnectionParams.GetConnectionString;
for I := 0 to LStringList.Count - 1 do
begin
LName := LStringList.Names[I];
FSQLConnection.Params.Values[LName] := LStringList.Values[LName];
end;
if (FConnectionParams.GetServerPort > 0) and (FConnectionParams.GetDatabaseType = dbtPostgreSQL) then
FSQLConnection.Params.Values['port'] := IntToStr(FConnectionParams.GetServerPort);
finally
LStringList.Free;
end;
end;
function TMiniRESTSQLConnectionParamsSQLDb.GetServerHostName: string;
begin
Result := FServerHostName;
end;
procedure TMiniRESTSQLConnectionParamsSQLDb.SetServerHostName(const AServerHostName: string);
begin
FServerHostName := AServerHostName;
end;
function TMiniRESTSQLConnectionParamsSQLDb.GetServerPort: Integer;
begin
Result := FPort;
end;
procedure TMiniRESTSQLConnectionParamsSQLDb.SetServerPort(const AServerPort: Integer);
begin
FPort := AServerPort;
end;
end.