pavani.meduri

sqlite3 not working in nucleus RTOS

Discussion created by pavani.meduri on Nov 12, 2013
Latest reply on Dec 4, 2013 by pavani.meduri

The following issues are seen when trying to use sqlite3 in nucleus RTOS:

 

sqlite3_open() was successful in opening a database. Later when trying to create a table using sqlite3_exec() an exception error occurs.


Code snippet of sqlite3_exec function call in my code:

            // Execute the query for creating the table

            retval = sqlite3_exec(

                        handle,

                       "CREATE TABLE IF NOT EXISTS AudioRecords \

                       (TrackId int, Duration int(2), ReleaseYear int, TrackNo char, PlayCount short, MetadataSize int, ID3V1 char, \

                       FileName varchar(255), SongTitle varchar(90), AlbumTitle varchar(90), ArtistName varchar(90), MusicGenre varchar(90))",

                       0,

                       0,

                       0);



The above same code works fine in linux.



On debugging i found that after sqlite3Prepare(), there was a call to generateColumnNames() and from there the sequence of function calls are like this:

generateColumnNames()->sqlite3VdbeSetColName()->sqlite3VdbeMemSetStr()->sqlite3VdbeMemGrow()->sqlite3DbMallocSize()


In sqlite3DbMallocSize() the following line gives exception error:

if( db && isLookaside(db, p) )

The reason for exception is in function isLookaside 'p' pointer is accessed which is NULL in this case. 'p' parameter passed is pMem->zMalloc which is NULL. There are other members in pMem like db that are proper.


Later i tried to add a check in sqlite3DbMallocSize() to check if 'p' is not NULL as provided below:

if(NULL != p)

{

if( db && isLookaside(db, p) )

....

}

If 'p' is NULL then this function simply returns. After this in sqlite3VdbeMemGrow() again memory is allocated to pMem->zMalloc as the following code is executed:

else{

      sqlite3DbFree(pMem->db, pMem->zMalloc);

      pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);

    }

}


After that code change sqlite3_exec() executed fine till exec_out:

After this sqlite3VdbeFinalize() again an exception occured.


Not sure if this is due to the fix made or some other issue.


Later i tried changing the sqlite3_exec() call to sqlite3_prepare_v2(), sqlite_step(), sqlite3_finalize(), as i observed that sqlite3_exec is a legacy function though internally sqlite3_exec() calls sqlite3_prepare_v2(), sqlite_step() and sqlite3_finalize().


With this code also sqlite3_step() gave an exception error. With the above fix in code, observed that exception occurs in sqlite3_finalize() function.



Please help in resolving the above issues to proceed further.

 

 

Thanks,

Pavani

Outcomes