Dear Jonathan, Thank you very much for this information.
I am using sqlite.c SQLITE_AMALGAMATION old version code. I think that lastest version is almost same with old version. I used below predefine option for building sqlite3.c -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_COMPLETE -DSQLITE_OMIT_WAL=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 Because there is file locking problem due to fcntl(F_SETLK) unsupported feature, DB file access is error. Therefore, I just modify this in below; I inserted predefine option(#define USE_RTEMS) static int unixFileLock(unixFile *pFile, struct flock *pLock){ int rc; unixInodeInfo *pInode = pFile->pInode; assert( unixMutexHeld() ); assert( pInode!=0 ); if( ((pFile->ctrlFlags & UNIXFILE_EXCL)!=0 || pInode->bProcessLock) && ((pFile->ctrlFlags & UNIXFILE_RDONLY)==0) ){ if( pInode->bProcessLock==0 ){ struct flock lock; assert( pInode->nLock==0 ); lock.l_whence = SEEK_SET; lock.l_start = SHARED_FIRST; lock.l_len = SHARED_SIZE; lock.l_type = F_WRLCK; rc = osFcntl(pFile->h, F_SETLK, &lock); #ifndef USE_RTEMS if( rc<0 ) return rc; #endif pInode->bProcessLock = 1; pInode->nLock++; }else{ rc = 0; } }else{ rc = osFcntl(pFile->h, F_SETLK, pLock); } #ifndef USE_RTEMS return rc; #else return 0; #endif } Whenever fcntl(F_SETLK) is used, I fcntl always return 0(successful). After I modify this, there is not problem using simple sqlite example code(attached: main.c). But, there is side-effect(for example: memory leaking issue by locking patch code) in my customer side using RTEMS. I have tried to build sqlite using rtems-source-builder as this reason. I guess that there is additional predefine option for resolving this. Best Regards, JunBeom -----Original Message----- From: Jonathan Brandmeyer <jbrandme...@planetiq.com> Sent: Tuesday, March 26, 2019 11:25 PM To: JunBeom Kim <jb...@e-coretech.kr> Cc: users@rtems.org Subject: Re: Sqlite building failure using rtems-source-builder My team hasn't gotten to the stage of actually using SQLite in the RTEMS environment yet, but it builds just fine. We don't use rtems-source-builder to do it. We are just using the latest stable amalgamation release, supplied by sqlite.org. We build it with the same options that the configure script normally uses to build a .so on Linux, except that we also specify -DSQLITE_OMIT_LOAD_EXTENSION. I've seen some documentation to the effect that rtems actually does support dlopen/dlsym, but we haven't tried it and we don't need it for our mission. If I understand correctly, the only conflicts with RTEMS should be SQLIte's dependency on mmap. RTEMS does not provide virtual memory at all, so mmap and kin are only stub functions that return an error. The SQLite3 documentation does describe how to configure the write-ahead log (WAL) in such a way that it should not rely on mmap at runtime, though. Hope that helps, -- Jonathan Brandmeyer
#include <stdlib.h> #include <stdbool.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <fcntl.h> #include <bsp.h> #include <sqlite3.h> static int callback(void *NotUsed, int argc, char **argv, char **azColName) { int i; for(i = 0; i<argc; i++) { printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); } printf("\n"); return 0; } sqlite3 *db; int rc; void create_table(void) { char *zErrMsg = 0; char *sql; /* Open database */ rc = sqlite3_open("/mnt/ramdisk/test.db", &db); if( rc ) { printf("Can't open database: %s\n", sqlite3_errmsg(db)); return(0); } else { printf("Opened database successfully\n"); } /* Create SQL statement */ sql = "CREATE TABLE COMPANY(" \ "ID INT PRIMARY KEY NOT NULL," \ "NAME TEXT NOT NULL," \ "AGE INT NOT NULL," \ "ADDRESS CHAR(50)," \ "SALARY REAL );"; /* Execute SQL statement */ rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ printf("SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } else { printf("Table created successfully\n"); } } void insert_table(void) { char *zErrMsg = 0; char *sql; /* Create SQL statement */ sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (1, 'Paul', 32, 'California', 20000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (3, 'Teddy', 23, 'Norway', 20000.00 );" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );"; /* Execute SQL statement */ rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ printf("SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); } else { printf("Records created successfully\n"); } } int main(int argc, char *argv[]) { create_table(); insert_table(); while (1) { usleep(1000000); } return 0; }
_______________________________________________ users mailing list users@rtems.org http://lists.rtems.org/mailman/listinfo/users