uses ADODB;
interface
// Typ der Datenbankverbindung feststellen
function IsAccessConnection(cn: TADOConnection): Boolean;
function IsSQLServerConnection(cn: TADOConnection): Boolean;
function IsMySQLConnection(cn: TADOConnection): Boolean;
function IsOracleConnection(cn: TADOConnection): Boolean;
function IsODBCConnection(cn: TADOConnection): Boolean;
type
TADOConnectionType = ( ctMSAccess, ctMSSqlServer, ctMySQL, ctOracle, ctUnknown,
ctODBC );
function GetADOConnectionType(cn: TADOConnection): TADOConnectionType;
implementation
uses SysUtils;
function PosIgnoreCase(
const SubStr, S:
string): Integer;
begin
Result := Pos(UpperCase(SubStr),UpperCase(S));
end;
function IsAccessConnection(cn: TADOConnection): Boolean;
begin
Result := PosIgnoreCase('
Microsoft.Jet.OLEDB.',cn.Provider) > 0;
end;
function IsSQLServerConnection(cn: TADOConnection): Boolean;
begin
Result := (PosIgnoreCase(\\\'
SQLOLEDB\\\',cn.Provider) > 0)
or
// SQL Native Client von SQL Server 2005
(PosIgnoreCase(\\\'
SQLNCLI\\\',cn.Provider) > 0);
end;
function IsMySQLConnection(cn: TADOConnection): Boolean;
begin
// Warning !!! untested
Result := PosIgnoreCase('
MYSQLOLEDB',cn.Provider) > 0;
end;
function IsOracleConnection(cn: TADOConnection): Boolean;
begin
// Warning !!! untested
Result := PosIgnoreCase('
MSDAORA',cn.Provider) > 0;
end;
function IsODBCConnection(cn: TADOConnection): Boolean;
begin
Result := PosIgnoreCase('
MSDASQL', cn.Provider) > 0;
end;
function GetADOConnectionType(cn: TADOConnection): TADOConnectionType;
begin
Result := ctUnknown;
if not Assigned(cn)
then
Exit;
if IsAccessConnection(cn)
then
Result := ctMSAccess
else if IsSQLServerConnection(cn)
then
Result := ctMSSqlServer
else if IsMySQLConnection(cn)
then
Result := ctMySQL
else if IsOracleConnection(cn)
then
Result := ctOracle
else if IsODBCConnection(cn)
then
Result := ctODBC;
end;
end.