File: blocking.adb

package info (click to toggle)
gnade 1.6.2-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,220 kB
  • ctags: 847
  • sloc: ada: 40,154; sh: 4,124; sql: 3,590; makefile: 1,372; xml: 120; awk: 29
file content (106 lines) | stat: -rw-r--r-- 3,286 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
------------------------------------------------------------------------------
--  Thin Ada95 binding to OCI (Oracle Call Interface)                    --
--  Copyright (C) 2000-2004 Dmitriy Anisimkov.                              --
--  License agreement and authors contact information are in file oci.ads   --
------------------------------------------------------------------------------

--  $Id: blocking.adb,v 1.8 2006/12/10 09:29:35 merdmann Exp $

--  Example of the non blocking execution.

with
   Ada.Text_IO,
   OCI.Thick.OCINumber_Var,
   OCI.Thick.Number_Functions,
   OCI.Thick.Servers,
   OCI.Thick.Connections,
   OCI.Thick.Statements;

procedure Blocking is
   use OCI.Thick;
   use Ada.Text_IO;

   Server : Servers.Server := Servers.Attach ("");
   --  Using the OCI.Thick.Servers package.
   --  Creating server attachment.
   --  Empty name mean local server.

   Connect1 : Connections.Connection := Connections.Logon
     (DB       => Server,
      User     => "scott",
      Password => "tiger");

   Connect2 : Connections.Connection := Connections.Logon
     (DB       => Server,
      User     => "scott",
      Password => "tiger");
   --  Using the OCI.Thick.Connections package.
   --  Logon to the database and creating database connection

   Connect3 : Connections.Connection := Connections.Logon
                                              (Server_Name => "",
                                               User        => "scott",
                                               Password    => "tiger");

   Stmt_Text : String
      :=   "declare" & ASCII.LF
         & "  Dt Date := Sysdate;" & ASCII.LF
         & "  J  Integer;" & ASCII.LF
         & "begin" & ASCII.LF
         & "   loop" & ASCII.LF
         & "      J := NVL (J, 0) + 1;" & ASCII.LF
         & "      exit when Sysdate - Dt > 1/24/3600;" & ASCII.LF
         & "   end loop;" & ASCII.LF
         & "   :J := NVL (:J, 0) + 1;" & ASCII.LF
         & "end;" & ASCII.LF;

   Stmt : Statements.Statement := Statements.Prepare (Stmt_Text);
   --  Prepearing statement.
   --  OCI is prepearing statements without any communication with a server.

   J : OCINumber_Var.Variable;

begin
   --  We can see the server version information.

   Put_Line (Servers.Server_Version (Server));
   New_Line;

   Servers.Set_Blocking (Server, False);

   OCINumber_Var.Bind (Stmt, J, "J");

   loop
      Statements.Execute_And_Commit (Connect1, Stmt);
      exit when not Statements.Is_Executing (Stmt);
      Servers.Set_Blocking (Server, True);
      Put ('.');
      delay 0.1;
   end loop;

   Put_Line ("J = " & Number_Functions.To_String
                        (OCINumber_Var.Value (J), "9999999"));

   Servers.Set_Blocking (Server, False);

   loop
      Statements.Execute (Connect2, Stmt);
      exit when not Statements.Is_Executing (Stmt);
      Put ('.');
      delay 0.1;
   end loop;

   Put_Line ("J = " & Number_Functions.To_String
                        (OCINumber_Var.Value (J), "9999999"));

   loop
      Statements.Execute (Connect3, Stmt);
      exit when not Statements.Is_Executing (Stmt);
      Put ('.');
      delay 0.1;
   end loop;

   Put_Line ("J = " & Number_Functions.To_String
                        (OCINumber_Var.Value (J), "9999999"));

end Blocking;