4 Replies Latest reply on Dec 4, 2013 9:41 PM by pavani.meduri

    sqlite3 not working in nucleus RTOS

    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

        • 1. Re: sqlite3 not working in nucleus RTOS
          Usama_Masood

          Hi Pavani,

           

          Can you please provide some more details on this, preferably the actual code snipt that you are using and the project configuration file.

          Also can you please enable stack error checking if possible (nu.os.kern.plus.core.stack_checking = true).

           

          Regards,

          Usama Masood

          • 2. Re: sqlite3 not working in nucleus RTOS
            pavani.meduri

            Hi Masood,

             

            I have attached the project configuration file. I will try to enable stack checking when possible and let you know the results.

             

            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);

             

             

            Later as mentioned earlier i tried splitting this function call to prepare, step and finalize and the code snippet for that code is:

                        // Execute the query for creating the table

             

             

                        retval = sqlite3_prepare_v2(

                                    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))",

                                   -1,

                                   &stmt,

                                   0);

             

             

                        if(0 == retval)

                        {  

                            // fetch a row's status

                            retval = sqlite3_step(stmt);

             

             

                            if(retval == SQLITE_DONE)

                            {

                                // Finalize to free prepared statement

                                retval = sqlite3_finalize(stmt);

                            }

                            else

                            {

                                printf("Create table failed = %d\n", retval);

                            }

                        }  

             

            With the above function calls the exception occurs during sqlite3_step( ).

            • 3. Re: sqlite3 not working in nucleus RTOS
              Usama_Masood

              I have tried to reproduce this on my system but I did not see any exception.

              I have attached my application source. Can you please try this on your setup, if exception still reproduces then I will try to reproduce it on sead3.

               

              Regards,

              Usama Masood

              • 4. Re: sqlite3 not working in nucleus RTOS
                pavani.meduri

                Hi Masood,

                 

                I will try with your application and let you know, currently i am working on some other high priority task, once done with this will try it out and let you know the results.

                 

                Thanks,

                Pavani