Re: Ada DB bindings and APQ

From: Warren W. Gay VE3WWG (ve3wwg_at_NoSpam.cogeco.ca)
Date: 12/17/04


Date: Fri, 17 Dec 2004 06:13:47 -0500

Brian May wrote:
>>>>>>"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 like that idea.

> 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?

An unexpected error would raise SQL_Error (or somesuch). So
if you expect to recover from it, you must obviously be willing
to catch the exception at some level.

> 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?

I haven't tried this, but I know that PostgreSQL is supposed
to support this, and I believe it will. Whether MySQL and Sybase
can, I am not sure.

In MySQL's case, what I believe happens is that any Q2 rows that
are skipped over to fetch rows for Q1, will just be loaded
into the C client memory for later use. But I have not taken
the time to test this.

--
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg


Relevant Pages

  • 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: 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 ... Will this work, trigger an error, or will it kill the Mysql connection ...
    (comp.lang.ada)
  • Re: determining input data type
    ... -- But if the data is a packed buffer string then you could use ... -- In this case the best was is to use a loop and search for all ... Data_Error: exception; ... raise Data_Error; ...
    (comp.lang.ada)
  • Re: Riddle me this (a question about expressions)
    ... But raise does actually break out of the current frame (and the ... whole main loop) if it isn't rescued...mabye raise, ... enters to exception handler, shortcircuts the void assignment ... exception; or mabye it completes the assignment with nil, ...
    (comp.lang.ruby)
  • Re: is parameter an iterable?
    ... raise an exception, and you'll catch it during testing ... I don't want an exception, ... for val in iterator: ... # do loop stuff ...
    (comp.lang.python)