• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Contractor project : Record count and deleting.

 
S Perreault
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question about the data file and how to count the number of records.
For instance, we have a file and the first 3 records look like this:
Record #, Valid flag, Contractor Name, etc.
1, 0, ContractorA
2, 0, ContractorB
3, 0, ContractorC
Let's say that we delete record 2 (ConstructorB).
1, 0, ContractorA
2, 1, ContractorB
3, 0, ContractorC
When we do a record count, do we have 2 or 3? Also, would the file be more like this?
1, 0, ContractorA
-, 1, ContractorB
2, 0, ContractorC
Thanks for any insight.
Perogi.
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my implementation, I leave the record number unchanged even after a deletion. So it is still 1 2(deleted) 3. I don't know how others doing.
By the way, the deleted flag is 0x8000, isn't that the minimum value of a short, not -1?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Perogi & Peter,
Perogi: I agree with Peter. It will be easier for you (IMHO) if you determine your record numbers based on their physical location in the file, not on whether the records have been deleted or not. If you don't do this, you are going to get into difficulties if the following occurs (just to give one example):
  • Client A reads records 1 (Contractor A), 2 (Contractor B), and 3 (Contractor C)
  • Client B deletes record 2 (Contractor B)
  • Client A sends a request to book record 2.


  • If you have kept the record numbers based on file location, you will be able to identify that the record has been deleted, and handle it appropriately.
    If you have changed the record numbers, then Client A has now potentially booked the wrong contractor
    (By the way - in a real database, you would not think of changing the primary key: in fact you should not be able to do so)
    Originally posted by Peter Ye:
    By the way, the deleted flag is 0x8000, isn't that the minimum value of a short, not -1?

    Different people have different requirements. Even if two people have "Contractors" assignment, they can still have different requirements. One of the many small differences is in what indicates a deleted record. Both the value for a deleted record and it's size (byte or short) can vary between assignments.
    This is one of the reasons why you must include your instructions and your database file in the jar you submit to Sun: anyone else's instructions and/or database file could fail to work with your code.
    Regards, Andrew
     
    S Perreault
    Ranch Hand
    Posts: 37
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Peter Ye:
    In my implementation, I leave the record number unchanged even after a deletion. So it is still 1 2(deleted) 3. I don't know how others doing.
    By the way, the deleted flag is 0x8000, isn't that the minimum value of a short, not -1?

    Thanks for the responses!
    Peter, in regards to the above quote, I think you were referring to this 'diagram':
    1, 0, ContractorA
    -, 1, ContractorB
    2, 0, ContractorC
    The second in the list isnt prefaced with a -1, the - is to show that I don't consider this to be have an id. The 1 is to show that it is deleted. When I read my instructions it says,
    "Data section.
    Repeat to end of file:
    1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record
    Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information "
    Yours obviously says something different! Peter, thanks for clearing that up because I would have been freaking out that I wasn't reading the above section of the instructions correctly. I have worked at my client's offices as a consultant but even the worst ones gave me better specs than Sun heh.
    Thanks to you both again,
    Shawn.
    aka Perogi.
     
    Yuan Ye
    Ranch Hand
    Posts: 172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Shawn, I think you misunderstood what I said. As Andrew pointed out, obvoius we have different specs for the representation of a deleted record. So please ignore my comment about delete flag.
    As to the record number, I used the following way, no matter whether you have delete a record or not, it still keeps its original record number.
    So in ur case it would be like:
    1, 0, ContractorA
    2, 1, ContractorB
    3, 0, ContractorC
    Hopes this is clear.
    [ October 30, 2003: Message edited by: Peter Ye ]
     
    S Perreault
    Ranch Hand
    Posts: 37
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Peter,
    Yup, crystal clear!
    Thanks for reposting and making sure that I understood.
    GL!
    Perogi.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic