comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Windows Ada database support.
Date: Tue, 7 Dec 2004 11:29:13 +0100
Date: 2004-12-07T11:29:13+01:00	[thread overview]
Message-ID: <r5p1mpfyyji4.1nd60cmilikqn.dlg@40tude.net> (raw)
In-Reply-To: I%atd.1534$4t5.727@read1.cgocable.net

On Tue, 07 Dec 2004 00:16:21 -0500, Warren W. Gay VE3WWG wrote:

> Dmitry A. Kazakov wrote:
>> On Mon, 06 Dec 2004 12:52:40 -0500, Warren W. Gay VE3WWG wrote:

>> Also we should distinguish two cases:
>> 
>> A. Some Ada application stores its data in a database. The way the data are
>> organized there is free.
> 
> Its not clear to me what you mean by "free" here.

It means that bindings (the driver) are free to choose the most suitable
implementation. The application describes what it needs and the driver
implements it using available gears. It is not guaranteed that the
schemata, types etc will be same for other data bases or on other
platforms.

>> B. Accessing existing (but unknown at design time) data base. The data
>> structure is fixed and the application must adapt to it.
> 
> I think I know the two points you are raising, but it isn't
> clear which is A or B.
> 
>> A is much easier than B. Not everybody needs B. Further B is often bound to
>> some concrete data base, in which case data base specific bindings make
>> much sense. So we could ignore B for a while. At least until it will be
>> clear how to provide at least A.
> 
> If in one case you mean a package capable of being used in a GUI
> tool, where it can connect to the database and discover tables,
> keys, indexes, views, triggers and the like, and allow dynamic
> operations without any foreknowledge, then agreed, this is much
> more difficult. This is even more of a nightmare approach wise,
> because the standard(s) never addressed this need - hence every
> vendor implements this functionality they way they see fit.

Yes, this would be B.

> While the above is import (for tools), application needs are usually
> much simpler. Written to do fixed operations, on a fixed set of
> tables, views and stored procedures. But as I've pointed out,
> even this simpler case is complex in a multi-vendor world.

I think that static vs. dynamic difference is rather marginal. Essential is
who must adapt to whom, i.e. A vs. B.

>>>Related to this same issue is how to identify rows that lack
>>>a natural primary key. Some databases support an identity
>>>type for the purpose (Sybase), while others use sequences.
>>>Still others like MySQL use some weird idea of an auto
>>>increment integer field (I am too lazy to look up the
>>>specifics for this, but this is documented in the APQ
>>>manual).
>>>
>>>Here's another good one: Some databases allow you to declare
>>>a VARCHAR(256). Others are restricted to VARCHAR(255), and you
>>>must switch to a different type (TEXT I think), if you need
>>>longer fields.
>>>
>>>Some support boolean types, and others do not. Some support
>>>arrays, others do not. If they both support arrays, they
>>>are guaranteed to work with different rules and syntax.
>>>
>>>There seems to be virtually no agreement on how blobs are
>>>handled and managed, between the different products.
>> 
>> This is the case B. 
> 
> Blobs?
>
>>I think that it could still be possible to solve it in
>> an OO way. 
> 
> I beg to differ on this one, though I've not tried very
> hard on this one ;-)  Consider some of the challenges:
> 
> 1) PostgreSQL uses an API that opens/creates etc. and returns
>     an OID.
> 2) PostgreSQL blobs are referenced by saving a OID in a column
>     of a row.
> 3) ALL PostgreSQL blob operations must occur within the confines
>     of a transaction (otherwise the operation fails!)
> 4) MySQL (IIRC), wants you to put the entire blob into a
>     row.
> 5) MySQL, IIRC, wants you to perform the blob I/O in one
>     operation and IIRC, doesn't care about transactions (optional).
> 6) PostgreSQL blobs can be operated on like files, with seeks,
>     partial writes, reads etc.

In the case A it is up to the driver what (and if) it would use for some
given type. The driver of a database X knows how to deal with large
objects. If, say, a Postres driver decides that the type Baz should be
stored as a blob, then it should add all necessary bells and whistles
transparent to the application. Compare: in 99.9% cases I do not care if
and how the Ada compiler creates dopes for my arrays.

Also I wouldn't be much surprised if users of the A-bindings will never
store giant indigestible objects into a data base. It is not the Ada's way,
after all. What is stored as blobs, usually has some finer internal
structure, which appears too complex to map it into data base things.
Provided that this need to be made manually. Being automated via A-bindings
it might turn very different.

> I seem to recall there were more problems, but when I started
> with this list, I decided to leave it for a rainy day!!! ;-)
> 
>> All database types should be derived from one base. Factory can
>> be used to create values "like in the column". Differences between VARCHAR,
>> TEXT, LONGCHAR etc are uninteresting for the application. 
> 
> You might expect so, but the Boolean case and Dates have created
> a lot of problem. Since you have to work with SQL, how do you
> satisfy databases that want 0 and 1 for Booleans (or bit?),
> and the more nomal ones that that True and False?

That would be the case B! For A, the application will just use say
Ada.Database.Relational.Boolean, which the driver will translate into the
most appropriate type for the data base it supports: SMALLINT, CHAR, BIT,
whatsoever available.

> I sheltered the application to some degree from this in APQ,
> but allowing the fields to be encoded for you (APQ knows
> in the MySQL case it wants 0 and 1 - I think it was MySQL).
> But this problem still pokes out in places like hardcoded WHERE
> clauses :
> 
> ...
> WHERE MARRIED = False and ...
> 
> or
> 
> WHERE MARRIED = 0 and ...
> 
> So if MARRIED is BOOLEAN, I think you have to test if you
> are using MySQL (I think it was them), and then use the 0
> and 1 instead (or use APQ to encode a hardcoded False!)
> 
> Dates, Timestamps and timezones get even more interesting.
> Versions of databases add to the problems! MySQL in one
> version formats the dates differently than later versions
> -- ugh!

This is exactly why I would like to get rid of any traces of SQL in the
bindings. The interface should provide an iterator. The iteration filter
will be an object describing the filtering condition. That will be
translated by the driver into SQL's WHERE ... with all literals selected as
required. ODBC does it well for ?-parameters in prepared statements. (SQL
is the evil! (:-))

>> In general I do not think that primitive data types are the greatest
>> problem. The problem is that the semantics of "what and how" slips away. It
>> is too low level.
> 
> I think you would be surprised! Just sticking to "normal"
> primitive data types in APQ, has had me see enough horrors ;-)

I am not. For example with ODBC, you have to ask the driver what it has
today for say GUID. Let it answers: sorry. What would your application do?
Emulate GUID using BIGINT, TIMESTAMP? ODBC is just irreparably wrong!

>>>The list of incompatibilities and differences are many
>>>more. For example, there are differences in the way the
>>>client libraries work (ability to fetch one row at a time,
>>>randomly or not (PostgreSQL), must fetch them all into
>>>client memory for random access, or use one-at-a-time
>>>sequential access (MySQL), etc.)
>>>
>>>The challenges for a "unified Ada access" layer are so
>>>numerous, that I consider it unachievable. I took a stab
>>>at providing a "portable" binding in APQ, but had to
>>>make various compromises along the way (these are documented
>>>in the manual).
>> 
>> I think that APQ could become an alternative to ODBC. ODBC tries to swallow
>> documents and spreadsheets (like Excel), things that are too far from a
>> "normal" data base.
> 
> Well, in fairness to ODBC, some sort of generalized interface
> was called for, and it was "a solution" of sorts. But I never
> felt it was meant to be used by application programmers.

My impression is that ODBC tried to be both A and B, and failed both.

> IMHO,
> any API that has application programmers coding a whole whack
> of complex API calls to just do a select and return a row (for
> example), is not "the solution". Application programmers want
> to focus on the application problem - not API details (most
> mediochre programmers can't get it right anyway). Once coded,
> it becomes so complex, that no one wants to make major changes
> to it. Then comes the patchwork!

Yes

> Many people feel that code generators are the answer. I disagree
> there also. That is a one-time fix. Eventually, someone has to
> go back and change it. At this point it is unreadable and near
> unmaintainable.

Yes

> APQ tries to make it simple for the application programmer. I
> would much rather be thinking in SQL and Ada terms, than trying
> trying to remember API calls. APQ's API tries to be self
> intuitive, and time will tell if it is or not.
> 
> This has been an interesting diversion ;-)

Yes!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2004-12-07 10:29 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-24 12:31 Windows Ada database support Mark Doherty
2004-11-24 15:04 ` Marius Amado Alves
2004-11-24 18:35 ` Pascal Obry
2004-11-24 19:17   ` Alex R. Mosteo
2004-11-24 19:30     ` Dmitry A. Kazakov
2004-11-24 22:32       ` Ching Bon Lam
2004-11-25  1:03 ` David Botton
2004-11-25 17:50   ` Warren W. Gay VE3WWG
2004-11-26  9:15     ` Dmitry A. Kazakov
2004-11-26 18:36       ` David Botton
2004-11-27  8:59         ` Dmitry A. Kazakov
2004-11-28  0:46           ` David Botton
2004-11-28  9:51             ` Dmitry A. Kazakov
2004-11-28 10:23               ` Pascal Obry
2004-11-28 11:03                 ` Dmitry A. Kazakov
2004-11-28 14:38                   ` Martin Dowie
2004-11-28 16:51                     ` Marius Amado Alves
2004-11-28 19:50                       ` Martin Dowie
2004-11-28 20:49                       ` Christopher Browne
2004-11-28 17:29                     ` Dmitry A. Kazakov
2004-11-28 17:47                       ` Marius Amado Alves
2004-11-28 18:56                         ` Dmitry A. Kazakov
2004-12-06 14:57                           ` Warren W. Gay VE3WWG
2004-11-28 18:45                   ` Pascal Obry
2004-11-28 19:13                     ` Dmitry A. Kazakov
2004-11-28 20:04                       ` Pascal Obry
2004-11-29  9:04                         ` Dmitry A. Kazakov
2004-11-29 10:07                         ` Adrien Plisson
2004-11-29 11:00                           ` Alex R. Mosteo
2004-11-29 13:12                             ` Frank Piron
2004-12-01 16:19                           ` Pascal Obry
2004-12-02 10:37                             ` Marius Amado Alves
2004-12-02 10:58                               ` Frank Piron
2004-12-03  2:50                               ` John B. Matthews
2004-11-28 20:36                     ` Marius Amado Alves
2004-11-29  1:40                       ` Georg Bauhaus
2004-11-29 10:30                         ` Marius Amado Alves
2004-11-29  1:28       ` Georg Bauhaus
2004-11-29  8:53         ` Dmitry A. Kazakov
2004-11-29 11:09           ` Georg Bauhaus
2004-11-29 12:01             ` Dmitry A. Kazakov
2004-11-29 14:07               ` Georg Bauhaus
2004-11-29 18:04                 ` Dmitry A. Kazakov
2004-11-29 22:05                   ` Georg Bauhaus
2004-11-30 11:00                     ` Dmitry A. Kazakov
2004-11-30 13:46                       ` Ole-Hjalmar Kristensen
2004-11-30 15:04                         ` Dmitry A. Kazakov
2004-11-30 16:09                         ` Georg Bauhaus
2004-11-30 16:07                       ` Georg Bauhaus
2004-11-30 18:52                         ` Dmitry A. Kazakov
2004-11-30 21:10                           ` Georg Bauhaus
2004-12-01  9:11                             ` Dmitry A. Kazakov
2004-11-29 12:56       ` Marius Amado Alves
2004-11-29 13:26         ` Dmitry A. Kazakov
2004-11-29 15:02       ` Frank Piron
2004-11-29 15:58         ` Marius Amado Alves
2004-11-29 18:16         ` Dmitry A. Kazakov
2004-11-30  7:14           ` Frank Piron
2004-12-06 14:48       ` Warren W. Gay VE3WWG
2004-12-06 16:29         ` Dmitry A. Kazakov
2004-12-06 17:52           ` Warren W. Gay VE3WWG
2004-12-06 19:44             ` Georg Bauhaus
2004-12-06 20:49             ` Dmitry A. Kazakov
2004-12-07  5:16               ` Warren W. Gay VE3WWG
2004-12-07 10:29                 ` Dmitry A. Kazakov [this message]
2004-12-07 15:49               ` Georg Bauhaus
2004-12-07 21:29                 ` Dmitry A. Kazakov
2004-12-08  2:24                   ` Georg Bauhaus
2004-12-08  9:05                     ` Dmitry A. Kazakov
2004-12-08 10:03                       ` Ole-Hjalmar Kristensen
2004-12-08 10:56                         ` Dmitry A. Kazakov
2004-12-08 11:19                           ` Marius Amado Alves
2004-12-08 12:51                             ` Frank Piron
2004-12-08 13:43                               ` Dmitry A. Kazakov
2004-12-08 13:41                             ` Dmitry A. Kazakov
2004-12-08 16:09                               ` Georg Bauhaus
2004-12-08 19:46                                 ` Dmitry A. Kazakov
2004-12-09 12:20                                   ` Georg Bauhaus
2004-12-09 12:59                                     ` Dmitry A. Kazakov
2004-12-08 15:58                           ` Georg Bauhaus
2004-12-08 19:43                             ` Dmitry A. Kazakov
2004-12-09 11:58                               ` Georg Bauhaus
2004-12-09 13:27                                 ` Dmitry A. Kazakov
2004-12-09 18:58                                   ` Georg Bauhaus
2004-12-10 10:22                                     ` Dmitry A. Kazakov
2004-12-10 14:28                                       ` Georg Bauhaus
2004-12-10 15:14                                         ` Dmitry A. Kazakov
2004-12-08 15:52                         ` Georg Bauhaus
2004-12-08 20:22                           ` Dmitry A. Kazakov
2004-12-09 12:12                             ` Georg Bauhaus
2004-12-09 12:59                               ` Dmitry A. Kazakov
2004-12-09 18:45                                 ` Georg Bauhaus
2004-12-09 12:22                             ` Ole-Hjalmar Kristensen
2004-12-09 14:03                               ` Dmitry A. Kazakov
2004-12-10 20:47                   ` Simon Wright
2004-11-25  2:18 ` bubble
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox