• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

recNo missing in UrlyBird 1.2.3

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the file is not corrupt, you need to assign these numbers yourself on startup of the database server
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anand,
Welcome to the SCJD forum. Most people have been forming a compound key to deal with this issue, though a few have been creating their own.
HTH,
M
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


  • Regards,
    Phil.
     
    Wanderer
    Posts: 18671
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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?
     
    Ranch Hand
    Posts: 64
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Anand Lakhani
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Anand
    You should have the comment in your instructions file:

    A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is a little more efficient.


    So performance is not the major consideration.
    Regards, Andrew
     
    Ranch Hand
    Posts: 555
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    I used the formula as Phil did:

    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.


    It is pretty simple and works perfect.
    Vlad
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic