Dear Jonathan, I tried to use "unix-dotfile" according to your comment.
I am successful for testing sqlite. I attached my testing code. Thank you very much. Best Regards, JunBeom -----Original Message----- From: Jonathan Brandmeyer <jbrandme...@planetiq.com> Sent: Saturday, March 30, 2019 3:50 AM To: JunBeom Kim <jb...@e-coretech.kr> Cc: users@rtems.org Subject: Re: Sqlite building failure using rtems-source-builder On Fri, Mar 29, 2019 at 12:57 AM JunBeom Kim <jb...@e-coretech.kr> wrote: > Because there is file locking problem due to fcntl(F_SETLK) unsupported > feature, DB file access is error. SQLite3 ships with a set of VFS methods that avoid file locking entirely, named "unix-none". There are several methods available to pick this style of locking. Since my application is being tested on both a general-purpose POSIX OS as well as RTEMS, I change the VFS type in my RTEMS startup code using sqlite3_vfs_find() and sqlite3_vfs_register(). There is also a "unix-dotfile" method available, and we may switch over to that for better error-handling paths. In the case of the "unix-none" locking mode, you must maintain the invariant that there is exactly one database connection per database file in the entire application. That seems OK to me, so we set the -DSQLITE_DEFAULT_LOCKING_MODE=1 (EXCLUSIVE) to help enforce it in the testing environment. > > 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. Regarding your memory leak, don't forget to sqlite3_close() the database. This must be done even if sqlite3_open() fails. HTH, -- 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; /* Change VFS for unix dotflie */ rc = sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1); if (rc) { printf("sqlite3_vfs_register: fail=%d\n", rc); } /* 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