All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field.
But in my database file all fields are Space filled and not null terminated? Why is the db file format different from the format that my application is expected to use?
The field values are null-terminated as far as their length is less than the maximum field length.
As the space (ASCII 32) is a normal character, if field values are right-padded with it till the field length, it's normal rather normal that you don't find nulls at the end.
Example: Given a field length of 3 (the nulls are represented by 0):
"abc":no null at the end
"ab ":no null at the end
"a00": two nulls
I personally decided to do as Anthony.
[ August 28, 2004: Message edited by: Philippe Maquet ]
I just want to give some info regarding this question even though it is too late to give some. (It might be helpful for future readers)
Data file which is sent by your SCJD assignment makes sense perfectly.
If fields in original db file were null_terminated, it could be too much hassle to find correct place according record number.
but with current file, we as a developer can easily jump correct place of the record.
Some clue : offset of the file is general data such as schema info or file info at the begining.
rest of info in the file are records which are fixed length. Therefore you can easily jump the record you want by using these numbers....
Note : In case of adding new record(Think there is no reusable record in db)
, add new record by obeying fixed length policy of db file. definitely it will help to find records
Originally posted by Muhammad Shafique:
If the record length is fixed then field/attribute termination with null does make sense since we shouldn't add characters after the null (not even spaces). There is no concept of null after null.
I had similar text and simply ignored it!
This is not strictly true as it could mean padding in full with as many "0" bytes as is nescessary couldn't it? It is meerly to fill space to the end of the record after all. I do agree that that soultion would not be in the true sprit of what a null terminted string is supposed to be tho.