Re: A nongeneric bounded string array type (in database code)

From: Warren W. Gay VE3WWG (ve3wwg_at_cogeco.ca)
Date: 10/16/03


Date: Thu, 16 Oct 2003 12:39:34 -0400

Robert I. Eachus wrote:
> Warren W. Gay VE3WWG wrote:
>
>> Ah, but "arbitrary number of matches" could mean billions of
>> rows! Do you really want to process columns that way? ;-)
>
> Ah, it could mean that, but, depending on the database, you can either
> ask for the number of records that match, or return at most say 50, and
> a count of how many more records remain. That is an implementation
> detail that the programmer needs to thing about and handle appropriately.

Yes, depending on the database indeed. But you see how easy it
is to forget that important detail? ;-) And databases vary
widely in that level of support (MySQL supports a LIMIT clause,
but many others do not).

Using a fetch loop that processes one row at a time is so
much easier (at least when possible). This eliminates the resource
issue. The CLIENT LIBRARY should already be handling the EFFICIENCY
aspects of fetching, in bunches of rows, thus freeing your code
from such implementation details.

If you insist on arrays at a time processing, then you
are usually focusing on efficiency, which is very implementation
minded design. This is what many Ada people try to get
away from (and certainly my focus).

There is another problem with the array approach. You start referring
to values by subscript (either by constant, variable or by number),
and that can lead to more possibilities for error. I suppose you
could use renaming, but you have to ask yourself why am I coding
all of these extra language constructs?

Whereas if you process a row at a time, you have no possibility
of mixing the wrong Customer_Name with another's Customer_Account.
Its readable, its simple and it can be strongly typed.

As a side note, your Ada_Strings_Bounded_Array package makes a
common mistake: it does not allow for the processing of NULL
values. This is one fault I see so frequently in embedded SQL
code, because the programmer never took the trouble to code
for that possibility. This leads to all sorts of hideous
problems when NULLs are encountered in processing. There is
no doubt that Ada_Strings_Bounded_Array could be augmented
to handle this, but does illustrate how this RDBMS feature
gets overlooked. Microsoft is another one that is guilty of
this in their database controls (try handling a null date
type in the date picker, for example ;-)

This is why in APQ, if the programmer doesn't allow for a NULL
value, he will get the appropriate exception raised. While this
is less than ideal (compile time errors would be better), it
does guarantee that it will get addressed if the NULL value
ever shows up and it was not anticipated.

If you take arrays to the further level of columns x rows, then
you have a 2-dimensional array to mess with -- which in my view
is very dangerous from a code readability/code-write-reliability
point of view. Don't get me wrong, arrays have their place.

But here I can't help but think that it is for programer
convenience and/or efficiency, which IMO is not the best
approach. No offense intended here, but this approach seems
to transport the "Perl way" into Ada code. ;-)

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


Relevant Pages

  • Re: When to use sub-values
    ... from the outset as if each discrete problem is a database problem -- ... "optimizations" are merely optimizations. ... within LOCATE (depending on the controlling-nesting levels you want to ... reimplemented our own simulated RDBMS to be able to store/retrieve/sort ...
    (comp.databases.pick)
  • Re: Lucid statement of the MV vs RM position?
    ... before database managment systems, much of Pick will be familiar to you. ... Dictionaries are ... mind of the end-users too. ... decoding the data ought to be in the mind of the programmer, ...
    (comp.databases.theory)
  • Re: MySQL Database problem (probably already solved in a message, but this is somewhat urgent)
    ... MySQL server has a database with a table, ... columns, an FSR column, and a password column. ... checked if the supposed arrays that were returned were actually arrays ...
    (comp.lang.php)
  • Re: Useful Utility or Not?
    ... >the most part static in content and whose main function is the support ... >programmer, I've spent significant hours coding in support of these ... the need to load tables into OCCURS has been ... Just read entries from the file or database. ...
    (comp.lang.cobol)
  • Re: MV Keys (was: Key attributes with list values)
    ... "the programmer knows what the data means". ... one of which was an entirely different database (and RDBMS) ... whose data was transferred at night by batch jobs. ...
    (comp.databases.theory)