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, 26 Mar 2007 09:56:03 -0500
Date: 2007-03-26T17:00:02+02:00	[thread overview]
Message-ID: <mailman.125.1174920983.18371.comp.lang.ada@ada-france.org> (raw)

Alright, here is my status.  I decided to use the fixed record length
and I have the program limping successfully.  I kept getting
segmentation faults in GNAT and I tracked it down to missing "all"
operator on pointers.  I'll come back to the segmentation fault issue in
a moment.  I have some further questions about the record structures I
used and their size with respect to calculating a positive_count within
a file to use the stream_io set_index procedure.  

The base types are (not in this order):

    type schema (number_of_attributes : Integer) is tagged record
        tablename : String (1 .. max_tablename_length) := (1 ..
max_tablename_length => ' ');
        attributes    : attribute_array (1 .. number_of_attributes);
        record_length : Integer := 0;
        byte_start    : Integer := 0;
        byte_end      : Integer := 0;
    end record;

    type attribute is tagged record
        name         : String (1 .. max_attributename_length) := (1 ..
max_attributename_length => ' ');
        domain       : String (1 .. max_typename_length) := (1 ..
max_typename_length => ' ');
        isprimarykey : Boolean := False;
        byte_start   : Integer := 0;
        byte_end     : Integer := 0;
    end record;

Extended types are:
    type booleanattribute is new attribute with record
        value : Boolean := False;
    end record;

    type integerattribute is new attribute with record
        value : Integer := 0;
    end record;

    type stringattribute is new attribute with record
        value : String (1 .. max_stringlength) := (1 .. max_stringlength
=> ' ');
    end record;

    type dateattribute is new attribute with record
        year  : Year_Number  := 1901;
        month : Month_Number := 1;
        day   : Day_Number   := 1;
        value : Time         := Time_Of (1901, 1, 1);
    end record;


My database file looks something like:
--------------------------------
<<Schema'output here  >><<schema.attributes'output here>>
<<attribute(1)'output>><<attribute(2)'output>>...<<attribute(n)'output>>
<<attribute(1)'output>><<attribute(2)'output>>...<<attribute(n)'output>>
. Each of these rows are tuples
.
.
<<attribute(1)'output>><<attribute(2)'output>>...<<attribute(n)'output>>
--------------------------------


Where attribute(1) - attribute(n) are the streamed values of the
attributes.  The schema.attributes'output is only for
descriptive/comparative purposes so that when I open the file I can load
the schema information as a guide and a reference as to the format,
count, properties of each tuple that follows it in the file.  Tuples are
not ended with an end_of_line character in my database file.

When inserting tuples I calculate the byte_start and byte_end values for
each attribute.  When doing this I found that I must adjust them as
follows:

            if Trim (schemainfo.attributes (x).domain, Ada.Strings.Both)
= "BOOLEAN" then
                values (x).byte_end := values (x).byte_start +
(booleanattribute'size / 8) - 1;
                booleanattribute'output (Stream (fout), booleanattribute
(values (x).all));
            elsif Trim (schemainfo.attributes (x).domain,
Ada.Strings.Both) = "STRING" then
                values (x).byte_end := values (x).byte_start +
(stringattribute'size / 8) - 8;
                stringattribute'output (Stream (fout), stringattribute
(values (x).all));
            elsif Trim (schemainfo.attributes (x).domain,
Ada.Strings.Both) = "INTEGER" then
                values (x).byte_end := values (x).byte_start +
(integerattribute'size / 8) - 7;
                integerattribute'output (Stream (fout), integerattribute
(values (x).all));
            else -- "DATE"
                values (x).byte_end := values (x).byte_start +
(dateattribute'size / 8) - 11;
                dateattribute'output (Stream (fout), dateattribute
(values (x).all));
            end if;

I had to debug the program to get the -1, -8, -7, and -11 values.  The
adjustments were made so that the byte_start and byte_end values match
the values returned by the stream_io.index function before and after
calling 'output on each attribute.  I'm sure that I don't need to go
into detail as to why the positive_index value is imporant to record on
a database file so I won't spend time explaining that.

I don't understand why I needed the -1, -8, -7, and -11 adjustments.  I
know it relates to the size of the object but why isn't it on a byte
boundary?
Thanks for any information you can provide.



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



             reply	other threads:[~2007-03-26 14:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-26 14:56 Carroll, Andrew [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-03-13  0:50 Design help Carroll, Andrew
2007-03-13  2:48 ` 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
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