Skip to main content

Posts

Showing posts with the label sqlite

Sqlite database is locked

sqlite는 embedded system에서 널리 사용되는 무료 dbms?(dbms라고 말하긴 좀 그렇지만, dbms라 불러주자 ㅎ) 이다. 특히 memory db 기능이 아주 유용하다. 그 밖의 dbms에서도 이 기능이 있으나, 이 기능이 지원되는 버전은 대부분 고가이다. 따라서, 무료인 sqlite를 많이들 애용하는 것 같다. 멀티쓰레드를 sqlite DB를 구현하고 롱런테스트를 하다보면, pthread_mutex_lock으로 쓰레드 간의 교착상태를 막아줘도, sqlite lock 에러가 간헐적으로 발생할 것이다. 이에 대해 본인은 다음과 같은 에러 처리 구문을 준비하여 사용하고 있다. sqlite Error가 발생하면, sqlite3_exception함수를 호출한다. 이 함수에서 sqlite error code를 구분하여, 만약, busy 또는 locked이면 최대 2초간 sleep 상태로 만드는 sqlite3_busy_timeout, busy handler를 호출한다. 그 다음, goto 구문으로 재차 sqlite3_exec를 실행한다. 단, sqlite3_exec는 transaction의 begin과 commit 또는 rollback 구문 사이에서 실행한다. 대부분 lock 에러가 발생하더라도 1~2번 실패 후에, 처리된다는 것이 본인의 테스트 결과이다. 단, journal를 WAL로 변경하였음. 기존 journal은 멀티쓰레드 지향적이지 않다는 점을 잊지마시길.... Error Code SQLITE_LOCKED (6): Database Is Locked This error code occurs when you try to do two incompatible things with a database at the same time from the same database connection. For example, if you are in the middle of a SELECT statement and y...

Sqlite - Opening A new Database connection

- 3개의 패턴이 있다. 나는 주로 sqlite3_open_v2를 애용하고 있다. int sqlite3_open( const char *filename, /* Database filename (UTF-8) */ sqlite3 **ppDb /* OUT: SQLite db handle */ ); int sqlite3_open16( const void *filename, /* Database filename (UTF-16) */ sqlite3 **ppDb /* OUT: SQLite db handle */ ); int sqlite3_open_v2( const char *filename, /* Database filename (UTF-8) */ sqlite3 **ppDb, /* OUT: SQLite db handle */ int flags, /* Flags */ const char *zVfs /* Name of VFS module to use */ ); sqlite3_open_v2의 flags인수로 사용가능한 것은 SQLITE_OPEN_NOMUTEX - mutexes(Mutual Exclusion Object ) on the opened database connection are disabled and the application must insure that access to the database connection and its associated prepared statement is serialized. - 뮤텍스를 보장하지 않는다. SQLITE_OPEN_FULLMUTEX SQLITE_OPEN_SHAREDCACHE SQLITE_OPEN_PRIVATECACHE SQLITE_OPEN_READONLY - the database is opened in read-only mode. If the database does...

SQLITE Result Codes

#define SQLITE_OK 0 /* Successful result */ /* beginning-of-error-codes */ #define SQLITE_ERROR 1 /* SQL error or missing database */ #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ #define SQLITE_PERM 3 /* Access permission denied */ #define SQLITE_ABORT 4 /* Callback routine requested an abort */ #define SQLITE_BUSY 5 /* The database file is locked */ #define SQLITE_LOCKED 6 /* A table in the database is locked */ #define SQLITE_NOMEM 7 /* A malloc() failed */ #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */ #define SQLITE_FULL 13 /* Insertion failed because data...
linux에서 sqlite * sqlite site http://sqlite.org http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers       1.http://www.ch-werner.de/javasqlite/   (jdbc site: 여기서부터 시작) 2. 테스트 전 PC에 Sqlite,JDK,gcc 가 설치 되어있어야함   - SQLite 2.4.12 or higher   # wget http://www.hwaci.com/sw/sqlite/sqlite-2.8.9.tar.gz   # mv sqlite-2.8.9.tar.gz /usr/src   # tar -xvzf sqlite-2.8.9.tar.gz   # cd sqlite   # ./configure   # make   # make install   - JDK 1.1 or higher ( http://www.blackdown.org/java-linux/java-linux-d2.html 에 서 다운)   - C compiler and make 3.Sqlite을 설치하고 제대로 동작하는지 간단한 TEST #sqlite DB sqlite>create table TEST(a int,b char[10]); sqlite>insert into TEST values(10,'aa'); sqlite>insert into TEST values(20,'bb'); sqlite>select * from TEST 4.http://www.ch-werner.de/javasqlite/javasqlite-20040424.tar.gz  (jdbc 설치) #./configure #make #make install 5.cd /r...