Your first programming lab is to implement a very simple relation manager that will support creating new relations, inserting records, etc. Specifically you need to implement the functions below. I've provided the header file already that includes the prototypes.
This function creates a new table with the given name. The paramater num_cols specifies how many columns will be in the new table and atts is an array of descriptors, one per column. See the header file and the sample test program for more details.
This function inserts a new row into an existing table specified by table_name. The column values for the new row are passed in via the vals array and num_vals indicates how many entries are in the array. If a column in the table has no corresponding value in the vals array its value in the new row should be NULL (the database meaning, not necessarily the C meaning).
This function is used to begin a scan of an existing table specified by table_name. Upon successful completion, the scan descriptor that was passed in will be properly set. The scan will be positioned before the first row in the table.
This function advances the scan by one record. If there are no more records it should return the error END_OF_SCAN. The scan parameter should have already been set by a ScanBegin call.
This function get the value of a string column from the current row in the scan. The name of the desired column will be in col_name and on successful completion, the val pointer will be set to the string value. If the column is NULL, the function should return the error NULL_VALUE. If the column is an integer column, it should return the error BAD_COL_TYPE.
This function get the value of an integer column from the current row in the scan. The name of the desired column will be in col_name and on successful completion, the val pointer will be set to the integer value. If the column is NULL, the function should return the error NULL_VALUE. If the column is a string column, it should return the error BAD_COL_TYPE.
This function updates the current record in the scan by setting some of its columns to the values indicated in the vals array. The parameter num_vals will contain the number of entries in the vals array. Any column that does not appear in the array will not have its value changed. In addition, if the vals array entry has the is_null flag set, the value of the corresponding column will be set to NULL. If the scan is not currently on a row, the error NOT_ON_ROW should be returned.
This function deletes the current record in the scan. If the scan is not currently on a row, the error NOT_ON_ROW should be returned.
This function ends a scan and reclaims any resources needed by the open scan. Every call to BeginScan should have a matching call to ScanEnd.
Notes:
To make this assignment easier, I'm providing a really simple buffer manager that you MUST use. You should not use any operating systems calls for file access. Both the header file and code are available on the web. You may not change the buffer manager in any way without my permission. Send me email if you think you've found a bug. Here are the functions that the buffer manager supports. A simple test program that shows how to call them is available as well.
This function must be called before any other buffer manager calls are made.
This function will check if a file with the passed in name already exists, returning 1 if it does and 0 if it does not.
This function opens the indicated file and returns a file descriptor for it. If the file did not exists, a new file is created. Note that this is not the same as the operating system file descriptor - it is only for use by the buffer manager calls. A negative number indicates an error upon opening the file.
This function closes a file previously opened with the OpenFile function.
This function returns the number of blocks that are in the previously opened file indicated by the passed descriptor.
This function reads a particular block from a file and set the buffer pointer to point to it. The parameter block_num should be a non-negative value indicating which block to read. The block will be pinned until a ReleaseBlock call is made.
This function adds a new block to the end of the file and sets the buffer pointer to point to it. The initial values in the block are undefined. The block will be pinned until a ReleaseBlock call is made.
This function releases a previously pinned block. The modified flag should be 1 if the block was modified since it was read, 0 otherwise. Blocks that were just appended should always be marked as modified. After a block has been released, any previously returned pointer to it (GetBlock, AppendBlock) should be considered invalid.
This function trims the file so that last_block (0-based) is the last block in the file.
Notes:
I've provided an optional makefile for your use.
You must submit a description of your design in a plain text file called dbe.doc, and to include comments in the code.
The grade of your program will be based on three aspects:
Submission of the assignment will take place electronically. Please tar your source code, makefile, and your dbe.doc documentation file. Then, send me an email with the subject Program 1 and attach the tar file.
Students must work alone on this assignment, both on the design, coding, and testing stages.
Every line of code should have been written by you or provided by me. YOU MAY
NOT SHARE CODE, EVEN TEST CODE. Please do not turn in work that is similar enough to a fellow
student's that we have to involve the academic police.