Skip to content

Commit b0ab0fc

Browse files
committed
refactor: simplify some more calls to Query() with the overloaded variants
1 parent d7910c1 commit b0ab0fc

File tree

8 files changed

+7
-11
lines changed

8 files changed

+7
-11
lines changed

source/dbconnection.pas

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,7 +3360,7 @@ procedure TDBConnection.DoAfterConnect;
33603360
else
33613361
Offset := '-';
33623362
Offset := Offset + Format('%.2d:%.2d', [Abs(Hours), Abs(Minutes)]);
3363-
Query(FSqlProvider.GetSql(qSetTimezone, [EscapeString(Offset)]));
3363+
Query(qSetTimezone, [EscapeString(Offset)]);
33643364
end;
33653365

33663366
// Process startup script
@@ -4299,7 +4299,6 @@ procedure TDBConnection.PrefetchCreateCode(Objects: TDBObjectList);
42994299
procedure TDBConnection.SetDatabase(Value: String);
43004300
var
43014301
s: String;
4302-
UseQuery: String;
43034302
begin
43044303
Log(lcDebug, 'SetDatabase('+Value+'), FDatabase: '+FDatabase);
43054304
if Value <> FDatabase then begin
@@ -4319,9 +4318,8 @@ procedure TDBConnection.SetDatabase(Value: String);
43194318
s := s + ', ' + EscapeString('public');
43204319
end else
43214320
s := QuoteIdent(Value);
4322-
UseQuery := FSqlProvider.GetSql(qUSEQuery);
4323-
if not UseQuery.IsEmpty then begin
4324-
Query(FSqlProvider.GetSql(qUSEQuery, [s]), False);
4321+
if FSqlProvider.Has(qUSEQuery) then begin
4322+
Query(qUSEQuery, [s]);
43254323
end;
43264324
FDatabase := DeQuoteIdent(Value);
43274325
if Assigned(FOnDatabaseChanged) then

source/dbstructures.interbase.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function TInterbaseProvider.GetSql(AId: TQueryId): string;
186186
begin
187187
case AId of
188188
qDatabaseDrop: Result := 'DROP DATABASE %s';
189-
qEmptyTable: Result := 'TRUNCATE ';
189+
qEmptyTable: Result := 'TRUNCATE %s';
190190
qRenameTable: Result := 'RENAME TABLE %s TO %s';
191191
qRenameView: Result := 'RENAME TABLE %s TO %s';
192192
qCurrentUserHost: Result := IfThen(

source/dbstructures.mssql.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ function TMsSqlProvider.GetSql(AId: TQueryId): string;
450450
'xtype',
451451
'type'
452452
);
453-
qEmptyTable: Result := 'DELETE FROM ';
454453
qRenameTable: Result := 'EXEC sp_rename %s, %s';
455454
qRenameView: Result := 'EXEC sp_rename %s, %s';
456455
qCurrentUserHost: Result := 'SELECT SYSTEM_USER';

source/dbstructures.mysql.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3247,7 +3247,7 @@ function TMySqlProvider.GetSql(AId: TQueryId): string;
32473247
begin
32483248
case AId of
32493249
qDatabaseDrop: Result := 'DROP DATABASE %s';
3250-
qEmptyTable: Result := 'TRUNCATE ';
3250+
qEmptyTable: Result := 'TRUNCATE %s';
32513251
qRenameTable: Result := 'RENAME TABLE %s TO %s';
32523252
qRenameView: Result := 'RENAME TABLE %s TO %s';
32533253
qCurrentUserHost: Result := 'SELECT CURRENT_USER()';

source/dbstructures.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function TSqlProvider.GetSql(AId: TQueryId): string;
205205
begin
206206
// Basic default SQL snippets compatible to all or most servers
207207
case AId of
208+
qEmptyTable: Result := 'DELETE FROM %s';
208209
qForeignKeyEventAction: Result := 'RESTRICT,CASCADE,SET NULL,NO ACTION';
209210
qOrderAsc: Result := 'ASC';
210211
qOrderDesc: Result := 'DESC';

source/dbstructures.postgresql.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ function TPostgreSQLProvider.GetSql(AId: TQueryId): string;
599599
begin
600600
case AId of
601601
qDatabaseDrop: Result := 'DROP SCHEMA %s';
602-
qEmptyTable: Result := 'DELETE FROM ';
603602
qRenameTable: Result := 'ALTER TABLE %s RENAME TO %s';
604603
qRenameView: Result := 'ALTER VIEW %s RENAME TO %s';
605604
qCurrentUserHost: Result := 'SELECT CURRENT_USER';

source/dbstructures.sqlite.pas

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ function TSQLiteProvider.GetSql(AId: TQueryId): string;
401401
begin
402402
case AId of
403403
qDatabaseDrop: Result := 'DROP DATABASE %s';
404-
qEmptyTable: Result := 'DELETE FROM ';
405404
qRenameTable: Result := 'ALTER TABLE %s RENAME TO %s';
406405
qRenameView: Result := 'ALTER TABLE %s RENAME TO %s';
407406
qCurrentUserHost: Result := ''; // unsupported

source/main.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4541,7 +4541,7 @@ procedure TMainForm.actEmptyTablesExecute(Sender: TObject);
45414541
Conn.Query(QueryDisableChecks);
45424542
try
45434543
for TableOrView in Objects do begin
4544-
Conn.Query(Conn.SqlProvider.GetSql(qEmptyTable) + TableOrView.QuotedName);
4544+
Conn.Query(qEmptyTable, [TableOrView.QuotedName]);
45454545
ProgressStep;
45464546
end;
45474547
actRefresh.Execute;

0 commit comments

Comments
 (0)