瀏覽代碼

* Try to drop the table if it already exists while setting up tests. This avoids an annoying exception while debugging the tests

git-svn-id: trunk@12213 -
joost 16 年之前
父節點
當前提交
836f7352e3
共有 1 個文件被更改,包括 21 次插入0 次删除
  1. 21 0
      packages/fcl-db/tests/sqldbtoolsunit.pas

+ 21 - 0
packages/fcl-db/tests/sqldbtoolsunit.pas

@@ -77,6 +77,7 @@ type
     procedure DropFieldDataset; override;
     Function InternalGetNDataset(n : integer) : TDataset; override;
     Function InternalGetFieldDataset : TDataSet; override;
+    procedure TryDropIfExist(ATableName : String);
   public
     destructor Destroy; override;
     constructor Create; override;
@@ -171,6 +172,7 @@ var CountID : Integer;
 begin
   try
     Ftransaction.StartTransaction;
+    TryDropIfExist('FPDEV');
     Fconnection.ExecuteDirect('create table FPDEV (       ' +
                               '  ID INT NOT NULL,           ' +
                               '  NAME VARCHAR(50),          ' +
@@ -196,6 +198,7 @@ var CountID : Integer;
 begin
   try
     Ftransaction.StartTransaction;
+    TryDropIfExist('FPDEV_FIELD');
 
     Sql := 'create table FPDEV_FIELD (ID INT NOT NULL,';
     for FType := low(TFieldType)to high(TFieldType) do
@@ -283,6 +286,24 @@ begin
     end;
 end;
 
+procedure TSQLDBConnector.TryDropIfExist(ATableName: String);
+begin
+  // This makes live 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.
+  try
+    if SQLDbType = INTERBASE then
+      begin
+      FConnection.ExecuteDirect('execute block as begin if (exists (select 1 from rdb$relations where rdb$relation_name=''FPDEV_FIELD'')) '+
+             'then execute statement ''drop table ' + ATAbleName + ';'';end');
+      FTransaction.CommitRetaining;
+      end;
+  except
+    FTransaction.RollbackRetaining;
+  end;
+end;
+
 destructor TSQLDBConnector.Destroy;
 begin
   if assigned(FTransaction) then