mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 11:17:57 +08:00
Safe 9 lines of code by introducing new server specific snippets spEmptyTable and spCurrentUserHost.
This commit is contained in:
@ -205,7 +205,8 @@ type
|
||||
TDBEvent = procedure(Connection: TDBConnection; Database: String) of object;
|
||||
TDBDataTypeArray = Array of TDBDataType;
|
||||
TSQLSpecifityId = (spDatabaseTable, spDatabaseTableId,
|
||||
spDbObjectsTable, spDbObjectsCreateCol, spDbObjectsUpdateCol, spDbObjectsTypeCol);
|
||||
spDbObjectsTable, spDbObjectsCreateCol, spDbObjectsUpdateCol, spDbObjectsTypeCol,
|
||||
spEmptyTable, spCurrentUserHost);
|
||||
|
||||
TDBConnection = class(TComponent)
|
||||
private
|
||||
@ -1233,12 +1234,16 @@ end;
|
||||
procedure TMySQLConnection.DoAfterConnect;
|
||||
begin
|
||||
inherited;
|
||||
FSQLSpecifities[spEmptyTable] := 'TRUNCATE ';
|
||||
FSQLSpecifities[spCurrentUserHost] := 'SELECT CURRENT_USER()';
|
||||
end;
|
||||
|
||||
|
||||
procedure TAdoDBConnection.DoAfterConnect;
|
||||
begin
|
||||
inherited;
|
||||
FSQLSpecifities[spEmptyTable] := 'DELETE FROM ';
|
||||
FSQLSpecifities[spCurrentUserHost] := 'SELECT SYSTEM_USER';
|
||||
case ServerVersionInt of
|
||||
2000: begin
|
||||
FSQLSpecifities[spDatabaseTable] := QuoteIdent('master')+'..'+QuoteIdent('sysdatabases');
|
||||
@ -2343,23 +2348,12 @@ end;
|
||||
|
||||
|
||||
function TDBConnection.GetCurrentUserHostCombination: String;
|
||||
var
|
||||
sql: String;
|
||||
begin
|
||||
// Return current user@host combination, used by various object editors for DEFINER clauses
|
||||
Log(lcDebug, 'Fetching user@host ...');
|
||||
Ping(True);
|
||||
if FCurrentUserHostCombination = '' then begin
|
||||
case Parameters.NetTypeGroup of
|
||||
ngMySQL:
|
||||
sql := 'SELECT CURRENT_USER()';
|
||||
ngMSSQL:
|
||||
sql := 'SELECT SYSTEM_USER';
|
||||
else
|
||||
raise Exception.CreateFmt(MsgUnhandledNetType, [Integer(Parameters.NetType)]);
|
||||
end;
|
||||
FCurrentUserHostCombination := GetVar(sql);
|
||||
end;
|
||||
if FCurrentUserHostCombination = '' then
|
||||
FCurrentUserHostCombination := GetVar(GetSQLSpecifity(spCurrentUserHost));
|
||||
Result := FCurrentUserHostCombination;
|
||||
end;
|
||||
|
||||
|
@ -3298,10 +3298,7 @@ begin
|
||||
EnableProgress(Objects.Count);
|
||||
try
|
||||
for TableOrView in Objects do begin
|
||||
case TableOrView.Connection.Parameters.NetTypeGroup of
|
||||
ngMySQL: TableOrView.Connection.Query('TRUNCATE ' + TableOrView.QuotedName);
|
||||
ngMSSQL: TableOrView.Connection.Query('DELETE FROM ' + TableOrView.QuotedName);
|
||||
end;
|
||||
TableOrView.Connection.Query(TableOrView.Connection.GetSQLSpecifity(spEmptyTable) + TableOrView.QuotedName);
|
||||
ProgressStep;
|
||||
end;
|
||||
actRefresh.Execute;
|
||||
|
Reference in New Issue
Block a user