Maybe there is a padding byte between the ttype and seconds,
so the struct you are using, is treated by the compiler (in order to
preserve 2byte aligment) like this:

typedef struct FuelsDBType
{
 char ttype;
------- char padding;---------
 UInt32 seconds;  // Timestamp
 char tailno[9];
 char amount[11];
} FuelsDBType;

----- Original Message -----
From: "Ray Marron" <[EMAIL PROTECTED]>
Newsgroups: palm-dev-forum
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Monday, February 17, 2003 19:12
Subject: Prob reading uint32 from db


> I added a UInt32 value in my Palm app's database to act as a timestamp
that
> gets its value from TimGetSeconds() just before the record is saved.  When
I
> read this value back out, it is always a much smaller value.  I'm sure I'm
> messing it up during the save or retrieval.  Can somebody take a look at
my
> code and see if you can notice anything I'm doing wrong?  This is my first
> Palm app, and most of my save/load code was taken from CW and book
examples.
> If there is some code you would like to see that I haven't included, just
> request it.
>
> For example, if I save a record with a timestamp of 3128320727 (the
morning
> of 2003-02-17), it gets read back as 1985899456 (sometime in 1966!).
There
> doesn't seem to be a constant difference between the saved/read values,
but
> the difference is always ~1.141 billion.
>
> Pasted from my app's header file:
>
> typedef struct FuelsDBType
> {
>  char ttype;
>  UInt32 seconds;  // Timestamp
>  char tailno[9];
>  char amount[11];
> } FuelsDBType;
>
> typedef FuelsDBType* FuelsDBPtr;
>
> #define FDB_TTYPE_START    0
> #define FDB_TTYPE_SIZE     sizeof(char)
> #define FDB_SECONDS_START  (FDB_TTYPE_START + FDB_TTYPE_SIZE)
> #define FDB_SECONDS_SIZE   sizeof(UInt32)
> #define FDB_TAILNO_START   (FDB_SECONDS_START + FDB_SECONDS_SIZE)
> #define FDB_TAILNO_SIZE    9
> #define FDB_AMOUNT_START   (FDB_TAILNO_START + FDB_TAILNO_SIZE)
> #define FDB_AMOUNT_SIZE    11
>
> #define FDB_RECSIZE     (FDB_AMOUNT_START + FDB_AMOUNT_SIZE)
>
> The seconds value was formerly at the end of the struct. I moved it up
> behind ttype in case my string saving was buggy but it didn't change
> anything.
>
> From my app's database.c:
>
> Err AddToDatabase(FuelsDBPtr recordP)
> {
>  Err error = errNone;
>  UInt16 recIndex = dmMaxRecordIndex;
>  MemHandle recH;
>  MemPtr recP;
>
>  recH = DmNewRecord(gDB, &recIndex, FDB_RECSIZE);
>  if (recH) {
>   recP = MemHandleLock(recH);
>   DmWrite(recP, FDB_TTYPE_START, &recordP->ttype,
>           FDB_TTYPE_SIZE);
>   DmWrite(recP, FDB_SECONDS_START, &recordP->seconds,
>           FDB_SECONDS_SIZE);
>   DmWrite(recP, FDB_TAILNO_START, recordP->tailno,
>           FDB_TAILNO_SIZE);
>   DmWrite(recP, FDB_AMOUNT_START, recordP->amount,
>           FDB_AMOUNT_SIZE);
>   error = DmReleaseRecord(gDB, recIndex, true);
>   MemHandleUnlock(recH);
>  }
>
>  if (error == errNone)
>   return 0;
>  else
>   return DmGetLastErr();
> }
>
>
> Err GetFromDatabase(FuelsDBPtr recordP, UInt32 cursor)
> {
>     MemHandle recH;
>     FuelsDBPtr recP;
>     Err error = 0;
>
>     recH = DmQueryRecord(gDB, cursor);
>     if (recH)
>     {
>         recP = (FuelsDBPtr)MemHandleLock(recH);
>         recordP->ttype = recP->ttype;
>         recordP->seconds = recP->seconds;
>         StrCopy(recordP->tailno, recP->tailno);
>         StrCopy(recordP->amount, recP->amount);
>         MemHandleUnlock(recH);
>     }
>     else
>      error = DmGetLastErr();
>     return error;
> }
>
> Thanks for your help!
>
> --
> Ray Marron
>
>
>
> --
> 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