• 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

What about records

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding that after reading the feild names then there should be record values
so when I use readByte from the 7th byte , it does not give me desired results:
DB file is :

Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record

Schema description section.
Repeated for each field in a record:
1 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
1 byte numeric, field length in bytes
end of repeating block

Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF 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

End of file



It starts reading feild names again. Please help.

Regards

Uzma

P.S list is storing the bytes in each field
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The 7th byte will give you start of the schema description section not the start of the data section for record values.

I can't understand from your code what you are trying to achieve with the iterator?

1) Read Magic Cookie
2) Read Number of fields
3) Use a for loop to get the fieldname a field length

Once you have performed the following steps the file pointer will be at the start of the data section, you can then use the field lengths you have retrieved in the previous step to read each record.

Regards
Jason
 
uzma ali
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jason you are always been help


Finally I am getting values in shape of records. The iterator is to iterate records basically.
The output is as under for one record, it's still not 100% but I am close. Any suggestions?

Bitter Homes & Gardens Smallville Drywall, Painting, Carpets 10 $75.00 ]

Thanks for all the help, I am grateful.

Regards

Uzma
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what is bufferstore? as you are still reading records from your randomaccessfile (in) object? so it's not clear what you are iterating.

The read(byte[] b) method returns -1 if there is no more data or then end of file is reached, so you could loop through the records until you reach the end and remove the need for your iterator, which I think complicates the mechanism.

Otherwise I think you are almost there, you just need to split the record byte array into individual fields before converting to strings.


Jason
[ August 10, 2007: Message edited by: Jason Moors ]
 
uzma ali
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jason

you were right iterator was not needed



Now there is last problem left there is a box I am getting in the out put where every record start. I know the reason which is 1 byte flag. 00 implies valid record, 0xFF implies deleted record , according to the data file . I am just thinking how to read this byte so it does not show in the output. Any suggestions? Also please advice , am I on the right track?

regards

Uzma
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you need to do is split the oneRecord byte array into separate fields, as you know the length of the fields from reading the header section.

When I read the header section I store the field information in an array call fieldInfo, therefore when I've read the record byte array I know how many bytes to read


[ August 10, 2007: Message edited by: Jason Moors ]
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Please check this link.
May be it will help you.

https://coderanch.com/t/187523/java-developer-SCJD/certification/db-format

Thanks

Vaishali
 
uzma ali
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jason , your tips are always been helpful.
if you would not hear anything from me by tomorrow then that means I have done it

Thanks Vaishali for the link. but only thing is that they are hard coding the values which might not be a good idea.

Thanks a bunch

regards

Uzma
 
Vaishali Paramane
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes its hard coded
I am also stuck on fetching field lenght.

using that link code i understand all schema related quesion but i cannot able to read field length from schema thats the problem for me.
 
uzma ali
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
read through my this post and the last one and still you don't get and idea then ask me Jason was a big help to me.

Please do ask if your problem persists after reading.

Uzma
 
Vaishali Paramane
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks

My problem solved.
[ August 10, 2007: Message edited by: Vaishali Paramane ]
 
Vaishali Paramane
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI

can anyone tell me that following checking valid or deleted flag is correct or not?
my out put is correct no problem. just want to confirm.
(2 byte flag. 00 implies valid record, 0x8000 implies deleted record)

short flag = raf.readShort();

while(flag==00 || flag==0x8000){}
 
uzma ali
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it should be ok as the link you provided me earlier used the same check. Also from datafile description it sounds that you are on the right track.

regards

uzma
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic