From: Michael Erdmann <michael.erdmann@snafu.de>
Subject: Re: Call for review: Database API for the GNADE Project
Date: Fri, 04 Jan 2002 18:44:49 +0100
Date: 2002-01-04T18:44:49+01:00 [thread overview]
Message-ID: <3C35EA10.F541E91E@snafu.de> (raw)
In-Reply-To: a10veu$8ht$1@shell.monmouth.com
Kenneth Almquist schrieb:
> Michael Erdmann <michael.erdmann@snafu.de> wrote:
>
> > X : Connection.Object;
> > Connect(X);
> > declare
> > q : Query.Object( X );
> > begin
> > Statement( q, "select * from employees where name = ?" );
> > Bind( q, 1, Name );
> > Execute( q );
> > .....
> > end ;
>
> I wonder if replacing the various Bind procedures with generic
> packages would be better:
>
> declare
> Statement : constant SQL_Statement
> := Prepare(Connection, "select * from employees where empno = ?");
> package Empno is new Set_Statement_Integer(Statement, 1);
> begin
> Empno.Set(Name);
> Result := Execute_Query(Statement);
> ...
I agree on this. The problem might be in the future that i have to handle the
null indicator in a save way which means there will be for each data type hidden
variables. Then the best aproach of doing it will be a generic package which
takes the Ada 95 type and provides a save encapsulation of these hidden
parameter. Such a package will have to provide the following procdures/funtions:
Value - Returns or set the value
Is_Null - Item is null
x : integer
package integer_vars is new package( type => integer );
use package;
.....
Integer_Vars.Bind( x, 1, statement );
> Set_Statement_Integer is a generic package containing a single procedure
> named Set. We use a generic package rather than a generic procedure
> so that we can perform validity checking when the package is instantiated,
> rather than performing a check every time a new value is assigned to
> empno.
>
> I've changed Execute to Execute_Query because when we execute a query
> we get back a set of results, whereas when we execute other types of
> SQL statements we get back a status code.
>
> > result := Execute( statement );
> > while not End_of( result ) loop
> > row := Fetch( result );
> > name := Get( row, 1 );
> > boss := Get( row, 2 );
> > .......
> > loop;
>
> Is the row value valid after a subsequent fetch operation? If not,
> we could eliminate the row variable and get the fields of the current
> row directly from the result variable.
>
> Again, generics might be useful to get the row numbers out of the code:
>
> declare
> Row : SQL_Row;
> function Get_Name is new Get_Row_String(1);
> function Has_Boss is new Get_Row_Is_Null(2);
> function Get_Boss is new Get_Row_Integer(2);
> begin
> ...
> Row := Fetch(Result);
> Name := Get_Name(Row);
> if Has_Boss(Row) then
> Boss := Get_Boss(Row);
> else
> Put_Line("The CEO does not have a boss");
> end if;
> ...
I have to admit, this realy looks better!
>
>
> > Mode: The fetch mode controls the behavior of the cursor in the
> > result set. Modes are: Forward, Backward.
> As far as I know, this is not supported by standard SQL, and I can't
> think of a reason why anyone would need this.
There are somtimes applications which like to browse through
result sets. A lot of native data base bindings and ODBC support
this.
> > If the server drops the connection the procedure Disconnection_Event is
> > called. In order to implement specific behavior, the procedure may be
> > overloaded.
>
> If I understand correctly, Server_Error will be raised after this
> procedure is called. It seems like this procedure is unnecessary,
> since anything done by this procedure could instead be done by an
> exception handler.
Yes, this was just an option i wanted to provide. But you are right you can
do the same thing capturing the exception. I think i wil remove it because
i made the experience that with such procedure it is quite difficult to
communicate data into them unless you are using some kind of
global data areas!
>
>
> I hope these random thoughts are helpful.
> Kenneth Almquist
Yes, I realy apreciate your effort. I will do the update today! Please keep
an eye on http://gnade.sourceforge.net/ to seen what happens.
Michael
next prev parent reply other threads:[~2002-01-04 17:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3C2E334F.EF4C534@snafu.de>
2001-12-31 3:26 ` Call for review: Database API for the GNADE Project Nick Roberts
2002-01-01 9:45 ` Michael Erdmann
2002-01-01 22:55 ` Nick Roberts
2002-01-02 14:31 ` Michael Erdmann
2002-01-02 23:34 ` Nick Roberts
2002-01-03 6:58 ` Kenneth Almquist
2002-01-04 17:44 ` Michael Erdmann [this message]
2002-01-06 12:58 ` Julio Cano
2002-01-06 21:14 ` Michael Erdmann
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox