Hi All, I have been assigned with URLyBird 1.2.3. It seems a little strange to me that my data file does not contain the "recNo" and yet it is used as the primary key in the interface we are supposed to implement !!! Are we supposed to generate these recNo's ourselves, and merge it with the data from the text file in some intermediary data structure? Is this primary key missing from everyone else's assignment as well? Maybe my data file is corrupt !! Thanks, Anand
Hi Anand, I've got URLyBird 1.2.1 and it seems very comparable to yours as far as recNos and primary are concerned.
The recNo. As Data uses a fixed-length record format, recNo is just the basic information you need to compute where a given record must be read from / written to the file. After having read the file header while opening the file, you may store the file position (begin of data section of the file) in some long variable (I called it dataOffset). Afterwards, to read or write a record, you just need to use the right position within the file, using this simple formula : dataOffset + (recNo - 1) * recordLength.
With URLyBird 1.2.1, it's impossible to define a primary key on the only table we use - even a compound one, Max - because the application we write must accept duplicate rooms (there is no room number, so we cannot distinct two different rooms / same hotel / same date / same location / same smoking status while we must be able to store multiple such records in the database). So OK, we don't need a primary key in the only table we'll use, but Data must be able to handle an optional one. In other words, I've added support for such a primary key, but I let it null for our given database.
Max - I think if you want to create a compound key of some sort that's a separate issue. The API needs to access records based on an int, called recNo. The simplest way to do this, IMO, is to say that the first record in the file is record 0 (or 1 if you prefer), and subsequent record numbers are found by counting 1, 2, 3, 4. This leads to simple formulas such as Philippe mentioned. Are you saying a compound key might be used to replce this formula somehow?
Hi All: I think the record number might be viewed as an "Implied Primary Key". Certainly, if there was a autoincrement field called record number, then all would be happy. However, as long as database compaction isn't allowed, then an equivalent "implied" key exists -- the physical index of the record in the database. Tx
Joined: Jul 15, 2003
Thanks for all your comments - they have been very useful. I think I will take the approach of initially loading all the data from the file into a data structure and then adding the incrementing record numbers to it, starting from 0. I guess using a data structure will also help with performance of the searching algorithm. Or is this just overkill? Do Sun take performance into account when marking the assignment? Thanks, Anand