Skip to content

Commit ca98ff7

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

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
@@ -3498,7 +3498,7 @@ procedure TDBConnection.DoAfterConnect;
34983498
else
34993499
Offset := '-';
35003500
Offset := Offset + Format('%.2d:%.2d', [Abs(Hours), Abs(Minutes)]);
3501-
Query(FSqlProvider.GetSql(qSetTimezone, [EscapeString(Offset)]));
3501+
Query(qSetTimezone, [EscapeString(Offset)]);
35023502
end;
35033503

35043504
// Process startup script
@@ -4446,7 +4446,6 @@ procedure TDBConnection.PrefetchCreateCode(Objects: TDBObjectList);
44464446
procedure TDBConnection.SetDatabase(Value: String);
44474447
var
44484448
s: String;
4449-
UseQuery: String;
44504449
begin
44514450
Log(lcDebug, 'SetDatabase('+Value+'), FDatabase: '+FDatabase);
44524451
if Value <> FDatabase then begin
@@ -4466,9 +4465,8 @@ procedure TDBConnection.SetDatabase(Value: String);
44664465
s := s + ', ' + EscapeString('public');
44674466
end else
44684467
s := QuoteIdent(Value);
4469-
UseQuery := FSqlProvider.GetSql(qUSEQuery);
4470-
if not UseQuery.IsEmpty then begin
4471-
Query(FSqlProvider.GetSql(qUSEQuery, [s]), False);
4468+
if FSqlProvider.Has(qUSEQuery) then begin
4469+
Query(qUSEQuery, [s]);
44724470
end;
44734471
FDatabase := DeQuoteIdent(Value);
44744472
if Assigned(FOnDatabaseChanged) then

source/dbstructures.interbase.pas

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

source/dbstructures.mssql.pas

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

source/dbstructures.mysql.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3241,7 +3241,7 @@ function TMySqlProvider.GetSql(AId: TQueryId): string;
32413241
begin
32423242
case AId of
32433243
qDatabaseDrop: Result := 'DROP DATABASE %s';
3244-
qEmptyTable: Result := 'TRUNCATE ';
3244+
qEmptyTable: Result := 'TRUNCATE %s';
32453245
qRenameTable: Result := 'RENAME TABLE %s TO %s';
32463246
qRenameView: Result := 'RENAME TABLE %s TO %s';
32473247
qCurrentUserHost: Result := 'SELECT CURRENT_USER()';

source/dbstructures.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ function TSqlProvider.GetSql(AId: TQueryId): string;
209209
begin
210210
// Basic default SQL snippets compatible to all or most servers
211211
case AId of
212+
qEmptyTable: Result := 'DELETE FROM %s';
212213
qForeignKeyEventAction: Result := 'RESTRICT,CASCADE,SET NULL,NO ACTION';
213214
qOrderAsc: Result := 'ASC';
214215
qOrderDesc: Result := 'DESC';

source/dbstructures.postgresql.pas

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

source/dbstructures.sqlite.pas

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

source/main.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4596,7 +4596,7 @@ procedure TMainForm.actEmptyTablesExecute(Sender: TObject);
45964596
Conn.Query(QueryDisableChecks);
45974597
try
45984598
for TableOrView in Objects do begin
4599-
Conn.Query(Conn.SqlProvider.GetSql(qEmptyTable) + TableOrView.QuotedName);
4599+
Conn.Query(qEmptyTable, [TableOrView.QuotedName]);
46004600
ProgressStep;
46014601
end;
46024602
actRefresh.Execute;

0 commit comments

Comments
 (0)