minrel : bootstrap
Table of Contents
1 intro
We've shown how to reify our types so we can write generalized routines that work with user defined relations, but we haven't actually given our users a way to declare relations and keys.
Except… We have a database. Wouldn't it be nice if the data that described our database could be stored in the database?
Let's start simple, and build a routine to import tab delimited text files. This probably won't be the primary way to get data into the system but it's a common data format that's easy to parse, easy to generate and already has decent tool support. It's also ready to write by hand in any text editor.
2 tab reader
ReadTuple is a lot like WriteTuple from Last time:
procedure ReadTuple( buf : array of byte ); var key : TKeyDef; c : cardinal; pos : cardinal = 0; ch : char; s : string[255]; begin for key in keys do with key do begin case keyType of ktPadding : inc( pos, keySize ); ktCardinal : begin read( c ); move( c, buf( pos ), keySize ); end; ktString : begin s := ''; c := 0; ch := #0; while c < keyLength and ch <> kSep and not eof do begin read( ch ); s := s + ch; inc( c ); end end end; move( c, buf( pos ), keySize ); end end;
3 dynamic arrays
Reading the whole table is no big deal, but we do need to know how to make it happen.
Now to read the table:
procedure ReadData( def : TRelDef ); begin while not eof do begin end end;
4 polymorphism
Now we have WriteTuple and WriteHeader for text formatting but what about computer readable?
- interfaces : IRowReader , IRowWriter