--- "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?

I can definitely tell you that the code below is not the best way to
handle this task. :)

> DmOpenRef gSRCatDB = 0;
> #define kSRCatDB_DBName     "myDB"
> #define kCreator            "TEST"
> #define kDBType             "DATA"
> 
> gSRCatDB = DmOpenDatabase(0, DmFindDatabase(0,kSRCatDB_DBName),
dmModeReadWrite);

You should use 2 lines for this and check the result of
DmFindDatabase() before calling DmOpenDatabase().

> 
> /* 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);
> 
>     if (!gSRCatDB)
>        return DmGetLastErr();
> }
> 
> 
> 
> -- 
> For information on using the Palm Developer Forums, or to
> unsubscribe, please see http://www.palmos.com/dev/support/forums/


__________________________________________________
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/

Reply via email to