comp.lang.ada
 help / color / mirror / Atom feed
* Re: "Dynamic" object
  2000-03-06  0:00 "Dynamic" object Preben Randhol
@ 2000-03-06  0:00 ` Gisle S�lensminde
  2000-03-06  0:00   ` Preben Randhol
  0 siblings, 1 reply; 7+ messages in thread
From: Gisle S�lensminde @ 2000-03-06  0:00 UTC (permalink / raw)


Preben Randhol wrote:

>I'm wondering how to do the following in Ada 95.
>
>I want to have a small program as a frontend to a database. Thus the
>program needs to read the definition of the db and then generate the
>proper GUI for this. This I think I know how to to, but the problem is
>how do I define a type that contains the different fields so that I can
>put it in a linked list?
>
>Example:
>
>Field 1: First_Name (string of size 30)
>Field 2: Sirname    (string of size 40)
>Field 3: Age        (integer of size 3)
>...
>Field n: Address    (string of size 80)
>
>Any hints much appreciated.


I have some problem understanding what problem is. To get a more precise
answer (at least from me), you should give more details of your problem.

Is you problem:

1) The problem of making a type representing the data you describe,
   and put that in a linked list. (probably not, you would have
   figured that out yourself!) 

-- a type for your table entries

type table_entry is 
  record
    first_name : string(1..30);
    surname    : string(1..40);
    age        : natural;                          
    ....  
    address    : string(1..80);
  end record;

-- instaniate a generic linked list with your table entry type
package entrylist is new linked_lists(element => table_entry)


2) You have several kinds of tables, and want to make a hetrogenous 
list of table entries. Then you can make a controlled table type
holding a pointer to the actual data. The type is made controlled
to ease memory handling, it could have been just tagged. Since the 
different table entry types typically will have different sizes, 
I have used an access type poining to super_entry'class. 

with ada.finalization; use ada.finalization;

-- super type for all tables (not called entry for obvious reason :-)
type super_entry is tagged null record;

-- the table types, like in (1)
type table1_entry is new super_entry with record ... end record;
type table1_entry is new super_entry with record ... end record;
     
type entry_access is access table_entry'class;

type entry_holder is new controlled with
  record
     T : entry_access;
  end record;

package entrylists is new linked_lists(element => entry_holder);

Then you should implement the initialize, adjust and finalize
for entry_holder.

I don't know if this is an answer to you question, but if not
please tell me.

--
Gisle S�lensminde ( gisle@ii.uib.no )   

ln -s /dev/null ~/.netscape/cookies




^ permalink raw reply	[flat|nested] 7+ messages in thread

* "Dynamic" object
@ 2000-03-06  0:00 Preben Randhol
  2000-03-06  0:00 ` Gisle S�lensminde
  0 siblings, 1 reply; 7+ messages in thread
From: Preben Randhol @ 2000-03-06  0:00 UTC (permalink / raw)


I'm wondering how to do the following in Ada 95.

I want to have a small program as a frontend to a database. Thus the
program needs to read the definition of the db and then generate the
proper GUI for this. This I think I know how to to, but the problem is
how do I define a type that contains the different fields so that I can
put it in a linked list?

Example:

Field 1: First_Name (string of size 30)
Field 2: Sirname    (string of size 40)
Field 3: Age        (integer of size 3)
...
Field n: Address    (string of size 80)

Any hints much appreciated.

-- 
Preben Randhol -- [randhol@pvv.org] -- [http://www.pvv.org/~randhol/]
         "Det eneste trygge stedet i verden er inne i en fortelling."
                                                      -- Athol Fugard




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "Dynamic" object
  2000-03-06  0:00 ` Gisle S�lensminde
@ 2000-03-06  0:00   ` Preben Randhol
  2000-03-07  0:00     ` Simon Wright
  2000-03-08  0:00     ` Gisle S�lensminde
  0 siblings, 2 replies; 7+ messages in thread
From: Preben Randhol @ 2000-03-06  0:00 UTC (permalink / raw)


On 6 Mar 2000 17:58:55 +0100, Gisle S�lensminde <gisle@apal.ii.uib.no> wrote:
>Preben Randhol wrote:
>
>>I'm wondering how to do the following in Ada 95.
>>
>>I want to have a small program as a frontend to a database. Thus the
>>program needs to read the definition of the db and then generate the
>>proper GUI for this. This I think I know how to to, but the problem is
>>how do I define a type that contains the different fields so that I can
>>put it in a linked list?
>>
>>Example:
>>
>>Field 1: First_Name (string of size 30)
>>Field 2: Sirname    (string of size 40)
>>Field 3: Age        (integer of size 3)
>>...
>>Field n: Address    (string of size 80)
>>
>>Any hints much appreciated.
>
>
>I have some problem understanding what problem is. To get a more precise
>answer (at least from me), you should give more details of your problem.


Ok think about it more in the way of making a GUI interface to PostgreSQL where
you can set up the fields as you like in your database. 

So you can make one database which is an address book containing only the
fields Name and Address or you can make a database to organize the books that
you own, etc...

So the program cannot statically (at compile-time) know which fields are
present in the database you want to open. 

-- 
Preben Randhol -- [randhol@pvv.org] -- [http://www.pvv.org/~randhol/]
         "Det eneste trygge stedet i verden er inne i en fortelling."
                                                      -- Athol Fugard




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "Dynamic" object
  2000-03-06  0:00   ` Preben Randhol
@ 2000-03-07  0:00     ` Simon Wright
  2000-03-08  0:00       ` Preben Randhol
  2000-03-08  0:00     ` Gisle S�lensminde
  1 sibling, 1 reply; 7+ messages in thread
From: Simon Wright @ 2000-03-07  0:00 UTC (permalink / raw)


randhol@pvv.org (Preben Randhol) writes:

> Ok think about it more in the way of making a GUI interface to
> PostgreSQL where you can set up the fields as you like in your
> database.
> 
> So you can make one database which is an address book containing
> only the fields Name and Address or you can make a database to
> organize the books that you own, etc...
> 
> So the program cannot statically (at compile-time) know which fields
> are present in the database you want to open.

Ada doesn't really offer you any more facilities for doing this than
C would. How would you do it in C? (or perl, come to that?)

* interface to the DBMS to determine the record(s) involved, the
  fields, the type/size of each field

* construct some GUI to display these fields

* construct & execute query, populate GUI

You'll probably end up making a binding from Ada to PostGres, with
things in it like dbms_table_description which could contain a
table_name and an unconstrained array of dbms_field which would
contain a field_name & a type_name .. is there a binding already?
ODBC?




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "Dynamic" object
  2000-03-06  0:00   ` Preben Randhol
  2000-03-07  0:00     ` Simon Wright
@ 2000-03-08  0:00     ` Gisle S�lensminde
  2000-03-08  0:00       ` Preben Randhol
  1 sibling, 1 reply; 7+ messages in thread
From: Gisle S�lensminde @ 2000-03-08  0:00 UTC (permalink / raw)


Preben Randhol wrote:

>On 6 Mar 2000 17:58:55 +0100, Gisle S�lensminde <gisle@apal.ii.uib.no> wrote:
>>Preben Randhol wrote:
>>
>>>I'm wondering how to do the following in Ada 95.
>>>
>>>I want to have a small program as a frontend to a database. Thus the
>>>program needs to read the definition of the db and then generate the
>>>proper GUI for this. This I think I know how to to, but the problem is
>>>how do I define a type that contains the different fields so that I can
>>>put it in a linked list?
>>>
>>>Example:
>>>
>>>Field 1: First_Name (string of size 30)
>>>Field 2: Sirname    (string of size 40)
>>>Field 3: Age        (integer of size 3)
>>>...
>>>Field n: Address    (string of size 80)
>>>
>>>Any hints much appreciated.
>>
>>
>>I have some problem understanding what problem is. To get a more precise
>>answer (at least from me), you should give more details of your problem.
>
>
>Ok think about it more in the way of making a GUI interface to PostgreSQL where
>you can set up the fields as you like in your database. 
>
>So you can make one database which is an address book containing only the
>fields Name and Address or you can make a database to organize the books that
>you own, etc...
>
>So the program cannot statically (at compile-time) know which fields are
>present in the database you want to open. 

It seems like you realy want to use some tuple construct, which 
is available in several functional languages. In Procedural/OO
languages like Ada, C++ and Pascal there are no such thing.
You must know at compile time which fields a record have. If
you want to return a table entry without a priori knowlegde 
of it's contents, you must use a list of hetrogenous objects, or
some similar data structure. 

Typically you will make a tagged supertype (probably controlled) 
for a general field type, and make subtypes for the different 
field types. This will be much along the lines of the second
soultion in my last posting, but with lists of fields instead of 
lists of table entries (possibly lists of lists of fields).


--
Gisle S�lensminde ( gisle@ii.uib.no )   

ln -s /dev/null ~/.netscape/cookies




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "Dynamic" object
  2000-03-07  0:00     ` Simon Wright
@ 2000-03-08  0:00       ` Preben Randhol
  0 siblings, 0 replies; 7+ messages in thread
From: Preben Randhol @ 2000-03-08  0:00 UTC (permalink / raw)


On 07 Mar 2000 06:15:42 +0000, Simon Wright <simon@pogner.demon.co.uk> wrote:

>You'll probably end up making a binding from Ada to PostGres, with
>things in it like dbms_table_description which could contain a
>table_name and an unconstrained array of dbms_field which would
>contain a field_name & a type_name .. is there a binding already?
>ODBC?

There is an alpha binding, by Samuel Tardieu, that I want to use and
possibly extend (if needed), it can be found at:
http://www.infres.enst.fr/ANC/

-- 
Preben Randhol -- [randhol@pvv.org] -- [http://www.pvv.org/~randhol/]
         "Det eneste trygge stedet i verden er inne i en fortelling."
                                                      -- Athol Fugard




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: "Dynamic" object
  2000-03-08  0:00     ` Gisle S�lensminde
@ 2000-03-08  0:00       ` Preben Randhol
  0 siblings, 0 replies; 7+ messages in thread
From: Preben Randhol @ 2000-03-08  0:00 UTC (permalink / raw)


On 8 Mar 2000 10:58:26 +0100, Gisle S�lensminde <gisle@gribb.ii.uib.no> wrote:
>Typically you will make a tagged supertype (probably controlled) 
>for a general field type, and make subtypes for the different 
>field types. This will be much along the lines of the second
>soultion in my last posting, but with lists of fields instead of 
>lists of table entries (possibly lists of lists of fields).

Yes, I have been thinking in these lines too after your prior proposal.
:-) Thanks!

-- 
Preben Randhol -- [randhol@pvv.org] -- [http://www.pvv.org/~randhol/]
         "Det eneste trygge stedet i verden er inne i en fortelling."
                                                      -- Athol Fugard




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2000-03-08  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-06  0:00 "Dynamic" object Preben Randhol
2000-03-06  0:00 ` Gisle S�lensminde
2000-03-06  0:00   ` Preben Randhol
2000-03-07  0:00     ` Simon Wright
2000-03-08  0:00       ` Preben Randhol
2000-03-08  0:00     ` Gisle S�lensminde
2000-03-08  0:00       ` Preben Randhol

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