Next: , Previous: Top, Up: Top


1 Introduction

The mst_rdb package allows the reading of database files in /rdb format. These files consist of optional comments beginning with pound signs (#), a header containing the field names of the columns, and rows of ASCII data delineated by tabs. There are two data types, strings and numeric. The mst_rdb library allows access to both types of data fields.

The reading of an /rdb table consists of the following steps:

There are several ways in C of specifying a complex data structure, and eventually this library will support a number of them. For now, there is one supported method for each of the above steps. The suffixes of the function names indicate what method is being used to specify the data structures; ar stands for array, st stands for struct, and va stands for varargs.

It is presumed that the user wishes to select certain columns to read, and has established an array of structs, or a single struct, into which the data are to be placed. The header mapping routine connects the properties of this struct to those of the /rdb file, selecting desired columns by name, and informing the software of the data type (string or numeric) for each desired field. The user then passes the reading routine a pointer to a struct of the agreed type, and the reading routine obtains data from a single line of the file, and places the desired fields into the struct. If numeric, the data are put into a double in the struct. If string, space for the string is allocated dynamically, and a pointer to this string is put into a char * field of the struct. It is important for the user to remember to free the memory allocated for unused strings.

When the user is done with the data structures used in reading an /rdb file, they should be freed. Use the normal free() call on all strings returned by the column reading function, and then call first rdb_free_map() and then rdb_free_hdr() to free the memory associated with the column map and header data structures respectively.