4

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);
Nitin Bhosale
  • 41
  • 1
  • 3
  • 1
    Does your embedded platform have working storage? Does the file specified in your code exist; if so, is there any data already in it? –  Mar 02 '16 at 06:28
  • The STM32(ARM cortex M4) platform has a NOR flash and onto it there is a FAT FS. The DB file getting created and table is also getting created in it, but when we do insert it fails with error 26(file is encrypted or is not a database). – Nitin Bhosale Mar 02 '16 at 09:06
  • You did not set SQLITE_TEMP_STORE as specified in the demovfs documentation. Anyway, you have to trace the actual file system calls to find out where the wrong data comes from. – CL. Mar 03 '16 at 07:40
  • Sqlite 3.12 does not have large support for SQLITE_OS_OTHER=1, so when code evolved from 3.6.22 version Sqlite has not maintained code under SQLITE_OS_OTHER. – Nitin Bhosale Mar 04 '16 at 04:36
  • 1
    I had fixed the issue for error no: 26(SQLITE_NOTADB) in file "http://www.sqlite.org/src/doc/trunk/src/test_demovfs.c" by creating the journal file in (CREATE_NEW |READ |WRITE) mode in demoOpen() function, because the issue was that behavior for " SQLITE_OS_OTHER =1" that the journal mode set is "journal_mode=DELETE" but the journal file is always opened in "READ_ONLY" mode because in function "sqlite3PagerSharedLock()" the value of "pPager->eState" is PAGER_OPEN and hence it sets "bHotJournal" to "1" and opens journal file in "READ_ONLY" mode – Nitin Bhosale Mar 04 '16 at 04:45
  • @NitinBhosale I'm looking to add SQLite support to a ARM Cortex M4 on TI's CC3200. I was wondering if you would be willing to share the code that you got to work on the STM32 platform? – Jonathan Nov 18 '17 at 05:27

0 Answers0