Make your own free website on Tripod.com

File : test.adb


with
   Text_IO,
   Ada.Integer_Text_IO,
   Ada.Long_Float_Text_IO,
   Oci.Thick,
   OCI.Thick.Integer_Var,
   OCI.Thick.OCIDate_Var,
   OCI.Thick.Long_Float_Var,
   OCI.Thick.OCINumber_Var,
   OCI.Thick.String_Var,
   OCI.Thick.String_Bounded,
   OCI.Thick.Connection_pkg,
   OCI.Thick.Statement_pkg,
   OCI.Thick.Parameter_pkg,
   OCI.Thread,
   OCI.Thick.Number_Functions;
procedure Test is
   use Text_IO, Oci.Thick;

   use 
      Ada.Integer_Text_IO,
      Ada.Long_Float_Text_IO,
      Long_Float_Var,
      Integer_Var,
      String_Bounded,
      OCIDate_Var,
      OCINumber_Var,
      String_Var,
      Connection_pkg,
      Statement_pkg,
      Parameter_pkg,
      OCI.Thread,
      Number_Functions;
      
   procedure Main is
      Strv : String_Var.VString;
      strb : String_Bounded.Variable(64);
      Int : Integer_Var.Variable;
      Flt : Long_Float_Var.Variable;
      Numb : OCINumber_Var.Variable;
      Date  : OCIDate_Var.Variable;
      Param : Parameter;
      Stmt : Statement;
      Connect : Connection;
      onumb1,onumb2 : OCINumber;
      aflt : Long_Float;
      NULL_descr : array (boolean) of String(1..8) := (false => "NOT NULL",TRUE => "    NULL");
   begin
      Connect := Logon("scott/tiger@eforex.world");
      put_line(Server_Version(Connect));
      
      Stmt := Prepare(Connect, "select object_name,"&
          "timestamp, OBJECT_ID,"&
          "sysdate-created, sysdate-Last_ddl_Time, Last_ddl_Time "&
          "from user_objects where object_type=:objtype and object_id>:id");
      Set_Value(strb, "TABLE");
      Bind(Stmt,Strb,"objtype");
      Set_Value(int, 2);
      Bind(Stmt,int, 2);
      Execute(Stmt);
      declare
        Columns : Parameters := Get_Parameters(Stmt);
      begin
        for i in Columns'Range loop
          Set_Col(01); Put(Name(Columns(i)));
          Set_Col(25); Put(Typecode'Image(Type_Code(Columns(i))));
          Set_Col(38); Put(Type_Name(Columns(i)));
          Set_Col(40); Put(Integer'Image(Data_Size(Columns(i))));
          Set_Col(45); Put(Integer'Image(Precision(Columns(i))));
          Set_Col(50); Put(Integer'Image(Scale(Columns(i))));
          Set_Col(55); Put(NULL_DEscr(Is_Null(Columns(i))));
          Set_Col(65); Put(Schema_Name(Columns(i)));
        end loop;
        Param := Columns(1);
      end;
      Define(Stmt,Strv,1);
      Define(Stmt,strb,2);
      Define(Stmt,Int,3);
      Define(Stmt,Flt,4);
      Define(Stmt,Numb,5);
      Define(Stmt,Date,6);
      for i in 1..4 loop
         exit when not Fetch(Stmt);
         Set_Col(1);  Put(Get_Value(Strv)); 
         Set_Col(16); Put(Get_Value(Strb)); 
         Set_Col(35); Put(Get_Value(Int),Width=>6); 
         Set_Col(42); Put(Get_Value(Flt),Aft => 3,Exp=>0); 
         Set_Col(50); Put(To_String(Get_Value(Numb),"FM999990.99999")); 
         Set_Col(60); Put(To_String(Get_Value(Date),"DD Mon RRRR HH24:MI:SS"));
      end loop;
      Set_Col(1);
      Stmt := Prepare(Connect, "begin :result := (sysdate - :client_time)*60*60*24; end;");
      Bind(Stmt,Numb,":result");
      Bind(Stmt,Date,":client_time");
      Set_Value(Date,Sysdate); -- client local time
      Put_Line("Client time : "&To_String(Get_Value(Date),"Day Ddspth Month Yyyyspth HH24:MI:SS"));
      Execute(Stmt);
      Put_Line("Time difference : "&To_String(Get_Value(Numb),"FM999990.099")&" seconds");
      oNumb1 := Get_Value(Numb);
      oNumb2 := abs(onumb1);
      put("Time difference : ");
      Put_Line(To_String(onumb1,"FM999990.099")&" seconds");
      Put_Line(To_String(To_Number(To_Long_Float(-onumb2)),"FM9999999.099999"));
      Put_Line(To_String(onumb2,"FM999990.099"));
      Put_Line(To_String(ArcTan2(onumb1,onumb2),"FM999990.099"));
   end Main;

--   remove comments below to check multitasking
--   task type Parallel is
--     entry Start;
--   end Parallel;

--   task body Parallel is
--   begin
--      accept start;
--      Main;
--   end Parallel;

--      p : array (1..4) of parallel;
---------------------------------------

begin
--   Same_Environment_In(p(1)'Identity,p(2)'Identity);
--   Same_Environment_In(p(2)'Identity);
--   for i in p'Range loop
--      p(i).Start;
--   end loop;
   Main;
end Test