NAME

RDB - object methods for dealing with rdb files


SYNOPSIS

  dofile( '/proj/axaf/simul/lib/lua/RDB.lua' )
  rdb = RDB:new( )
  rdb:open( file )
     or
  readfrom( file )
  rdb:open( )
  cols = rdb:cols( )
  data = rdb:read( )
  while data do
    local i = 1
    print( '---------------------' )
    while i <= rdb:ncols( ) do
      write ( cols[i], ' = ', data[cols[i]], '; ', type( data[cols[i]] ), '\n' )
      i = i + 1
    end
    data = rdb:read( )
  end


DESCRIPTION

This module eases use of RDB data files. It creates RDB objects which contain the necessary information for interpreting and manipulating RDB files.


Object data methods

Once the object is created, you can access the object's attributes using the following functions: information

cols()
This returns a table containing the names of the columns in the RDB table, indexed off of the unary-based position of the column in the file.
        cols = rdb:cols()

comments()
This returns a table containing the header comment lines in the RDB table, indexed off of the unary-based position of the column in the file. leading pound signs and trailing newline are removed.
        comments = rdb:comments()

defs( col )
return the definition for the passed column. returns nil if the column doesn't exist.
        defs = rdb:defs( col )

ncols()
This returns the number of columns in the rdb table:
        ncols = rdb:ncols()

pos( col )
return the unary-based position of the column in the rdb table. It returns nil if the column doesn't exist.
        pos = rdb:pos( col )

chk_cols
This is passed a table of columns whose existance in the table will be checked. It returns the name of the first column which doesn't exist, nil otherwise.

var( varname )
Returns the value of the header variable varname.


Object action methods

new [file]
new is the constructor, and must be called before any other methods are invoked. It creates an RDB object. It can optionally be passed a filename to be opened, which will be passed to the open method. Upon error, it returns two values, nil and an error message, else it returns the new object.
  rdb, msg = RDB:new( )
  rdb, msg = RDB:new( file )

open( [file] )
open reads the RDB table header from either the current input stream, or from the passed file, if it is specified. In the latter case, the file becomes the current input stream. The file is opened for reading. Upon error, it returns two values, nil and an error message, else it returns 0.
  err, msg = rdb:open( )
  err, msg = rdb:open( file )

read( )
Read in the next line from the rdb database, splitting the columns into a table keyed off of the column names. It returns this table upon success, nil upon end of file. Data values are converted from strings to numbers based upon the rdb table's column definitions.


AUTHOR

Diab Jerius ( djerius@cfa.harvard.edu )