Files
xahaud/doc/languages/ada/reference.html
Vinnie Falco 9708a12607 Squashed 'src/soci/' content from commit 6e9312c
git-subtree-dir: src/soci
git-subtree-split: 6e9312c4bb3748907bd28d62c40feca42878cfef
2015-03-18 19:36:00 -07:00

675 lines
23 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>SOCI-Ada - documentation</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1>SOCI-Ada - manual</h1>
<p class="section"><b>API Reference</b></p>
<p>
The SOCI-Ada library is entirely implemented as a single package named
<code>SOCI</code>. Additional child packages contain single procedures
for static registration of backends - these child packages are not
necessary for typical use, but can be useful to force static
linking of backend code.
</p>
<p>
The following describes all publicly visible elements of this package:
</p>
<hr />
<pre class="example">
--
-- General exception related to database and library usage.
--
Database_Error : exception;
</pre>
<p>
Each problem related to the interaction with the database or to the incorrect usage of the library itself is signalled by raising this exception. Each occurrence of this exception has some human-readable error message that can be obtained by a call to <code>Ada.Exceptions.Exception_Message</code>.
</p>
<hr />
<pre class="example">
--
-- Session.
--
type Session is tagged limited private;
not overriding
function Make_Session (Connection_String : in String) return Session;
not overriding
procedure Open (This : in out Session; Connection_String : in String);
not overriding
procedure Close (This : in out Session);
not overriding
function Is_Open (This : in Session) return Boolean;
</pre>
<p>
The <code>Session</code> object can exist in two states: "connected" (or "open") and "disconnected". It can be created as connected at initialization time with a call to the constructor function <code>Make_Session</code> or left default-initialized in the disconnected state and later changed to connected with <code>Open</code> (the latter option is the only that is available in the Ada 95 version of the library). <code>Session</code> objects can be also associated with the connection pool, see below.
</p>
<p>
The <code>Connection_String</code> should have the form <code>"backendname://parameters"</code>, where <code>backendname</code> is used to construct the name of the dynamically loadable library that will be used to provide specific database services. Backends included in the current distribution of the main SOCI library are:
</p>
<ul>
<li><code>oracle</code> (implemented as <code>libsoci_oracle.so</code> or <code>libsoci_oracle.dll</code>)</li>
<li><code>postgresql</code> (implemented as <code>libsoci_postgresql.so</code> or <code>libsoci_postgresql.dll</code>)</li>
<li><code>mysql</code> (implemented as <code>libsoci_mysql.so</code> or <code>libsoci_mysql.dll</code>)</li>
</ul>
<p>
Other backends can be added to the library in the future or by the user himself, please see the documentation of the main SOCI library for details.
</p>
<p>
The <code>parameters</code> component of the <code>Connection_String</code> depends on the given backend, please see the documentation of the main SOCI project for the meaning and recognized options. The web pages related to the backends above are:
</p>
<ul>
<li>Oracle: <a href="http://soci.sourceforge.net/doc/backends/oracle.html" target="_blank">http://soci.sourceforge.net/doc/backends/oracle.html</a></li>
<li>PostgreSQL: <a href="http://soci.sourceforge.net/doc/backends/postgresql.html" target="_blank">http://soci.sourceforge.net/doc/backends/postgresql.html</a></li>
<li>MySQL: <a href="http://soci.sourceforge.net/doc/backends/mysql.html" target="_blank">http://soci.sourceforge.net/doc/backends/mysql.html</a></li>
</ul>
<p>
The <code>Open</code> operation can be called only in the disconnected state (which changes the state of <code>Session</code> object to connected). The <code>Close</code> operation can be called in any state (provided that the session is not associated with the connection pool, see below) and after that the <code>Session</code> is in the disconnected state.
</p>
<p>
<code>Session</code> objects are closed automatically as part of their finalization. If the <code>Session</code> object is associated with the connection pool, the finalizer detaches from the pool without closing the connection.
</p>
<hr />
<pre class="example">
-- Transaction management.
not overriding
procedure Start (This : in Session);
not overriding
procedure Commit (This : in Session);
not overriding
procedure Rollback (This : in Session);
</pre>
<p>
These operations handle transactions. The exact meaning of transactions and whether transactions are automatic for some kinds of statements (and which ones) depend on the target database.
</p>
<hr />
<pre class="example">
-- Immediate query execution.
not overriding
procedure Execute (This : in Session; Query : in String);
</pre>
<p>
This operation allows to create implicit statement, prepare it for the given <code>Query</code> and execute it.
</p>
<hr />
<pre class="example">
--
-- Connection pool management.
--
type Connection_Pool (Size : Positive) is tagged limited private;
not overriding
procedure Open
(This : in out Connection_Pool;
Position : in Positive;
Connection_String : in String);
not overriding
procedure Close (This : in out Connection_Pool; Position : in Positive);
not overriding
procedure Lease (This : in out Connection_Pool; S : in out Session'Class);
</pre>
<p>
The <code>Connection_Pool</code> encapsulates a fixed-size collection of sessions. Individual sessions are indexed from <code>1</code> to <code>Size</code> (provided as discriminant) and can be <code>Open</code>ed and <code>Close</code>d explicitly. Each connection in the pool can be created with different <code>Connection_String</code>, if needed.
</p>
<p>
The <code>Lease</code> operation allows to associate a given <code>Session</code> object (that has to be in the disconnected state itself) with one connection from the pool. The pool guarantees that at most one task can lease a given connection from the pool. If there are no free connections in the pool, the <code>Lease</code> operation will block waiting until some connection is freed.
</p>
<p>
The <code>Session</code> object that is associated with a connection from the pool automatically gives it back to pool as part of the <code>Session</code>'s finalizer. There is no other way to "detach" from the pool.
</p>
<div class="note">
<p><span class="note">Note:</span></p>
<p>
It is assumed that the lifetime of <code>Connection_Pool</code> encloses the lifetimes of all <code>Session</code> objects that are leased from it. There is no particular protection against it and it is possible to construct a code example with allocators that create partially overlapping <code>Connection_Pool</code> and <code>Session</code>, but this is considered obscure and not representative to the actual use scenarios. To avoid any potential problems, create <code>Connection_Pool</code> in the scope that encloses the scopes of leased <code>Session</code>s.
</p>
</div>
<hr />
<pre class="example">
--
-- Statement.
--
type Statement (&lt;&gt;) is tagged limited private;
type Data_State is (Data_Null, Data_Not_Null);
type Into_Position is private;
type Vector_Index is new Natural;
</pre>
<p>
The <code>Statement</code> type and supporting types. <code>Data_State</code> is used to indicate null values in the database sense - each value of into or use elements has a state from this type.
</p>
<p>
<code>Into_Position</code> is used to identify into elements. <code>Vector_Index</code> is used to name individual entries in vector into and use elements.
</p>
<hr />
<pre class="example">
not overriding
function Make_Statement (Sess : in Session'Class) return Statement;
-- Ada 95 version:
-- procedure Make_Statement (This : in out Statement; Sess : in Session'Class);
</pre>
<p>
Construction function for creating <code>Statement</code> objects. The <code>Statement</code> is associated with one <code>Session</code> for its whole lifetime.
</p>
<hr />
<pre class="example">
-- Statement preparation and execution.
not overriding
procedure Prepare (This : in Statement; Query : in String);
not overriding
procedure Execute
(This : in Statement;
With_Data_Exchange : in Boolean := False);
not overriding
function Execute
(This : in Statement;
With_Data_Exchange : in Boolean := False) return Boolean;
not overriding
function Fetch (This : in Statement) return Boolean;
not overriding
function Got_Data (This : in Statement) return Boolean;
</pre>
<p>
The <code>Prepare</code> operation needs to be called before any other operation in the above group and it prepares the execution for the given <code>Query</code>. No into and use elements can be created after this operation is called.
</p>
<p>
The <code>Execute</code> operations cause the statement to execute, which might be combined with data exchange if requested. The function version of this operation returns <code>True</code> if some data has been returned back from the database server.
</p>
<p>
The <code>Fetch</code> function is used to transfer next portion of data (a single row or a whole bunch) from the database server and returns <code>True</code> if some data has been fetched. If this function returns <code>False</code> it means that no new data will be ever fetched for this statement and indicates the end-of-row condition.
</p>
<p>
The <code>Got_Data</code> function returns <code>True</code> if the last execution or fetch resulted in some data being transmitted from the database server.
</p>
<hr />
<pre class="example">
--
-- Data items handling.
--
-- Database-specific types.
-- These types are most likely identical to standard Integer,
-- Long_Long_Integer and Long_Float, but are defined distinctly
-- to avoid interfacing problems with other compilers.
type DB_Integer is new Interfaces.C.int;
type DB_Long_Long_Integer is new Interfaces.Integer_64;
type DB_Long_Float is new Interfaces.C.double;
</pre>
<p>
The data types used for interaction with the database are:
</p>
<ul>
<li><code>String</code></li>
<li><code>DB_Integer</code>, defined above</li>
<li><code>DB_Long_Long_Integer</code>, defined above</li>
<li><code>DB_Long_Float</code>, defined above</li>
<li><code>Ada.Calendar.Time</code></li>
</ul>
<hr />
<pre class="example">
-- Creation of single into elements.
not overriding
function Into_String (This : in Statement) return Into_Position;
not overriding
function Into_Integer (This : in Statement) return Into_Position;
not overriding
function Into_Long_Long_Integer (This : in Statement) return Into_Position;
not overriding
function Into_Long_Float (This : in Statement) return Into_Position;
not overriding
function Into_Time (This : in Statement) return Into_Position;
</pre>
<p>
These functions instruct the library to create internal simple into elements of the relevant type. They return the position of the into element, which can be later used to identify it.
</p>
<div class="note">
<p><span class="note">Note:</span></p>
<p>
Simple into elements cannot be created together with vector into elements for the same statement.
</p>
</div>
<hr />
<pre class="example">
-- Creation of vector into elements.
not overriding
function Into_Vector_String (This : in Statement) return Into_Position;
not overriding
function Into_Vector_Integer (This : in Statement) return Into_Position;
not overriding
function Into_Vector_Long_Long_Integer (This : in Statement) return Into_Position;
not overriding
function Into_Vector_Long_Float (This : in Statement) return Into_Position;
not overriding
function Into_Vector_Time (This : in Statement) return Into_Position;
</pre>
<p>
These functions instruct the library to create internal vector into elements of the relevant type. They return the position of the into element, which can be later used to identify it.
</p>
<div class="note">
<p><span class="note">Note:</span></p>
<p>
Vector into elements are empty (they have size 0) after they are created and have to be resized before any data is written to them.
</p>
</div>
<div class="note">
<p><span class="note">Note:</span></p>
<p>
Simple into elements cannot be created together with vector into elements for the same statement.
</p>
</div>
<hr />
<pre class="example">
-- Inspection of single into elements.
not overriding
function Get_Into_State
(This : in Statement;
Position : in Into_Position)
return Data_State;
not overriding
function Get_Into_String
(This : in Statement;
Position : in Into_Position)
return String;
not overriding
function Get_Into_Integer
(This : in Statement;
Position : in Into_Position)
return DB_Integer;
not overriding
function Get_Into_Long_Long_Integer
(This : in Statement;
Position : in Into_Position)
return DB_Long_Long_Integer;
not overriding
function Get_Into_Long_Float
(This : in Statement;
Position : in Into_Position)
return DB_Long_Float;
not overriding
function Get_Into_Time
(This : in Statement;
Position : in Into_Position)
return Ada.Calendar.Time;
</pre>
<p>
These functions allow to inspect the state and value of the simple into element identified by its position. If the state of the given element is <code>Data_Null</code>, the data-reading functions raise exceptions for that element.
</p>
<hr />
<pre class="example">
-- Inspection of vector into elements.
not overriding
function Get_Into_Vectors_Size (This : in Statement) return Natural;
not overriding
function Into_Vectors_First_Index (This : in Statement) return Vector_Index;
not overriding
function Into_Vectors_Last_Index (This : in Statement) return Vector_Index;
not overriding
procedure Into_Vectors_Resize (This : in Statement; New_Size : in Natural);
</pre>
<p>
The <code>Get_Into_Vectors_Size</code> returns the number of entries in any of the vector into elements for the given statement.
</p>
<p>
The <code>Into_Vectors_First_Index</code> returns the lowest index value for vector into elements (which is always <code>0</code>, even if the vectors are empty). The <code>Into_Vectors_Last_Index</code> returns the last index of into vectors, and raises the <code>CONSTRAINT_ERROR</code> exception if the vectors are empty.
</p>
<p>
The <code>Into_Vectors_Resize</code> procedure allows to change the size of all use vectors for the given statement.
</p>
<hr />
<pre class="example">
not overriding
function Get_Into_Vector_State
(This : in Statement;
Position : in Into_Position;
Index : in Vector_Index)
return Data_State;
not overriding
function Get_Into_Vector_String
(This : in Statement;
Position : in Into_Position;
Index : in Vector_Index)
return String;
not overriding
function Get_Into_Vector_Integer
(This : in Statement;
Position : in Into_Position;
Index : in Vector_Index)
return DB_Integer;
not overriding
function Get_Into_Vector_Long_Long_Integer
(This : in Statement;
Position : in Into_Position;
Index : in Vector_Index)
return DB_Long_Long_Integer;
not overriding
function Get_Into_Vector_Long_Float
(This : in Statement;
Position : in Into_Position;
Index : in Vector_Index)
return DB_Long_Float;
not overriding
function Get_Into_Vector_Time
(This : in Statement;
Position : in Into_Position;
Index : in Vector_Index)
return Ada.Calendar.Time;
</pre>
<p>
These functions allow to inspect the state and value of the vector use element identified by its position and index. If the state of the given element is <code>Data_Null</code>, the data-reading functions raise exceptions for that element.
</p>
<hr />
<pre class="example">
-- Creation of single use elements.
not overriding
procedure Use_String (This : in Statement; Name : in String);
not overriding
procedure Use_Integer (This : in Statement; Name : in String);
not overriding
procedure Use_Long_Long_Integer (This : in Statement; Name : in String);
not overriding
procedure Use_Long_Float (This : in Statement; Name : in String);
not overriding
procedure Use_Time (This : in Statement; Name : in String);
</pre>
<p>
These functions instruct the library to create internal simple use elements of the relevant type, identified by the given <code>Name</code>.
</p>
<div class="note">
<p><span class="note">Note:</span></p>
<p>
Simple use elements cannot be created together with vector use elements for the same statement.
</p>
<p>
Vector use elements cannot be created together with any into elements for the same statement.
</p>
</div>
<hr />
<pre class="example">
-- Creation of vector use elements.
not overriding
procedure Use_Vector_String (This : in Statement; Name : in String);
not overriding
procedure Use_Vector_Integer (This : in Statement; Name : in String);
not overriding
procedure Use_Vector_Long_Long_Integer (This : in Statement; Name : in String);
not overriding
procedure Use_Vector_Long_Float (This : in Statement; Name : in String);
not overriding
procedure Use_Vector_Time (This : in Statement; Name : in String);
</pre>
<p>
These functions instruct the library to create internal vector use elements of the relevant type, identified by the given <code>Name</code>.
</p>
<div class="note">
<p><span class="note">Note:</span></p>
<p>
Simple use elements cannot be created together with vector use elements for the same statement.
</p>
<p>
Vector use elements cannot be created together with any into elements for the same statement.
</p>
</div>
<hr />
<pre class="example">
-- Modifiers for single use elements.
not overriding
procedure Set_Use_State
(This : in Statement;
Name : in String;
State : in Data_State);
not overriding
procedure Set_Use_String
(This : in Statement;
Name : in String;
Value : in String);
not overriding
procedure Set_Use_Integer
(This : in Statement;
Name : in String;
Value : in DB_Integer);
not overriding
procedure Set_Use_Long_Long_Integer
(This : in Statement;
Name : in String;
Value : in DB_Long_Long_Integer);
not overriding
procedure Set_Use_Long_Float
(This : in Statement;
Name : in String;
Value : in DB_Long_Float);
not overriding
procedure Set_Use_Time
(This : in Statement;
Name : in String;
Value : in Ada.Calendar.Time);
</pre>
<p>
These operations allow to modify the state and value of simple use elements. Setting the value of use element automatically sets its state to <code>Data_Not_Null</code>.
</p>
<hr />
<pre class="example">
-- Modifiers for vector use elements.
not overriding
function Get_Use_Vectors_Size (This : in Statement) return Natural;
not overriding
function Use_Vectors_First_Index (This : in Statement) return Vector_Index;
not overriding
function Use_Vectors_Last_Index (This : in Statement) return Vector_Index;
not overriding
procedure Use_Vectors_Resize (This : in Statement; New_Size : in Natural);
</pre>
<p>
The <code>Get_Use_Vectors_Size</code> returns the number of entries in any of the vector use elements for the given statement.
</p>
<p>
The <code>Use_Vectors_First_Index</code> returns the lowest index value for vector use elements (which is always <code>0</code>, even if the vectors are empty). The <code>Use_Vectors_Last_Index</code> returns the last index of use vectors, and raises the <code>CONSTRAINT_ERROR</code> exception if the vectors are empty.
</p>
<p>
The <code>Use_Vectors_Resize</code> procedure allows to change the size of all use vectors for the given statement.
</p>
<hr />
<pre class="example">
not overriding
procedure Set_Use_Vector_State
(This : in Statement;
Name : in String;
Index : in Vector_Index;
State : in Data_State);
not overriding
procedure Set_Use_Vector_String
(This : in Statement;
Name : in String;
Index : in Vector_Index;
Value : in String);
not overriding
procedure Set_Use_Vector_Integer
(This : in Statement;
Name : in String;
Index : in Vector_Index;
Value : in DB_Integer);
not overriding
procedure Set_Use_Vector_Long_Long_Integer
(This : in Statement;
Name : in String;
Index : in Vector_Index;
Value : in DB_Long_Long_Integer);
not overriding
procedure Set_Use_Vector_Long_Float
(This : in Statement;
Name : in String;
Index : in Vector_Index;
Value : in DB_Long_Float);
not overriding
procedure Set_Use_Vector_Time
(This : in Statement;
Name : in String;
Index : in Vector_Index;
Value : in Ada.Calendar.Time);
</pre>
<p>
These operations allow to modify the state and value of vector use elements. Setting the value of use element automatically sets its state to <code>Data_Not_Null</code>.
</p>
<hr />
<pre class="example">
-- Inspection of single use elements.
--
-- Note: Use elements can be modified by the database if they
-- are bound to out and inout parameters of stored procedures
-- (although this is not supported by all database backends).
-- This feature is available only for single use elements.
not overriding
function Get_Use_State
(This : in Statement;
Name : in String)
return Data_State;
not overriding
function Get_Use_String
(This : in Statement;
Name : in String)
return String;
not overriding
function Get_Use_Integer
(This : in Statement;
Name : in String)
return DB_Integer;
not overriding
function Get_Use_Long_Long_Integer
(This : in Statement;
Name : in String)
return DB_Long_Long_Integer;
not overriding
function Get_Use_Long_Float
(This : in Statement;
Name : in String)
return DB_Long_Float;
not overriding
function Get_Use_Time
(This : in Statement;
Name : in String)
return Ada.Calendar.Time;
</pre>
<p>
These functions allow to inspect the state and value of the simple use element identified by its name. If the state of the given element is <code>Data_Null</code>, the data-reading functions raise exceptions for that element.
</p>
<table class="foot-links" border="0" cellpadding="2" cellspacing="2">
<tr>
<td class="foot-link-left">
<a href="idioms.html">Idioms</a>
</td>
<td class="foot-link-right">
</td>
</tr>
</table>
<p class="copyright">Copyright &copy; 2008-2011 Maciej Sobczak</p>
</body>
</html>