mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 18:09:27 +02:00
* FCL-DB: fix for MSSQL/Sybase db test framework errors when existing FPDEV table present.
Thanks to Lacak2 for the fix idea! git-svn-id: trunk@22898 -
This commit is contained in:
parent
1c19fb9ecc
commit
c26abcebe7
@ -408,17 +408,40 @@ end;
|
||||
|
||||
procedure TSQLDBConnector.TryDropIfExist(ATableName: String);
|
||||
begin
|
||||
// This makes live soo much easier, since it avoids the exception if the table already
|
||||
// This makes life soo much easier, since it avoids the exception if the table already
|
||||
// exists. And while this exeption is in a try..except statement, the debugger
|
||||
// always shows the exception. Which is pretty annoying
|
||||
// It only works with Firebird 2, though.
|
||||
// always shows the exception, which is pretty annoying.
|
||||
try
|
||||
if SQLDbType = INTERBASE then
|
||||
begin
|
||||
// This only works with Firebird 2+
|
||||
FConnection.ExecuteDirect('execute block as begin if (exists (select 1 from rdb$relations where rdb$relation_name=''' + ATableName + ''')) '+
|
||||
'then execute statement ''drop table ' + ATAbleName + ';'';end');
|
||||
'then execute statement ''drop table ' + ATAbleName + ';'';end');
|
||||
FTransaction.CommitRetaining;
|
||||
end;
|
||||
if SQLDBType = mssql then
|
||||
begin
|
||||
// Checking is needed here to avoid getting "auto rollback" of a subsequent CREATE TABLE statement
|
||||
// which leads to the rollback not referring to the right transaction=>SQL error
|
||||
// Use SQL92 ISO standard INFORMATION_SCHEMA:
|
||||
FConnection.ExecuteDirect(
|
||||
'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE=''BASE TABLE'' AND TABLE_NAME=''' + ATableName + ''') '+
|
||||
'begin '+
|
||||
'drop table ' + ATAbleName + ' '+
|
||||
'end');
|
||||
FTransaction.CommitRetaining;
|
||||
end;
|
||||
if SQLDbType = sybase then
|
||||
begin
|
||||
// Checking is needed here to avoid getting "auto rollback" of a subsequent CREATE TABLE statement
|
||||
// which leads to the rollback not referring to the right transaction=>SQL error
|
||||
// Can't use SQL standard information_schema; instead query sysobjects for User tables
|
||||
FConnection.ExecuteDirect(
|
||||
'if exists (select * from sysobjects where type = ''U'' and name=''' + ATableName + ''') '+
|
||||
'begin '+
|
||||
'drop table ' + ATAbleName + ' '+
|
||||
'end');
|
||||
end;
|
||||
except
|
||||
FTransaction.RollbackRetaining;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user