For some bizarre reason, this code which opens, or creates and then opens -
a database works great on POSE, all ROM versions, but fails in real devices.
I have (want) two databases and on the second run through this function, it
finds the database (which doesn't exist) and then fails to open it becuase
it cant find the resource.  I will donate $50 to your favorite charity to
the person who can solve this problem.

///////////Here is where it is called:
static int StartApplication(void)
{
    UInt                mode = dmModeReadWrite;
    Err                     err = 0;
    Boolean                 createdProducts;
    Boolean                 createdShoppingList;
    // Determime if secret records should be shown.
    gHideSecretRecords = PrefGetPreference(prefHidePrivateRecords);
    if (!gHideSecretRecords)
        mode |= dmModeShowSecret;

    // Find the Product database.  If it doesn't exist, create it.
    err = OpenOrCreateDB(&gProductsDB, 'TABL','INBK', mode,
        0, "TBLPRODUCTS-INBK", &createdProducts);

 if (err)
  {
  CharPtr error = MemPtrNew(sizeof(char[30]));
  StrIToA(error,err);
  FrmCustomAlert(GeneralInfoAlert,"Product Error",error,NULL);
  MemPtrFree(error);
  }
 CategoryGetName (gProductsDB, CurrentProductsCategory,
ProductsCategoryName);
 if (*ProductsCategoryName == 0)
  {
  CurrentProductsCategory = dmAllCategories;
  ShowAllProductCategories = true;
  }

    // Find the Shopping database.  If it doesn't exist, create it.
    err = OpenOrCreateDB(&gShoppingDB, 'TABL', 'INBK', mode,
        0, "TBLSHOPPINGLIST-INBK", &createdShoppingList);
...
/////////////////and here is the function:
 // open a database. If it doesn't exist, create it.
static Err OpenOrCreateDB(DmOpenRef *dbP, ULong type, ULong creator,
    ULong mode, UInt cardNo, char *name, Boolean *created)
{
    Err   err;
    LocalID local = DmFindDatabase(0,name);
    *created = false;
    if (! local)// Can't find database, so create it.
     {
        err = DmCreateDatabase(0, name, creator, type, false);
        if (err)
            return err;
        *created = true;
        local = DmFindDatabase(0,name);
        *dbP = DmOpenDatabase(0,local, mode);
        if (! *dbP)
            return DmGetLastErr();
         AppInfoInit(*dbP);
        if (StrCompare(name,SHOPPING_LIST_DB_NAME) == 0) // if they match
         {
   gLastActiveForm = FrmHelloForm;
   SetLastActiveForm();
   }
     }
    else
        *dbP = DmOpenDatabase(0,local, mode);
    if (! *dbP)
     {
        err = DmCreateDatabase(0, name, creator, type, false);
        if (err)
            return err;
        *created = true;
        local = DmFindDatabase(0,name);
        *dbP = DmOpenDatabase(0,local, mode);
        if (! *dbP)
            return DmGetLastErr();
         AppInfoInit(*dbP);
        }
    return err;
}





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

Reply via email to