IDATABASE_CreateRecord crashing :( | developer.brewmp.com IDATABASE_CreateRecord crashing :( | developer.brewmp.com

Developer

IDATABASE_CreateRecord crashing :(

Forums:

I am trying to store a record in the database, but I can't get it to work. I took some sample code from here on the forums, and added a piece to create a record. Here is what the code looks like:

void testDB() {
IDatabase * pIDatabase = NULL;
IDBMgr *pIDBMgr = NULL;
IShell * pShell = NULL;
AEEApplet * pApp = NULL;
IDBRecord * pIDBRecord = NULL;

pShell = shell;
if (pShell == NULL)
{
DBGPRINTF("error getting pointer to IShell");
return;
}

DBGPRINTF("trying to open database");

if ( ISHELL_CreateInstance(pShell, AEECLSID_DBMGR, (void **)&pIDBMgr) != SUCCESS )
{
DBGPRINTF("error creating dbmgr");
return;
}

if( (pIDatabase = IDBMGR_OpenDatabase (pIDBMgr, "db", TRUE)) == NULL)
{
DBGPRINTF("error opening database");
if (pIDBMgr != NULL)
IDBMGR_Release(pIDBMgr);
return;
}

DBGPRINTF("database opened");

AEEDBField pFieldArray[1];
pFieldArray[0].fType = AEEDB_FT_STRING;
pFieldArray[0].fName = AEEDBFIELD_NONE;
pFieldArray[0].wDataLen = STRLEN("hello");
pFieldArray[0].pBuffer = STRDUP("hello");

DBGPRINTF("array set up");

if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray, 1)) == NULL)
{
DBGPRINTF("error creating record");
if (pIDBMgr != NULL)
IDBMGR_Release(pIDBMgr);
if (pIDatabase != NULL)
IDATABASE_Release(pIDatabase);
}

if (pIDBMgr != NULL)
IDBMGR_Release(pIDBMgr);

if (pIDatabase != NULL)
IDATABASE_Release(pIDatabase);

if (pIDBRecord != NULL)
IDBRECORD_Release(pIDBRecord);

The output is as follows:

trying to open database
database opened
array set up

at that point, the simulator crashes.

Anyone know what I am doing wrong?

-Al

(1)
> pFieldArray[0].fName = AEEDBFIELD_NONE;
Why NONE? Try giving some valid name like AEEDBFIELD_TEXT.
(2)
If that does not work, try
char* s = "hello";
pFieldArray[0].pBuffer = (void*)s;
to see if works.
Best thing to do (for longterm sake) would be to heap-allocate "hello" and then pass the allocated pointer.

(1)
> pFieldArray[0].fName = AEEDBFIELD_NONE;
Why NONE? Try giving some valid name like AEEDBFIELD_TEXT.
(2)
If that does not work, try
char* s = "hello";
pFieldArray[0].pBuffer = (void*)s;
to see if works.
Best thing to do (for longterm sake) would be to heap-allocate "hello" and then pass the allocated pointer.

drvirens wrote:(1)
> pFieldArray[0].fName = AEEDBFIELD_NONE;
Why NONE? Try giving some valid name like AEEDBFIELD_TEXT.
(2)
If that does not work, try
char* s = "hello";
pFieldArray[0].pBuffer = (void*)s;
to see if works.
Best thing to do (for longterm sake) would be to heap-allocate "hello" and then pass the allocated pointer.
Implementing either or both of those causes the exact same behavior. As far as I was aware, the setting for the name does nothing, so I imagine it should work fine with any name. STRDUP() should be equivalent to a heap allocation, so I am already essentially doing that (and never freeing it, so it shouldn't have trouble getting at the data).

drvirens wrote:(1)
> pFieldArray[0].fName = AEEDBFIELD_NONE;
Why NONE? Try giving some valid name like AEEDBFIELD_TEXT.
(2)
If that does not work, try
char* s = "hello";
pFieldArray[0].pBuffer = (void*)s;
to see if works.
Best thing to do (for longterm sake) would be to heap-allocate "hello" and then pass the allocated pointer.
Implementing either or both of those causes the exact same behavior. As far as I was aware, the setting for the name does nothing, so I imagine it should work fine with any name. STRDUP() should be equivalent to a heap allocation, so I am already essentially doing that (and never freeing it, so it shouldn't have trouble getting at the data).

I should probably also note that I'm using GCC to compile for the simulator, so maybe that has something to do with it?

I should probably also note that I'm using GCC to compile for the simulator, so maybe that has something to do with it?

alwold wrote:I should probably also note that I'm using GCC to compile for the simulator, so maybe that has something to do with it?
Yeah, I think it is gcc I'm getting the same thing in the expense tracker app if I compile it with gcc. If I have to use Visual Studio, this is not going to be fun.

alwold wrote:I should probably also note that I'm using GCC to compile for the simulator, so maybe that has something to do with it?
Yeah, I think it is gcc I'm getting the same thing in the expense tracker app if I compile it with gcc. If I have to use Visual Studio, this is not going to be fun.

what version og gcc? this is out curioisty...

what version og gcc? this is out curioisty...

drvirens wrote:what version og gcc? this is out curioisty...
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
I installed it using the cygwin installer a couple months ago.

drvirens wrote:what version og gcc? this is out curioisty...
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
I installed it using the cygwin installer a couple months ago.

hi
me too working on BREW Database...
I do not know how far this will work,but i think the statement
if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray, 1)) == NULL)
[/B]
is creating the problem.
Try replacing it with
if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray[0], 1)) == NULL)
Since u have created 2 fields in ur record( AEEDBField pFieldArray[1] ), u should specify the field u r passing to IDATABASE_CreateRecord()
good luk :)

hi
me too working on BREW Database...
I do not know how far this will work,but i think the statement
if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray, 1)) == NULL)
[/B]
is creating the problem.
Try replacing it with
if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray[0], 1)) == NULL)
Since u have created 2 fields in ur record( AEEDBField pFieldArray[1] ), u should specify the field u r passing to IDATABASE_CreateRecord()
good luk :)

priyapai wrote:hi
me too working on BREW Database...
I do not know how far this will work,but i think the statement
if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray, 1)) == NULL)
[/B]
is creating the problem.
Try replacing it with
if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray[0], 1)) == NULL)
Since u have created 2 fields in ur record( AEEDBField pFieldArray[1] ), u should specify the field u r passing to IDATABASE_CreateRecord()
good luk :)
That results in the error:
error: cannot convert `AEEDBField' to `AEEDBField*' in argument passing
If I try it with &pFieldArray[0] it compiles as expected, but still crashes.
It doesn't crash if I pass 0 for iNumFields, but that is useless, cause it stores no fields (right?)
Has anyone successful gotten DB stuff working in the simulator using gcc to compile? How many people are using gcc to compile for the simulator?

priyapai wrote:hi
me too working on BREW Database...
I do not know how far this will work,but i think the statement
if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray, 1)) == NULL)
[/B]
is creating the problem.
Try replacing it with
if ( (pIDBRecord = IDATABASE_CreateRecord(pIDatabase, pFieldArray[0], 1)) == NULL)
Since u have created 2 fields in ur record( AEEDBField pFieldArray[1] ), u should specify the field u r passing to IDATABASE_CreateRecord()
good luk :)
That results in the error:
error: cannot convert `AEEDBField' to `AEEDBField*' in argument passing
If I try it with &pFieldArray[0] it compiles as expected, but still crashes.
It doesn't crash if I pass 0 for iNumFields, but that is useless, cause it stores no fields (right?)
Has anyone successful gotten DB stuff working in the simulator using gcc to compile? How many people are using gcc to compile for the simulator?

Hi
This is my code,its wrking....
c if it is helpful.....
// Function to Create Data-Base.
// msg_draft is the name of my applet Structure
IDatabase * create_DB(msg_draft * pMe , char * *temp_buffer)
{
IDBRecord * pIDBRecord;
AEEDBField pDBFields[3];
const char * pszFile = "database_file";
// uint16 record_ID;
pDBFields[0].pBuffer =(char *) MALLOC (160 * sizeof(char));
DBGPRINTF("****** START *******");
pMe->pIDatabase = IDBMGR_OpenDatabase(pMe->pIDBMgr,pszFile,TRUE);
if(! pMe->pIDatabase)
{
DBGPRINTF("Error opening database...");
if (pMe->pIDBMgr != NULL)
IDBMGR_Release (pMe->pIDBMgr);
return;
}
DBGPRINTF("****** DB Created *******");
pDBFields[0].fType = AEEDB_FT_STRING;
pDBFields[0].fName = AEEDBFIELD_TEXT;
pDBFields[0].wDataLen = STRLEN(temp_buffer);
strcpy((char *)pDBFields[0].pBuffer,temp_buffer);
pDBFields[1].fType = AEEDB_FT_STRING;
pDBFields[1].fName = AEEDBFIELD_TEXT;
pDBFields[1].wDataLen = STRLEN(temp_buffer);
(char *)pDBFields[1].pBuffer = "INBOX";
DBGPRINTF("****** Before CREATE *******");
pIDBRecord = IDATABASE_CreateRecord( pMe->pIDatabase,pDBFields,2);
// record_ID = IDBRECORD_GetID( pIDBRecord);
DBGPRINTF("****** END *******");
return pMe->pIDatabase;
}

Hi
This is my code,its wrking....
c if it is helpful.....
// Function to Create Data-Base.
// msg_draft is the name of my applet Structure
IDatabase * create_DB(msg_draft * pMe , char * *temp_buffer)
{
IDBRecord * pIDBRecord;
AEEDBField pDBFields[3];
const char * pszFile = "database_file";
// uint16 record_ID;
pDBFields[0].pBuffer =(char *) MALLOC (160 * sizeof(char));
DBGPRINTF("****** START *******");
pMe->pIDatabase = IDBMGR_OpenDatabase(pMe->pIDBMgr,pszFile,TRUE);
if(! pMe->pIDatabase)
{
DBGPRINTF("Error opening database...");
if (pMe->pIDBMgr != NULL)
IDBMGR_Release (pMe->pIDBMgr);
return;
}
DBGPRINTF("****** DB Created *******");
pDBFields[0].fType = AEEDB_FT_STRING;
pDBFields[0].fName = AEEDBFIELD_TEXT;
pDBFields[0].wDataLen = STRLEN(temp_buffer);
strcpy((char *)pDBFields[0].pBuffer,temp_buffer);
pDBFields[1].fType = AEEDB_FT_STRING;
pDBFields[1].fName = AEEDBFIELD_TEXT;
pDBFields[1].wDataLen = STRLEN(temp_buffer);
(char *)pDBFields[1].pBuffer = "INBOX";
DBGPRINTF("****** Before CREATE *******");
pIDBRecord = IDATABASE_CreateRecord( pMe->pIDatabase,pDBFields,2);
// record_ID = IDBRECORD_GetID( pIDBRecord);
DBGPRINTF("****** END *******");
return pMe->pIDatabase;
}

priyapai wrote:Hi
This is my code,its wrking....
c if it is helpful.....
// Function to Create Data-Base.
// msg_draft is the name of my applet Structure
IDatabase * create_DB(msg_draft * pMe , char * *temp_buffer)
{
IDBRecord * pIDBRecord;
AEEDBField pDBFields[3];
const char * pszFile = "database_file";
// uint16 record_ID;
pDBFields[0].pBuffer =(char *) MALLOC (160 * sizeof(char));
DBGPRINTF("****** START *******");
pMe->pIDatabase = IDBMGR_OpenDatabase(pMe->pIDBMgr,pszFile,TRUE);
if(! pMe->pIDatabase)
{
DBGPRINTF("Error opening database...");
if (pMe->pIDBMgr != NULL)
IDBMGR_Release (pMe->pIDBMgr);
return;
}
DBGPRINTF("****** DB Created *******");
pDBFields[0].fType = AEEDB_FT_STRING;
pDBFields[0].fName = AEEDBFIELD_TEXT;
pDBFields[0].wDataLen = STRLEN(temp_buffer);
strcpy((char *)pDBFields[0].pBuffer,temp_buffer);
pDBFields[1].fType = AEEDB_FT_STRING;
pDBFields[1].fName = AEEDBFIELD_TEXT;
pDBFields[1].wDataLen = STRLEN(temp_buffer);
(char *)pDBFields[1].pBuffer = "INBOX";
DBGPRINTF("****** Before CREATE *******");
pIDBRecord = IDATABASE_CreateRecord( pMe->pIDatabase,pDBFields,2);
// record_ID = IDBRECORD_GetID( pIDBRecord);
DBGPRINTF("****** END *******");
return pMe->pIDatabase;
}
I adapted your code to work in my app, and it crashes after the Before CREATE part. You are using gcc to compile for the simulator right? Which version are you using?

priyapai wrote:Hi
This is my code,its wrking....
c if it is helpful.....
// Function to Create Data-Base.
// msg_draft is the name of my applet Structure
IDatabase * create_DB(msg_draft * pMe , char * *temp_buffer)
{
IDBRecord * pIDBRecord;
AEEDBField pDBFields[3];
const char * pszFile = "database_file";
// uint16 record_ID;
pDBFields[0].pBuffer =(char *) MALLOC (160 * sizeof(char));
DBGPRINTF("****** START *******");
pMe->pIDatabase = IDBMGR_OpenDatabase(pMe->pIDBMgr,pszFile,TRUE);
if(! pMe->pIDatabase)
{
DBGPRINTF("Error opening database...");
if (pMe->pIDBMgr != NULL)
IDBMGR_Release (pMe->pIDBMgr);
return;
}
DBGPRINTF("****** DB Created *******");
pDBFields[0].fType = AEEDB_FT_STRING;
pDBFields[0].fName = AEEDBFIELD_TEXT;
pDBFields[0].wDataLen = STRLEN(temp_buffer);
strcpy((char *)pDBFields[0].pBuffer,temp_buffer);
pDBFields[1].fType = AEEDB_FT_STRING;
pDBFields[1].fName = AEEDBFIELD_TEXT;
pDBFields[1].wDataLen = STRLEN(temp_buffer);
(char *)pDBFields[1].pBuffer = "INBOX";
DBGPRINTF("****** Before CREATE *******");
pIDBRecord = IDATABASE_CreateRecord( pMe->pIDatabase,pDBFields,2);
// record_ID = IDBRECORD_GetID( pIDBRecord);
DBGPRINTF("****** END *******");
return pMe->pIDatabase;
}
I adapted your code to work in my app, and it crashes after the Before CREATE part. You are using gcc to compile for the simulator right? Which version are you using?

m working with MS Visual Studio, Version: 6.0

m working with MS Visual Studio, Version: 6.0

Try using
pFieldArray[0].pBuffer = "hello";
instead of
pFieldArray[0].pBuffer = STRDUP("hello");

Try using
pFieldArray[0].pBuffer = "hello";
instead of
pFieldArray[0].pBuffer = STRDUP("hello");

I finally got this working. I needed to add -D WIN32 to the gcc command line.

I finally got this working. I needed to add -D WIN32 to the gcc command line.

hi,
IDatabase * create_DB(msg_draft * pMe , char * *temp_buffer)
In the above what char * *temp_buffer contains what? and what it does?
could you please explain me, its little bit confusing me.
regards
Senthil K

hi,
IDatabase * create_DB(msg_draft * pMe , char * *temp_buffer)
In the above what char * *temp_buffer contains what? and what it does?
could you please explain me, its little bit confusing me.
regards
Senthil K

This coding is not working for me. It show run time error and attempt to exit the simulator. What to do for this?
Exactly the error is, while i try to execute the file it will pop up the windows xp error window and prompt to quit the execution.
regards
Senthil K

This coding is not working for me. It show run time error and attempt to exit the simulator. What to do for this?
Exactly the error is, while i try to execute the file it will pop up the windows xp error window and prompt to quit the execution.
regards
Senthil K

ksenthil_070881 wrote:This coding is not working for me. It show run time error and attempt to exit the simulator. What to do for this?
Exactly the error is, while i try to execute the file it will pop up the windows xp error window and prompt to quit the execution.
regards
Senthil K
Which code are you trying? I would try putting some DBGPRINTF statements in the code to see where it is crashing. For example...
DBGPRINTF("1");
ISHELL_CreateInstance(...
DBGPRINTF("2");
IDATABASE_Open(...
DBGPRINTF("3");
That way you can see which call is making it crash, which will allow us to better guess what the problem is.

ksenthil_070881 wrote:This coding is not working for me. It show run time error and attempt to exit the simulator. What to do for this?
Exactly the error is, while i try to execute the file it will pop up the windows xp error window and prompt to quit the execution.
regards
Senthil K
Which code are you trying? I would try putting some DBGPRINTF statements in the code to see where it is crashing. For example...
DBGPRINTF("1");
ISHELL_CreateInstance(...
DBGPRINTF("2");
IDATABASE_Open(...
DBGPRINTF("3");
That way you can see which call is making it crash, which will allow us to better guess what the problem is.