• 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

Valid / Invalid Records

 
Ranch Hand
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

When the insturctions say

1 byte flag. 00 implies valid record, 0xFF implies deleted record



does this mean that I can use the int value of 0 for a valid record and the int value 1 for an invalid record?
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you want to store an invalid record?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's correct! "invalid" as in "this record does not exist, it's deleted, so please don't show it to the user".
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Why would you want to store an invalid record?


Because that's part of the assignment. If the record is deleted, you have to write a flag to the file to indicate that this record is deleted, so you don't return it as a match when a search is executed.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe I misunderstood. I interpreted the question as meaning "invalid" as distinct from "deleted" - i.e. three states. Otherwise, what's the value 1 got to go with it?
 
Glen Iris
Ranch Hand
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:That's correct! "invalid" as in "this record does not exist, it's deleted, so please don't show it to the user".



Why do the instructions say 0 and 0xFF instead of 0 and 1?

I know there are 0-255 possible values between 0 and 0xFF and I think that is what is confusing me.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it's not an invalid record (as "in wrong data" or "incomplete"). It's just to indicate that a record is deleted and should be ignored when searching/retrieving
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Glen Iris wrote:Why do the instructions say 0 and 0xFF instead of 0 and 1?


You can't assign 0xFF to a byte. But if you force it (just use a cast) and just print it to the console, -1 is printed.

I just glanced back to my project and I definitely used 1 to indicate a deleted record. But I don't think that's the most important part of the assignment
 
Glen Iris
Ranch Hand
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I notice that none of the records in my database file have anything in the validity field.

I was thinking of initially assuming they are all valid and set them all to 1 when I first read them in. I would also write to the db file to mark them as valid records if they are not explicitly marked as invalid

Can you guys please share your thoughts on this?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Glen Iris wrote:I notice that none of the records in my database file have anything in the validity field.

I was thinking of initially assuming they are all valid and set them all to 1 when I first read them in. I would also write to the db file to mark them as valid records if they are not explicitly marked as invalid


Since 0 is supposed to mean "valid", doesn't that mean that they are all flagged as valid already, and you don't need to assume anything? And so, if that's the case, there's no need to write anything back (unless the records change).

Again, I feel I'm missing something (and I apologise if I am), but you seem to be making a distinction between having "nothing" in the validity field, and having zero. Surely these are the same case?
 
Glen Iris
Ranch Hand
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:

Glen Iris wrote:I notice that none of the records in my database file have anything in the validity field.

I was thinking of initially assuming they are all valid and set them all to 1 when I first read them in. I would also write to the db file to mark them as valid records if they are not explicitly marked as invalid


Since 0 is supposed to mean "valid", doesn't that mean that they are all flagged as valid already, and you don't need to assume anything? And so, if that's the case, there's no need to write anything back (unless the records change).

Again, I feel I'm missing something (and I apologise if I am), but you seem to be making a distinction between having "nothing" in the validity field, and having zero. Surely these are the same case?



this is my question really. Is it safe to assume this?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assumed all records in the database file are valid
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic