mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-15 02:54:07 +08:00
Introduce TSQLSpecifity and TDBConnection.GetSQLSpecifity(), which manage and return server version specific SQL snippets. Fixes issue #2796.
This commit is contained in:
@ -203,6 +203,8 @@ type
|
|||||||
TDBLogEvent = procedure(Msg: String; Category: TDBLogCategory=lcInfo; Connection: TDBConnection=nil) of object;
|
TDBLogEvent = procedure(Msg: String; Category: TDBLogCategory=lcInfo; Connection: TDBConnection=nil) of object;
|
||||||
TDBEvent = procedure(Connection: TDBConnection; Database: String) of object;
|
TDBEvent = procedure(Connection: TDBConnection; Database: String) of object;
|
||||||
TDBDataTypeArray = Array of TDBDataType;
|
TDBDataTypeArray = Array of TDBDataType;
|
||||||
|
TSQLSpecifityId = (spDatabaseTable, spDatabaseTableId,
|
||||||
|
spDbObjectsTable, spDbObjectsCreateCol, spDbObjectsUpdateCol, spDbObjectsTypeCol);
|
||||||
|
|
||||||
TDBConnection = class(TComponent)
|
TDBConnection = class(TComponent)
|
||||||
private
|
private
|
||||||
@ -241,9 +243,10 @@ type
|
|||||||
FQuoteChar: Char;
|
FQuoteChar: Char;
|
||||||
FDatatypes: TDBDataTypeArray;
|
FDatatypes: TDBDataTypeArray;
|
||||||
FThreadID: Cardinal;
|
FThreadID: Cardinal;
|
||||||
|
FSQLSpecifities: Array[TSQLSpecifityId] of String;
|
||||||
procedure SetActive(Value: Boolean); virtual; abstract;
|
procedure SetActive(Value: Boolean); virtual; abstract;
|
||||||
procedure DoBeforeConnect; virtual;
|
procedure DoBeforeConnect; virtual;
|
||||||
procedure DoAfterConnect;
|
procedure DoAfterConnect; virtual;
|
||||||
procedure SetDatabase(Value: String);
|
procedure SetDatabase(Value: String);
|
||||||
function GetThreadId: Cardinal; virtual; abstract;
|
function GetThreadId: Cardinal; virtual; abstract;
|
||||||
function GetCharacterSet: String; virtual; abstract;
|
function GetCharacterSet: String; virtual; abstract;
|
||||||
@ -291,6 +294,7 @@ type
|
|||||||
function GetLastResults: TDBQueryList; virtual; abstract;
|
function GetLastResults: TDBQueryList; virtual; abstract;
|
||||||
function GetCreateCode(Database, Name: String; NodeType: TListNodeType): String; virtual; abstract;
|
function GetCreateCode(Database, Name: String; NodeType: TListNodeType): String; virtual; abstract;
|
||||||
function GetServerVariables: TDBQuery; virtual; abstract;
|
function GetServerVariables: TDBQuery; virtual; abstract;
|
||||||
|
function GetSQLSpecifity(Specifity: TSQLSpecifityId): String;
|
||||||
procedure ClearDbObjects(db: String);
|
procedure ClearDbObjects(db: String);
|
||||||
procedure ClearAllDbObjects;
|
procedure ClearAllDbObjects;
|
||||||
procedure ParseTableStructure(CreateTable: String; Columns: TTableColumnList; Keys: TTableKeyList; ForeignKeys: TForeignKeyList);
|
procedure ParseTableStructure(CreateTable: String; Columns: TTableColumnList; Keys: TTableKeyList; ForeignKeys: TForeignKeyList);
|
||||||
@ -353,6 +357,7 @@ type
|
|||||||
FPlinkProcInfo: TProcessInformation;
|
FPlinkProcInfo: TProcessInformation;
|
||||||
procedure SetActive(Value: Boolean); override;
|
procedure SetActive(Value: Boolean); override;
|
||||||
procedure DoBeforeConnect; override;
|
procedure DoBeforeConnect; override;
|
||||||
|
procedure DoAfterConnect; override;
|
||||||
procedure AssignProc(var Proc: FARPROC; Name: PAnsiChar);
|
procedure AssignProc(var Proc: FARPROC; Name: PAnsiChar);
|
||||||
procedure ClosePlink;
|
procedure ClosePlink;
|
||||||
function GetThreadId: Cardinal; override;
|
function GetThreadId: Cardinal; override;
|
||||||
@ -386,6 +391,7 @@ type
|
|||||||
FLastRawResults: TAdoRawResults;
|
FLastRawResults: TAdoRawResults;
|
||||||
FLastError: String;
|
FLastError: String;
|
||||||
procedure SetActive(Value: Boolean); override;
|
procedure SetActive(Value: Boolean); override;
|
||||||
|
procedure DoAfterConnect; override;
|
||||||
function GetThreadId: Cardinal; override;
|
function GetThreadId: Cardinal; override;
|
||||||
function GetCharacterSet: String; override;
|
function GetCharacterSet: String; override;
|
||||||
procedure SetCharacterSet(CharsetName: String); override;
|
procedure SetCharacterSet(CharsetName: String); override;
|
||||||
@ -1188,6 +1194,36 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMySQLConnection.DoAfterConnect;
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TAdoDBConnection.DoAfterConnect;
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
case ServerVersionInt of
|
||||||
|
2000: begin
|
||||||
|
FSQLSpecifities[spDatabaseTable] := QuoteIdent('master')+'..'+QuoteIdent('sysdatabases');
|
||||||
|
FSQLSpecifities[spDatabaseTableId] := QuoteIdent('dbid');
|
||||||
|
FSQLSpecifities[spDbObjectsTable] := '..'+QuoteIdent('sysobjects');
|
||||||
|
FSQLSpecifities[spDbObjectsCreateCol] := 'crdate';
|
||||||
|
FSQLSpecifities[spDbObjectsUpdateCol] := '';
|
||||||
|
FSQLSpecifities[spDbObjectsTypeCol] := 'xtype';
|
||||||
|
end;
|
||||||
|
else begin
|
||||||
|
FSQLSpecifities[spDatabaseTable] := QuoteIdent('sys')+'.'+QuoteIdent('databases');
|
||||||
|
FSQLSpecifities[spDatabaseTableId] := QuoteIdent('database_id');
|
||||||
|
FSQLSpecifities[spDbObjectsTable] := '.'+QuoteIdent('sys')+'.'+QuoteIdent('objects');
|
||||||
|
FSQLSpecifities[spDbObjectsCreateCol] := 'create_date';
|
||||||
|
FSQLSpecifities[spDbObjectsUpdateCol] := 'modify_date';
|
||||||
|
FSQLSpecifities[spDbObjectsTypeCol] := 'type';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TMySQLConnection.Ping(Reconnect: Boolean): Boolean;
|
function TMySQLConnection.Ping(Reconnect: Boolean): Boolean;
|
||||||
begin
|
begin
|
||||||
Log(lcDebug, 'Ping server ...');
|
Log(lcDebug, 'Ping server ...');
|
||||||
@ -1763,12 +1799,7 @@ begin
|
|||||||
Result := inherited;
|
Result := inherited;
|
||||||
if not Assigned(Result) then begin
|
if not Assigned(Result) then begin
|
||||||
try
|
try
|
||||||
case ServerVersionInt of
|
FAllDatabases := GetCol('SELECT '+QuoteIdent('name')+' FROM '+GetSQLSpecifity(spDatabaseTable)+' ORDER BY '+QuoteIdent('name'));
|
||||||
2000:
|
|
||||||
FAllDatabases := GetCol('SELECT '+QuoteIdent('name')+' FROM '+QuoteIdent('master')+'..'+QuoteIdent('sysdatabases')+' ORDER BY '+QuoteIdent('name'));
|
|
||||||
else
|
|
||||||
FAllDatabases := GetCol('SELECT '+QuoteIdent('name')+' FROM '+QuoteIdent('sys')+'.'+QuoteIdent('databases')+' ORDER BY '+QuoteIdent('name'));
|
|
||||||
end;
|
|
||||||
except on E:EDatabaseError do
|
except on E:EDatabaseError do
|
||||||
FAllDatabases := TStringList.Create;
|
FAllDatabases := TStringList.Create;
|
||||||
end;
|
end;
|
||||||
@ -2198,6 +2229,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TDBConnection.GetSQLSpecifity(Specifity: TSQLSpecifityId): String;
|
||||||
|
begin
|
||||||
|
// Return some version specific SQL clause or snippet
|
||||||
|
Result := FSQLSpecifities[Specifity];
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TDBConnection.GetInformationSchemaObjects: TStringList;
|
function TDBConnection.GetInformationSchemaObjects: TStringList;
|
||||||
var
|
var
|
||||||
Objects: TDBObjectList;
|
Objects: TDBObjectList;
|
||||||
@ -2553,7 +2591,7 @@ var
|
|||||||
obj: TDBObject;
|
obj: TDBObject;
|
||||||
Results: TDBQuery;
|
Results: TDBQuery;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
tp, FromClause, CreateCol, UpdateCol, TypeCol: String;
|
tp: String;
|
||||||
begin
|
begin
|
||||||
// Cache and return a db's table list
|
// Cache and return a db's table list
|
||||||
if Refresh then
|
if Refresh then
|
||||||
@ -2576,22 +2614,8 @@ begin
|
|||||||
Results := nil;
|
Results := nil;
|
||||||
|
|
||||||
// Tables, views and procedures
|
// Tables, views and procedures
|
||||||
case ServerVersionInt of
|
|
||||||
2000: begin
|
|
||||||
FromClause := QuoteIdent(db)+'..'+QuoteIdent('sysobjects');
|
|
||||||
CreateCol := 'crdate';
|
|
||||||
UpdateCol := '';
|
|
||||||
TypeCol := 'xtype';
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
FromClause := QuoteIdent(db)+'.'+QuoteIdent('sys')+'.'+QuoteIdent('objects');
|
|
||||||
CreateCol := 'create_date';
|
|
||||||
UpdateCol := 'modify_date';
|
|
||||||
TypeCol := 'type';
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
try
|
try
|
||||||
Results := GetResults('SELECT * FROM '+FromClause+
|
Results := GetResults('SELECT * FROM '+QuoteIdent(db)+GetSQLSpecifity(spDbObjectsTable)+
|
||||||
' WHERE '+QuoteIdent('type')+' IN ('+EscapeString('P')+', '+EscapeString('U')+', '+EscapeString('V')+', '+EscapeString('TR')+', '+EscapeString('FN')+')');
|
' WHERE '+QuoteIdent('type')+' IN ('+EscapeString('P')+', '+EscapeString('U')+', '+EscapeString('V')+', '+EscapeString('TR')+', '+EscapeString('FN')+')');
|
||||||
except
|
except
|
||||||
on E:EDatabaseError do;
|
on E:EDatabaseError do;
|
||||||
@ -2601,10 +2625,10 @@ begin
|
|||||||
obj := TDBObject.Create(Self);
|
obj := TDBObject.Create(Self);
|
||||||
Result.Add(obj);
|
Result.Add(obj);
|
||||||
obj.Name := Results.Col('name');
|
obj.Name := Results.Col('name');
|
||||||
obj.Created := ParseDateTime(Results.Col(CreateCol, True));
|
obj.Created := ParseDateTime(Results.Col(GetSQLSpecifity(spDbObjectsCreateCol), True));
|
||||||
obj.Updated := ParseDateTime(Results.Col(UpdateCol, True));
|
obj.Updated := ParseDateTime(Results.Col(GetSQLSpecifity(spDbObjectsUpdateCol), True));
|
||||||
obj.Database := db;
|
obj.Database := db;
|
||||||
tp := Trim(Results.Col(TypeCol, True));
|
tp := Trim(Results.Col(GetSQLSpecifity(spDbObjectsTypeCol), True));
|
||||||
if tp = 'U' then
|
if tp = 'U' then
|
||||||
obj.NodeType := lntTable
|
obj.NodeType := lntTable
|
||||||
else if tp = 'P' then
|
else if tp = 'P' then
|
||||||
|
@ -8414,8 +8414,8 @@ begin
|
|||||||
', RTRIM('+Conn.QuoteIdent('p')+'.'+Conn.QuoteIdent('status')+'), '+
|
', RTRIM('+Conn.QuoteIdent('p')+'.'+Conn.QuoteIdent('status')+'), '+
|
||||||
'NULL AS '+Conn.QuoteIdent('Info')+' '+
|
'NULL AS '+Conn.QuoteIdent('Info')+' '+
|
||||||
'FROM '+Conn.QuoteIdent('sys')+'.'+Conn.QuoteIdent('sysprocesses')+' AS '+Conn.QuoteIdent('p')+
|
'FROM '+Conn.QuoteIdent('sys')+'.'+Conn.QuoteIdent('sysprocesses')+' AS '+Conn.QuoteIdent('p')+
|
||||||
', '+Conn.QuoteIdent('sys')+'.'+Conn.QuoteIdent('sysdatabases')+' AS '+Conn.QuoteIdent('d')+
|
', '+Conn.GetSQLSpecifity(spDatabaseTable)+' AS '+Conn.QuoteIdent('d')+
|
||||||
' WHERE '+Conn.QuoteIdent('p')+'.'+Conn.QuoteIdent('dbid')+'='+Conn.QuoteIdent('d')+'.'+Conn.QuoteIdent('dbid')
|
' WHERE '+Conn.QuoteIdent('p')+'.'+Conn.QuoteIdent('dbid')+'='+Conn.QuoteIdent('d')+'.'+Conn.GetSQLSpecifity(spDatabaseTableId)
|
||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user