mardi 1 mars 2016

SQLITE Porting on FreeRTOS with STM32

I am trying to port sqlite3 VFS implementation on freertos with stm32. I have created an amalgamation with sqlite3 version 3.12 base code.

When I run the below code it runs to create a database and a query "create a table cars". But when query "insert" is run then fails with following error:- error no: 26(SQLITE_NOTADB) error: "file is encrypted or is not a database"

I have given following options during compile: SQLITE_THREADSAFE=0 SQLITE_OS_OTHER=1 SQLITE_OMIT_WAL=1

Any pointer would really help.

Have a sample code as below:

sqlite3 *db = NULL;
char *zErrMsg = 0;
int rc;
char *sql;


rc = sqlite3_vfs_register(sqlite3_demovfs(), 1); /* Register a VFS */
if(rc != SQLITE_OK)
{
    abort();
}

rc = sqlite3_open_v2("testsql.db", &db, SQLITE_OPEN_READWRITE |   
SQLITE_OPEN_CREATE , "demo" );/* Create a SQL table */
if( rc )
{
    abort();
}

sql = "PRAGMA journal_mode=OFF";/* Create SQL statement */
rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);/* Execute SQL statement */
if( rc != SQLITE_OK )
{
    sqlite3_free(zErrMsg);
    abort();
}

sql ="CREATE TABLE Cars(Id INT, Name TEXT, Price INT);" ;/* Create SQL statement */
rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);/* Execute SQL statement */
if( rc != SQLITE_OK )
{
    sqlite3_free(zErrMsg);
    abort();
}

sql = "INSERT INTO Cars VALUES(1, 'Audi', 52642);"/* Create SQL statement */
        "INSERT INTO Cars VALUES(2, 'Skoda', 9000);";
rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);/* Execute SQL statement */
if( rc != SQLITE_OK )
{
    sqlite3_free(zErrMsg);
    abort();
}

sql = "SELECT * from Cars";/* Create SQL statement */
const char* data = "Callback function called";
rc = sqlite3_exec(db, sql, callback, (void *)data, &zErrMsg);/* Execute SQL statement */
if( rc != SQLITE_OK )
{
    sqlite3_free(zErrMsg);
    abort();
}
sqlite3_close(db);

Aucun commentaire:

Enregistrer un commentaire