Make your own free website on Tripod.com

File : oci-task_environment.adb


--with Text_IO,System.Address_Image; use Text_IO,System;
package body OCI.Task_Environment is

    use type sword,ub4;
    use type OCIHandle;
   
   procedure Free(H : OCIHandle; HType : Ub4) is
      Rc : Sword;
   begin
      if H=Empty_Handle then
         return;
      end if;
      RC := OCIHandleFree(H, HType);
      if Rc/=OCI_SUCCESS then
        null;
      end if;
   end Free;

  function Create return Thread_Environment is
      Env : aliased OCIEnv := OCIEnv(Empty_Handle);
      Rc : Sword;
  begin
     Rc := OCIEnvCreate(Env'access,
          OCI_THREADED+OCI_OBJECT);
     if Rc/=OCI_SUCCESS then
        raise ENVIRONMENT_CREATION_ERROR;
     end if;
     return (RF.Controlled_Reference with Environment => Env);
  end;

  procedure Destroy   (Object : in out Thread_Environment) is
  begin
     if Object.Environment/=OCIEnv(Empty_Handle) then
       Free(OCIHandle(Object.Environment),OCI_HTYPE_ENV);
--       Put_Line("Environment freed");
     end if;  
  end;

end OCI.Task_Environment;