Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading in records

 
David Khoi Pham
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys!

I'm doing the URLyBird project and I'm currently coding the functionality that allows me to read in the records from my .db file. I have some questions and I would greatly appreciate if you could answer them for me!

I have written all the code to read in all the header values, field names, etc. and now I'm at the stage to read in the record data.

How should I store the record data? Should I put it into a byte[] and then store all the records into one single String? Should I put it into a String[] with each element holding one single record? I'm really stuck at this stage!

And also, last question! Concerning the field names, and lengths, etc. - how should I store it? And why should I?

Sorry! I'm just having some brain blockages!

Thanks!
David Pham
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

You definitely want a byte[] for reading the record part. You can either put them in an ArrayList<String> or String[]. Read my post under General Comments started by Mandy Bowman. It is a maybe a week old, not too far down the list. I posted two URLs that I pretty much entirely got my file reader from. And get a Hex editor! It will help you profoundly to know what is in that file, so you can know if your code is working.
 
David Khoi Pham
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response!

I created a String[][] with the first dimension holding whole records and the second dimension holding the individual fields specific to those records.

One question I have is if I should include the byte flag in the String array? And how can I retrieve the byte flag - is there anything special I need to do since it's now in a String format?

Thanks,
David Pham
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I included it. After all, it is part of the record. It just shows up as two square things in mine, when I print it to the screen. I forgot to tell you to use an ASCII conversion chart, too. My hex editor has one included.
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to answer the part about the flag being a String. Look at the Wrapper classes if the String proves to be an issue. Mine is a long, I think. Long or Integer should have what you need. valueOf or decode might help you.
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David.


I created a String[][] with the first dimension holding whole records and the second dimension holding the individual fields specific to those records.


I implement this a bit different, List<String[]>, as you first dimension holding the data, but then i use a List because number of contractors is variable (and i'm more comfortable using Collections).


One question I have is if I should include the byte flag in the String array? And how can I retrieve the byte flag - is there anything special I need to do since it's now in a String format?


First i read this as a byte, then i didn't store, instead i insert a null in my list meaning a deleted record. This is done when i read data, but later in my program i use a value object than transforms this array of string, first verify if record is null, if not create another list with value objects contains a id with the real position of the record and deleted records are inserted again with a null value. This is done to keep the same phisical position of records in datafile if is required make another operation over the record, as a read, update, delete, etc. This id is for internal use only and is never showed in my gui, but is used in DB interface and the in my Data class implemntation as sun requires.

I hope it helps you.
[ July 12, 2007: Message edited by: Gabriel Vargas ]
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Khoi Pham:

And also, last question! Concerning the field names, and lengths, etc. - how should I store it? And why should I?


This is exactly what confuses me. Why is database schema described in instructions and it is again described in database?

Should we make independent reader for database, which will be based on field information from database file only or just make hard-coded version based on information from instructions?
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

I first made a DatabaseManager class than read all, later i separate this functionality in two classes, first made all file operations and returns a list of strings of the readed data (i call a helper ), then my Database manager take that data and converts it in my value objects. Database schema is harcoded in DatabaseManager but not in my helper makes my code more clear. I use the field data than contains the datafile, and it is the same than my instructions to make it more generic (some things are harcoded like size of cookie but things than can be variable isn't are harcoded).

I hope it helps you.
 
David Khoi Pham
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!

Thanks for all your tips and answers!

I finally successfully read in all the data and stored it in an array.

What should my next steps be?

Thanks!
David Pham
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anne Crace:
I included it. After all, it is part of the record.


Hmm that depends on what your idea is of a record. I think it is part of the record, but I wouldn't consider it part of the data. That's why I didn't include it. That is also more consistent with the rest. If you would include the delete flag in the result of read, you should probably also include it in the input parameter of update, of find (criteria), etc etc. Which would seem awkward to me.


As for the question on how to convert the delete flag: you can convert it to anything you like. You could choose "Y" for deleted, "N" for not. Or "1" and "0". Or whatever. As long as conversion back and forth is consistent.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic