Re: Ada DB bindings and APQ

From: Brian May (bam_at_snoopy.apana.org.au)
Date: 12/17/04


Date: Fri, 17 Dec 2004 15:55:44 +1100


>>>>> "Warren" == Warren W Gay VE3WWG <ve3wwg@NoSpam.cogeco.ca> writes:

    Warren> I like the neatness of this approach, but the danger is
    Warren> that you might do the "..." part on a row that might
    Warren> not exist. Though I suppose the Query_Type object could
    Warren> maintain enough state such that it can raise an exception
    Warren> if any "Values" were fetched from the row that is not there.
    Warren> Just a quibble: I'd prefer something like "No_Row(Q)" perhaps.

    Warren> An even neater loop is this, IMHO ;-)

>> loop
>> Fetch(Q);
>> exit when No_More_Data(Q);
>>
>> ...
>> end loop;

How about

Valid_Row : Boolean;

loop
        Fetch(Q, Valid_Row);
        exit when not Valid_Row;
        ...
end loop;

Where Valid_Row is an out variable from Fetch.

This would avoid breaking any existing software, and make it obvious
that Valid_Row has to be checked.

I suspect this should work regardless of what the database is.

Other questions that might be significant, especially to some of my
proposed changes.

1. What happens if an unexpected exception occurs within the above
   loop, and it prevents continuing the loop. In fact, the code that
   handles the exception may not realize it occurred in middle of the
   fetch operation. Is there any way of recovering the database
   connection?

2. With Mysql what happens if I do this:

declare
        Q1 : Root_Query_Type'Class := New_Query(C);
        Q2 : Root_Query_Type'Class := New_Query(C);
begin
        Prepare(Q1, ...);
        Prepare(Q2, ...)

        Set_Fetch_Mode(Q1, Sequential_Fetch);
        Set_Fetch_Mode(Q2, Sequential_Fetch);

        Execute(Q1, C);
        Execute(Q2, C);

        loop
                Fetch(Q1);
                Fetch(Q2);
                ...
        end loop;
end;

Will this work, trigger an error, or will it kill the Mysql connection
as requests are intermixed?

-- 
Brian May <bam@snoopy.apana.org.au>


Relevant Pages

  • Re: Ada DB bindings and APQ
    ... > end loop; ... > Where Valid_Row is an out variable from Fetch. ... What happens if an unexpected exception occurs within the above ... An unexpected error would raise SQL_Error. ...
    (comp.lang.ada)
  • Re: Ada DB bindings and APQ
    ... > supported on sequential connections, because it is not known if all ... > tuples have been fetched until you try to fetch the next one past the ... > condition for a loop. ... Fetch would raise an exception (it cannot be ...
    (comp.lang.ada)
  • Re: long double versions of functions in gcc under Cygwin
    ... rather than the nearest enclosing one) and a decent exception ... them it doesn't seem like goto usage would be affected ... int typfun() ... Why use a for loop when it is just a while loop in disguise? ...
    (comp.lang.c)
  • Re: CInternetSession
    ... the presence of the Sleepindicates the serious design flaw. ... Sleep() calls around like pixie dust, your design is fundamentally broken and will need to ... If you use Sleepin a loop, your design is probably wrong and needs to be ... The "First Chance Exception" message usually indicates nothing harmful. ...
    (microsoft.public.vc.mfc)
  • Re: Get_Line problem (GNAT bug?)
    ... Now, if the program specs says: "read the lines from input until EOF", then this for me immediately translates into a loop with some exit condition. ... "Read until" - you have a regular end-of-sequence condition here. ... I'm not convinced that exception might be a correct design choice for breaking the loop that reads data from well formatted file. ...
    (comp.lang.ada)