comp.lang.ada
 help / color / mirror / Atom feed
From: "Carroll, Andrew" <andrew.carroll@okstate.edu>
To: <comp.lang.ada@ada-france.org>
Subject: Design help
Date: Mon, 12 Mar 2007 19:50:11 -0500
Date: 2007-03-13T01:55:02+01:00	[thread overview]
Message-ID: <mailman.120.1173747027.18371.comp.lang.ada@ada-france.org> (raw)

I hope to have the database records be variable length however it may
make my life easier if they are fixed length due to the fact that some
of the record structures contain pointers.  I guess that would be access
type instead of pointer, anyway...

Here are the record structures I have defined:

   type attribute is tagged
      record
         name         : string_ptr;
         domain       : string_ptr;
         isprimarykey : boolean    := false;
         byte_start : integer;
         byte_end   : integer;
         size       : integer;
      end record;

   -----------------------------------
   --    Extended Attribute Types   --
   -----------------------------------
   type booleanattribute is new attribute with
      record
         value      : boolean := false;
      end record;
   type booleanattribute_ptr is access all booleanattribute'class;



   type integerattribute is new attribute with
      record
         value      : integer := 0;
      end record;
   type integerattribute_ptr is access all integerattribute'class;



   type stringattribute is new attribute with
      record
         value      : string_ptr;
      end record;
   type stringattribute_ptr is access all stringattribute'class;



   type dateattribute is new attribute with
      record
         year       : ada.calendar.year_number;
         month      : ada.calendar.month_number;
         day        : ada.calendar.day_number;
         value      : ada.calendar.time;
      end record;
   type dateattribute_ptr is access all dateattribute'class;



Obviously a database tuple could have any combination of these in it but
luckily I only have to worry about 5 attributes in a database table
schema.  So, I want to read a whole database tuple in as a bit string
(or something like that) and then be able to convert small sections of
it into the appropriate record structures above for each of the
attributes defined on the table.  

I can get rid of the string_ptr and set a default string size.  If I did
that I would be pretty close to a fixed-width database record and could
use something like Ludovic mentioned.  I think the drawback to this is
that I would have to have an I/O package for each type of attribute
right?  Like this:

package Attribute_IO is new Ada.Sequential_IO (Element_Type =>
Attribute); 
package BooleanAttribute_IO is new Ada.Sequential_IO (Element_Type =>
BooleanAttribute); 
package IntegerAttribute_IO is new Ada.Sequential_IO (Element_Type =>
IntegerAttribute); 
package StringAttribute_IO is new Ada.Sequential_IO (Element_Type =>
StringAttribute); 
package DateAttribute_IO is new Ada.Sequential_IO (Element_Type =>
DateAttribute); 

It seems like the second method that Ludovic mentioned might be better
in my case even if there is a fixed-width database record.  For each
type I have I could define a constructor function.  Like this:

function To_BooleanAttribute (Raw_Bytes : in
Ada.Streams.Stream_Element_Array)  return T
Is
Begin
	--but I don't know what to do here.
	--I'm assuming that because it's an array of stream_elements
(bytes?) 
      --that I can grab any number of them from the array.
	--something like Raw_Bytes(offset_byte..size);
      --where offset_byte index could be calculated ???
	--and the size would be taken from the size of the attribute
type.
      --
      --this is where I need help. 
   	--even if I knew that I could do the above, I wouldn't know how
to make
	--it officially a BooleanAttribute (in this case).  Would I use
a 
	--Qualified expression like:  return
BooleanAttribute'(Raw_Bytes(offset_byte..size));
End to_t;


HTHYHM



Andrew Carroll
Software Services
405-744-4943
andrew.carroll@okstate.edu



             reply	other threads:[~2007-03-13  0:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-13  0:50 Carroll, Andrew [this message]
2007-03-13  2:48 ` Design help Randy Brukardt
2007-03-13  8:52 ` Stuart
2007-03-13  9:40 ` Dmitry A. Kazakov
2007-03-13 20:18   ` Simon Wright
2007-03-13 22:22   ` Randy Brukardt
  -- strict thread matches above, loose matches on Subject: below --
2007-03-26 14:56 Carroll, Andrew
2007-03-09 22:43 Carroll, Andrew
2007-03-09 23:07 ` Simon Wright
2007-03-10  1:00 ` Jeffrey R. Carter
2007-03-10  4:40 ` Steve
2007-03-10 13:38 ` Ludovic Brenta
2007-03-17 20:34 ` Michael Erdmann
replies disabled

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