This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sqlite:create table success but insert fails

Hi

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

  • I want to port sqlite in freertos. can you please provide the step to porting?

    Now I have include sqlite3.c and sqlite3.h file, but I am getting error like

    ..\Core\Src\shell.c(182): error: #5: cannot open source input file "sys/resource.h": No such file or directory

    please give me step to port a qtlite in freertos. I am also using STM32746g-Eval2 board