⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testtoradb.pas

📁 delphi通过OCI访问ORACLE
💻 PAS
字号:
unit testTOraDB;

{$INCLUDE dOCI.inc}

interface
uses
 SysUtils, Dialogs, TestFrameWork, DB, ADataSet, OraDB, AOraSQL;

type
 TTestOraDB = class(TTestCase)
 private
  DB:TOraDB;
  SQL:TAOraSQL;
 protected
    procedure SetUp; override;
    procedure TearDown; override;
 published

   procedure testOraDBFloatPrecision1;
   procedure testOraDBFloatPrecision2;
   procedure testOraDBFloatPrecision3;
   procedure testOraDBFloatPrecision4;
   procedure testOraDBFloatPrecision5;
   procedure testOraDBFloatPrecision6;
   procedure testOraDBFloatPrecision7;
   procedure testOraDBFloatPrecision8;
   procedure testOraDBFloatPrecision9;
   procedure testOraDBFloatPrecision10;

   procedure testOraDBOpenManyTimes;
end;

implementation

procedure TTestOraDB.SetUp;
begin
 DB  := TOraDB.Create(nil);
 DB.DBLogin := 'test';
 DB.DBPassword := 'a';
 DB.DBServer := 'RRR';
 DB.LoginPrompt := False;

 SQL := TAOraSQL.Create(nil);
 SQL.Database := DB;
 SQL.Name := 'SQL';
end;

procedure TTestOraDB.TearDown;
begin
 DB.Free;
 SQL.Free;
end;


procedure TTestOraDB.testOraDBFloatPrecision1;
begin
 DB.Preferences.FloatPrecision := 0;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoDouble);
 Check(SQL.FieldByIndex[10].FieldType = ftoDouble);
 Check(SQL.FieldByIndex[11].FieldType = ftoDouble);
 Check(SQL.FieldByIndex[12].FieldType = ftoDouble);
 Check(SQL.FieldByIndex[13].FieldType = ftoDouble);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision2;
begin
 DB.Preferences.FloatPrecision := 1;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoString);
 Check(SQL.FieldByIndex[10].FieldType = ftoString);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision3;
begin
 DB.Preferences.FloatPrecision := 2;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoString);
 Check(SQL.FieldByIndex[10].FieldType = ftoString);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision4;
begin
 DB.Preferences.FloatPrecision := 3;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoString);
 Check(SQL.FieldByIndex[10].FieldType = ftoString);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision5;
begin
 DB.Preferences.FloatPrecision := 4;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoString);
 Check(SQL.FieldByIndex[10].FieldType = ftoString);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision6;
begin
 DB.Preferences.FloatPrecision := 5;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoString);
 Check(SQL.FieldByIndex[10].FieldType = ftoString);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);
 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision7;
begin
 DB.Preferences.FloatPrecision := 8;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoString);
 Check(SQL.FieldByIndex[10].FieldType = ftoString);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision8;
begin
 DB.Preferences.FloatPrecision := 9;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoString);
 Check(SQL.FieldByIndex[10].FieldType = ftoString);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision9;
begin
 DB.Preferences.FloatPrecision := 10;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoDouble);
 Check(SQL.FieldByIndex[10].FieldType = ftoString);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBFloatPrecision10;
begin
 DB.Preferences.FloatPrecision := 11;

 SQL.SetQuery('select * from testfloat');

 SQL.LoadFields;
 SQL.Open;
 SQL.ReadAll;

 Check(SQL.FieldByIndex[0].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[1].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[2].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[3].FieldType = ftoSmallInt);
 Check(SQL.FieldByIndex[4].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[5].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[6].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[7].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[8].FieldType = ftoInteger);
 Check(SQL.FieldByIndex[9].FieldType = ftoDouble);
 Check(SQL.FieldByIndex[10].FieldType = ftoDouble);
 Check(SQL.FieldByIndex[11].FieldType = ftoString);
 Check(SQL.FieldByIndex[12].FieldType = ftoString);
 Check(SQL.FieldByIndex[13].FieldType = ftoString);

 FreeAndNil(SQL);
end;

procedure TTestOraDB.testOraDBOpenManyTimes;
begin
 DB.Close;
 Check(not DB.Active);
 DB.Open;
 Check(DB.Active);
 DB.Open;
 Check(DB.Active);
 DB.Open;
 Check(DB.Active);
 DB.Close;
 Check(not DB.Active);
 DB.Close;
 Check(not DB.Active);
 DB.Open;
 Check(DB.Active);
 DB.Open;
 Check(DB.Active);
 DB.Close;
 Check(not DB.Active);
 DB.Close;
 Check(not DB.Active);
end;

initialization
 TestFramework.RegisterTest(TTestOraDB.Suite);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -