From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,72b10ed43fd78730 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-04 09:42:58 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!dispose.news.demon.net!demon!diablo.netcom.net.uk!netcom.net.uk!fr.clara.net!heighliner.fr.clara.net!unlisys!news.snafu.de!not-for-mail From: Michael Erdmann Newsgroups: comp.lang.ada Subject: Re: Call for review: Database API for the GNADE Project Date: Fri, 04 Jan 2002 18:44:49 +0100 Organization: http://purl.org/NET/michael.erdmann Message-ID: <3C35EA10.F541E91E@snafu.de> References: <3C2E334F.EF4C534@snafu.de> NNTP-Posting-Host: tc01-n70-217.de.inter.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.75 [de] (X11; U; Linux 2.2.16-22 i686) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:18548 Date: 2002-01-04T18:44:49+01:00 List-Id: Kenneth Almquist schrieb: > Michael Erdmann 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