OOPS! I hit send before I was done...
--- "Edward P. Ross" <[EMAIL PROTECTED]> wrote:
> In my app. I want to check to see if a database exists, if
> it doesn't I want to create it. Can someone look at the
> code below and tell me if this is the best way to handle
> this task?
ditto what I said before. :)
>
> DmOpenRef gSRCatDB = 0;
> #define kSRCatDB_DBName "myDB"
> #define kCreator "TEST"
> #define kDBType "DATA"
>
> gSRCatDB = DmOpenDatabase(0, DmFindDatabase(0,kSRCatDB_DBName),
> dmModeReadWrite);
This should be done with 2 lines, checking the result of
DmFindDatabase() before calling DmOpenDatabase(). For example:
LocalID lid = DmFindDatabase(0, kSRCatDB_DBName);
if (lid)
{
gSRCatDB = DmOpenDatabase(0, lid), dmModeReadWrite);
>
> /* If it doesn't exist, create it. */
> if (!gSRCatDB) {
> error = DmCreateDatabase(0, kSRCatDB_DBName, kCreator, kDBType,
> false);
>
> if (error)
> return error;
>
> /* If there is no error creating the database, open it. */
> gSRCatDB = DmOpenDatabase(0, DmFindDatabase(0,kSRCatDB_DBName),
> dmModeReadWrite);
>
Here, you should use the local id from before. e.g.,
gSRCatDB = DmOpenDatabase(0, lid, dmModeReadWrite);
> if (!gSRCatDB)
> return DmGetLastErr();
> }
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/