Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi,

I need to clear all the database files on the device, so I tried to use IDBMGR_Release and IDBMGR_Remove in my code. However, both API crashed on my simulator. Does anyone meet with this problem before and how to solve it?

 

The related code is :

static void resetAccounts(TXTBLUIMockup * pMockUp)

{

//$cleanup list_t accounts = NULL;

AccountDatabase * accountDatabase;

DatabaseManager * dbm = NULL;

boolean success = FALSE;

 

TXTBLBIGDBGPRINTF("resetAccounts");

 

accountDatabase = getAccountDatabase(pMockUp);

dbm = getManager(pMockUp);

 

destroyAccounts(accountDatabase->accounts);

 

if (NULL != accountDatabase->db.idb)

{

uint32 refCount = 0;

while(0 != (refCount = IDATABASE_Release(accountDatabase->db.idb)));

TXTBLBIGDBGPRINTF("refCount when releasing database %s %d", accountDatabase->db.name, refCount);

accountDatabase->db.idb = NULL;

}

if (dbm->imgr)

   {

 

IDBMGR_Release(dbm->imgr); // crash

   }

success = IDBMGR_Remove(dbm->imgr, accountDatabase->db.name); // crash

TXTBLBIGDBGPRINTF("DATABASE Remove returned %d", success);

freeIfWrapper(accountDatabase,__TXTBL__FILE__,__TXTBL__LINE__);

}

Which BrewMP version you are using, i tried with BrewMP ver 1.0.4.91 and i could not reproduced this.
Below is the code:
 
IDBMgr * pIDBMgr = NULL;
IDatabase * pIDatabase = NULL;
IDBRecord * pIDBRecord1 = NULL;
IDBRecord * pIDBRecord2 = NULL;
IDBRecord * pIDBRec1 = NULL;
IDBRecord * pIDBRec2 = NULL;
int nRetVal = EBADFILENAME;
AEEDBField dbField1[2];
AEEDBField dbField2[3];
uint32 recordCount = 0;
const char firstName [] = "John";
const char lastName [] = "Smith";
const char fullName [] = "Jane Smith";
uint16 category = 123;
uint32 homePhone = 7654321;
char szBuf[30] = {0};
AEEDBFieldType fieldType;
AEEDBFieldName fieldName;
uint16 fieldLen, recId = 0;
byte * data = NULL;
uint16 wordValue = 0;
uint32 dwordValue = 0;
boolean bRetValue = FALSE;
AECHAR * psz = NULL;

dbField1[0].fName = AEEDBFIELD_FIRSTNAME;
dbField1[0].fType = AEEDB_FT_STRING;
dbField1[0].pBuffer = (void *)firstName;
dbField1[0].wDataLen = STRLEN (firstName);

dbField1[1].fName = AEEDBFIELD_LASTNAME;
dbField1[1].fType = AEEDB_FT_STRING;
dbField1[1].pBuffer = (void *)lastName;
dbField1[1].wDataLen = STRLEN (lastName);

dbField2[0].fName = AEEDBFIELD_LASTNAME;
dbField2[0].fType = AEEDB_FT_STRING;
dbField2[0].pBuffer = (void *)&fullName;
dbField2[0].wDataLen = STRLEN (fullName);

dbField2[1].fName = AEEDBFIELD_CATEGORY;
dbField2[1].fType = AEEDB_FT_WORD;
dbField2[1].pBuffer = (void *)&category;
dbField2[1].wDataLen = sizeof (uint16);

dbField2[2].fName = AEEDBFIELD_HOME_PHONE;
dbField2[2].fType = AEEDB_FT_DWORD;
dbField2[2].pBuffer = (void *)&homePhone;
dbField2[2].wDataLen = sizeof (uint32);

ISHELL_CreateInstance(pIShell, AEECLSID_DBMGR, (void **)&pIDBMgr);

if (pIDBMgr == NULL)
return;

if ((pIDatabase = IDBMGR_OpenDatabase (pIDBMgr, "db", TRUE)) == NULL)
{
IDBMGR_Release (pIDBMgr);
return;
}
pIDBRecord1 = IDATABASE_CreateRecord (pIDatabase, dbField1, 2);
pIDBRecord2 = IDATABASE_CreateRecord (pIDatabase, dbField2, 3);

if (pIDBRecord1 == NULL || pIDBRecord2 == NULL)
{
if (pIDBRecord1 != NULL)
IDBRECORD_Release (pIDBRecord1);
if (pIDBRecord2 != NULL)
IDBRECORD_Release (pIDBRecord2);

IDATABASE_Release (pIDatabase);
IDBMGR_Remove (pIDBMgr, "db");
IDBMGR_Release (pIDBMgr);
return;
}

IDBRECORD_Release (pIDBRecord1);
IDBRECORD_Release (pIDBRecord2);

recordCount = IDATABASE_GetRecordCount (pIDatabase);

SPRINTF (szBuf, "Record Count: %u", recordCount);
DisplayOutput(pMe, 1, szBuf);

IDATABASE_Reset (pIDatabase);

pIDBRec1 = IDATABASE_GetNextRecord (pIDatabase);

if (pIDBRec1 != NULL)
{
if ((fieldType = IDBRECORD_NextField (pIDBRec1, &fieldName,
&fieldLen)) == AEEDB_FT_STRING)
{
if ((data = IDBRECORD_GetField (pIDBRec1, &fieldName,
&fieldType, &fieldLen)) != NULL)
{
SPRINTF (szBuf, "First Name: %s", (char *)data);
DisplayOutput (pMe, 2, szBuf);
}
}

if ((fieldType = IDBRECORD_NextField (pIDBRec1, &fieldName,
&fieldLen)) == AEEDB_FT_STRING)
{

if ((data = IDBRECORD_GetField (pIDBRec1, &fieldName,
&fieldType, &fieldLen)) != NULL)
{

SPRINTF (szBuf, "Last Name: %s", (char *)data);
DisplayOutput (pMe, 3, szBuf);
}
}
IDBRECORD_Release(pIDBRec1);
}

pIDBRec2 = IDATABASE_GetNextRecord (pIDatabase);

if (pIDBRec2 != NULL)
{
IDBRecord * pRec = NULL;

recId = IDBRECORD_GetID (pIDBRec2);

IDBRECORD_Release(pIDBRec2);

SPRINTF (szBuf, "Record 2 ID: %u", recId);
DisplayOutput (pMe, 4, szBuf);

pRec = IDATABASE_GetRecordByID (pIDatabase, recId);
fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen);
fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen);
fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen);

IDBRECORD_Reset (pRec);

if ((fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen))
== AEEDB_FT_STRING)
{
if ((psz = IDBRECORD_GetFieldString (pRec)) != NULL)
{
SPRINTF (szBuf, "Field 1 value: %s", psz);
DisplayOutput (pMe, 5, szBuf);
}
}

if ((fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen))
== AEEDB_FT_WORD)
{
if ((bRetValue = IDBRECORD_GetFieldWord (pRec, &wordValue)) == TRUE)
{
SPRINTF (szBuf, "Field 2 value: %u",wordValue);
DisplayOutput (pMe, 6, szBuf);
}
}

if ((fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen))
== AEEDB_FT_DWORD)
{
if ((bRetValue = IDBRECORD_GetFieldDWord (pRec, &dwordValue)) == TRUE)
{
SPRINTF (szBuf, "Field 3 value: %u", dwordValue);
DisplayOutput (pMe, 7, szBuf);
}
}

dbField2[0].fName = AEEDBFIELD_LASTNAME;
dbField2[0].fType = AEEDB_FT_STRING;
dbField2[0].pBuffer = (void *)&lastName;
dbField2[0].wDataLen = STRLEN (lastName);

if ((nRetVal = IDBRECORD_Update (pRec, dbField2, 1)) == SUCCESS)
{
if ((fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen))
== AEEDB_FT_STRING)
{
if ((psz = IDBRECORD_GetFieldString (pRec)) != NULL)
{
SPRINTF (szBuf, "Updated value: %s", psz);
DisplayOutput (pMe, 8, szBuf);
}
}
}
IDBRECORD_Release(pRec);
}

IDATABASE_Release (pIDatabase);
IDBMGR_Remove (pIDBMgr, "db");
IDBMGR_Release (pIDBMgr);
Also note that this interface has been deprecated in BrewMP. Refer to the dbc_ifactory interface instead.

Which BrewMP version you are using, i tried with BrewMP ver 1.0.4.91 and i could not reproduced this.
Below is the code:
 
IDBMgr * pIDBMgr = NULL;
IDatabase * pIDatabase = NULL;
IDBRecord * pIDBRecord1 = NULL;
IDBRecord * pIDBRecord2 = NULL;
IDBRecord * pIDBRec1 = NULL;
IDBRecord * pIDBRec2 = NULL;
int nRetVal = EBADFILENAME;
AEEDBField dbField1[2];
AEEDBField dbField2[3];
uint32 recordCount = 0;
const char firstName [] = "John";
const char lastName [] = "Smith";
const char fullName [] = "Jane Smith";
uint16 category = 123;
uint32 homePhone = 7654321;
char szBuf[30] = {0};
AEEDBFieldType fieldType;
AEEDBFieldName fieldName;
uint16 fieldLen, recId = 0;
byte * data = NULL;
uint16 wordValue = 0;
uint32 dwordValue = 0;
boolean bRetValue = FALSE;
AECHAR * psz = NULL;

dbField1[0].fName = AEEDBFIELD_FIRSTNAME;
dbField1[0].fType = AEEDB_FT_STRING;
dbField1[0].pBuffer = (void *)firstName;
dbField1[0].wDataLen = STRLEN (firstName);

dbField1[1].fName = AEEDBFIELD_LASTNAME;
dbField1[1].fType = AEEDB_FT_STRING;
dbField1[1].pBuffer = (void *)lastName;
dbField1[1].wDataLen = STRLEN (lastName);

dbField2[0].fName = AEEDBFIELD_LASTNAME;
dbField2[0].fType = AEEDB_FT_STRING;
dbField2[0].pBuffer = (void *)&fullName;
dbField2[0].wDataLen = STRLEN (fullName);

dbField2[1].fName = AEEDBFIELD_CATEGORY;
dbField2[1].fType = AEEDB_FT_WORD;
dbField2[1].pBuffer = (void *)&category;
dbField2[1].wDataLen = sizeof (uint16);

dbField2[2].fName = AEEDBFIELD_HOME_PHONE;
dbField2[2].fType = AEEDB_FT_DWORD;
dbField2[2].pBuffer = (void *)&homePhone;
dbField2[2].wDataLen = sizeof (uint32);

ISHELL_CreateInstance(pIShell, AEECLSID_DBMGR, (void **)&pIDBMgr);

if (pIDBMgr == NULL)
return;

if ((pIDatabase = IDBMGR_OpenDatabase (pIDBMgr, "db", TRUE)) == NULL)
{
IDBMGR_Release (pIDBMgr);
return;
}
pIDBRecord1 = IDATABASE_CreateRecord (pIDatabase, dbField1, 2);
pIDBRecord2 = IDATABASE_CreateRecord (pIDatabase, dbField2, 3);

if (pIDBRecord1 == NULL || pIDBRecord2 == NULL)
{
if (pIDBRecord1 != NULL)
IDBRECORD_Release (pIDBRecord1);
if (pIDBRecord2 != NULL)
IDBRECORD_Release (pIDBRecord2);

IDATABASE_Release (pIDatabase);
IDBMGR_Remove (pIDBMgr, "db");
IDBMGR_Release (pIDBMgr);
return;
}

IDBRECORD_Release (pIDBRecord1);
IDBRECORD_Release (pIDBRecord2);

recordCount = IDATABASE_GetRecordCount (pIDatabase);

SPRINTF (szBuf, "Record Count: %u", recordCount);
DisplayOutput(pMe, 1, szBuf);

IDATABASE_Reset (pIDatabase);

pIDBRec1 = IDATABASE_GetNextRecord (pIDatabase);

if (pIDBRec1 != NULL)
{
if ((fieldType = IDBRECORD_NextField (pIDBRec1, &fieldName,
&fieldLen)) == AEEDB_FT_STRING)
{
if ((data = IDBRECORD_GetField (pIDBRec1, &fieldName,
&fieldType, &fieldLen)) != NULL)
{
SPRINTF (szBuf, "First Name: %s", (char *)data);
DisplayOutput (pMe, 2, szBuf);
}
}

if ((fieldType = IDBRECORD_NextField (pIDBRec1, &fieldName,
&fieldLen)) == AEEDB_FT_STRING)
{

if ((data = IDBRECORD_GetField (pIDBRec1, &fieldName,
&fieldType, &fieldLen)) != NULL)
{

SPRINTF (szBuf, "Last Name: %s", (char *)data);
DisplayOutput (pMe, 3, szBuf);
}
}
IDBRECORD_Release(pIDBRec1);
}

pIDBRec2 = IDATABASE_GetNextRecord (pIDatabase);

if (pIDBRec2 != NULL)
{
IDBRecord * pRec = NULL;

recId = IDBRECORD_GetID (pIDBRec2);

IDBRECORD_Release(pIDBRec2);

SPRINTF (szBuf, "Record 2 ID: %u", recId);
DisplayOutput (pMe, 4, szBuf);

pRec = IDATABASE_GetRecordByID (pIDatabase, recId);
fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen);
fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen);
fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen);

IDBRECORD_Reset (pRec);

if ((fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen))
== AEEDB_FT_STRING)
{
if ((psz = IDBRECORD_GetFieldString (pRec)) != NULL)
{
SPRINTF (szBuf, "Field 1 value: %s", psz);
DisplayOutput (pMe, 5, szBuf);
}
}

if ((fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen))
== AEEDB_FT_WORD)
{
if ((bRetValue = IDBRECORD_GetFieldWord (pRec, &wordValue)) == TRUE)
{
SPRINTF (szBuf, "Field 2 value: %u",wordValue);
DisplayOutput (pMe, 6, szBuf);
}
}

if ((fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen))
== AEEDB_FT_DWORD)
{
if ((bRetValue = IDBRECORD_GetFieldDWord (pRec, &dwordValue)) == TRUE)
{
SPRINTF (szBuf, "Field 3 value: %u", dwordValue);
DisplayOutput (pMe, 7, szBuf);
}
}

dbField2[0].fName = AEEDBFIELD_LASTNAME;
dbField2[0].fType = AEEDB_FT_STRING;
dbField2[0].pBuffer = (void *)&lastName;
dbField2[0].wDataLen = STRLEN (lastName);

if ((nRetVal = IDBRECORD_Update (pRec, dbField2, 1)) == SUCCESS)
{
if ((fieldType = IDBRECORD_NextField(pRec, &fieldName, &fieldLen))
== AEEDB_FT_STRING)
{
if ((psz = IDBRECORD_GetFieldString (pRec)) != NULL)
{
SPRINTF (szBuf, "Updated value: %s", psz);
DisplayOutput (pMe, 8, szBuf);
}
}
}
IDBRECORD_Release(pRec);
}

IDATABASE_Release (pIDatabase);
IDBMGR_Remove (pIDBMgr, "db");
IDBMGR_Release (pIDBMgr);
Also note that this interface has been deprecated in BrewMP. Refer to the dbc_ifactory interface instead.

I'm using the BrewSDK v3.1.5. However, I didn't find the dbc_ifactory interface from the API document. What other interface can i use to delete the database file please?

I'm using the BrewSDK v3.1.5. However, I didn't find the dbc_ifactory interface from the API document. What other interface can i use to delete the database file please?

dbc_ifactory  is avialable in BrewMP

dbc_ifactory  is avialable in BrewMP

For Brew IDBMGR_Remove is the only API for removing db.

For Brew IDBMGR_Remove is the only API for removing db.