POL users may fill database records using such syntax:

          CRecordStream rs(db);
          rs << "string" << 123 << 'A';

The similar approach can be used to read data back from the record:

         CRecordStream rs(db, index);
         int num;
         char ch;
         CString str;
         rs >> str >> num >> ch;

Everything is written in compressed format, i.e. database record
occupies minimal required space.

______________________________________________

Best regards,
Maks Pyatkovskiy


> -----Original Message-----
> From: [EMAIL PROTECTED]
[mailto:bounce-palm-dev-
> [EMAIL PROTECTED] On Behalf Of Steve Jerrett
> Sent: Saturday, June 07, 2003 3:25 PM
> To: Palm Developer Forum
> Subject: Re: problem writing to database (beginner)
> 
> Matt,
> 
>   I would look at storing the data in compressed format instead of
> 
>  >>typedef struct {
>  >> char Department[20];
>  >> char Operator[20];
>  >> char RXNumber[20];
>  >>} DBRecord;
>  >>DBRecordType r;
> 
> The problem you are encountering is that you've designed the
"database"
> to have records of fixed length. This tends to waste storage space
which
> is at a premium on older devices as well as giving you the opportunity
> to store random "garbage" in the "fields" that your app does not
> populate. I would suggest reading up on packing your records either in
> the forum archives or in Neil Rhodes/Julie McKeehan's book (Palm OS
> Programming, 2nd Edition The Developer's Guide). Another good resource
> is Lonnon Foster's book, Palm OS Programming Bible. Also, the code for
> the installed apps can be helpful in this as well as other issues.
> 
> 
> Matt Andreko wrote:
> > perhaps i'm stupid, or just inexperienced, but what could i do to
stop
> this
> > from happening?  The data in this field will range from 3-20
characters
> > long, so i just said 20 would be good.  I don't mind if it has
spaces
> after
> > it, but i can't have random data, since the data is being parsed
into
> > another program i'm more familiar with.
> >
> >
> >
> > "Sebastian Voges" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> >>On Fri, 06 Jun 2003 15:52:46 -0500, Matt Andreko wrote:
> >>
> >>
> >>>ok, i've seen my mistakes there, and the application is running
fine,
> no
> >>>crashes.
> >>>However, do you see any reason why in my data, there would be
random
> >>
> > letters
> >
> >>>placed there?  i'm looking at the data when i'm pulling it off into
a
> >>
> > text
> >
> >>>file (this program is known to work already), and when reading it
right
> >>
> > off
> >
> >>>the palm using SyncWizard it has a 'p' and a 'DA' in it.
> >>>
> >>>The program that pulls it out has it come like:
> >>>123456789           987654321      p    147258369         DA
> >>>
> >>>any ideas?
> >>>
> >>
> >>Hi Matt,
> >>
> >>I don't know how you read out the data, consider the following
> >>from your code:
> >>
> >>typedef struct {
> >> char Department[20];
> >> char Operator[20];
> >> char RXNumber[20];
> >>} DBRecord;
> >>DBRecordType r;
> >> // fill the record with data
> >>    StrCopy(r.Department, "123456");
> >>    StrCopy(r.Operator, "987654321");
> >>    StrCopy(r.RXNumber, "147258369");
> >>
> >>
> >>
> >>you then write this structure out to the record.
> >>
> >>The data you write will look like this:
> >>
> >>123456\0 followed by 13 bytes of unknown content
> >>987654321\0 followed by 10 bytes of unknown content
> >>147258369\0 followed by 10 bytes of unknown content"
> >>
> >>My point here is that the structure you allocate is 20 bytes for
each
> >>item. You fill out the structure, but there are still unused spaces
(
> e.g.
> >>"1234567" only uses up 7 bytes of the 20 bytes allocation)
> >>
> >>Also you don't zero out the structure after creating it, so there
will
> be
> >>random data in it.
> >>so when you read in the data,you probably see the random data after
your
> >>strings.
> >>
> >>I hope that helps,
> >>
> >>Sebastian
> >>
> >>
> >>
> >
> >
> >
> >
> 
> 
> --
> Steve Jerrett
> Systems Analyst
> City of Columbia, MO
> 
> 
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/support/forums/




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to