Zaryab, There's no need to repeat your email several times.
> Question1: Can I have multiple connections opened for each thread to > the same in-memory dbase. No. Each connection to ":memory:" creates unique in-memory database which will be deleted when that connection is closed. > Question2: Why is sqlite3_exec( ) giving Segmentation Fault error: Did you change you SQLite sources? I can't find any information on what libaimdb.so is and why it is used in your environment. Pavel On Wed, Feb 9, 2011 at 8:07 PM, Zaryab Munir (zmunir) <zmu...@cisco.com> wrote: > Hi, > > I am using an in-memory dbase in a multi-threaded application and have > the following two questions: > I create dbase connections by each thread using the API: > { > Sqlite3 *db =3D NULL; > Sqlite3_open(":memory:", &db); > When I try to use sqlite3_exec( ) I get segmentation faults. > } > Question1: Can I have multiple connections opened for each thread > to > the same in-memory dbase. According to the documentation, the > sqlite3_open( ) API can be used multiple times to open multiple > connections to the same database, but its not clear is same applies > to > in-memory databases too. > Question2: Why is sqlite3_exec( ) giving Segmentation Fault error: > segfault at 00002b90153ac905 rip 00002b90153ac905 rsp > 00007fff95b1d938 > error 15 > Segmentation fault > > > Below is my code: > uint32 aim_sql_open (char *ptr, sqlite3 **db) > { > > int n; > n =3D sqlite3_open(ptr,db); > > if( n !=3D SQLITE_OK ) > { > /* zz get the wt_id */ > printf("Error opening database for thread =3D %d.\n",n); > return (0); > } > else { > /* zz get the wt_id */ > printf("Database open for thread =3D %d ok.\n",n); > } > } > NOTE: sqlite3_open( ) returns SQLITE_OK and the value of db is > updated. > > uint32 aim_db_init( ) { > char dbname[10]; > char tbname[13]; > char statement[760], *db_err; > sqlite3 *db =3D NULL; > int n; > bzero(dbname,10); > bzero(tbname,13); > bzero(statement,760); > memcpy(dbname,DB_NAME,9); > /* no need for dbname for inmemory dbase */ > n =3D aim_sql_open(":memory:", &db); > memcpy(tbname,AIM_TABLE_NAME,12); > if(!strcmp(tbname,"")) > return(FALSE); > sprintf(statement, "CREATE TABLE %s (%s INTEGER PRIMARY KEY,%s > DATE,%s INTEGER,%s INTEGER,%s INTEGER,%s TEXT,%s TEXT,%s TEXT,%s > INTEGER,%s INTEGER,%s INTEGER,%s INTEGER,%s DATE,%s INTEGER,%s > DATE,%s > INTEGER,%s DATE,%s INTEGER,%s DATE,%s INTEGER,%s INTEGER,%s DATE);", > > tbname,COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9,COL10,COL11,COL12,CO > L13,COL14,COL15,COL16,COL17,COL18,COL19,COL20,COL21,COL22); > n =3D sqlite3_exec(db, statement, NULL, 0, &db_err); > if( n !=3D SQLITE_OK ) > { > printf("Error executing: %s\n",db_err); > sqlite3_free(db_err); > return (FALSE); > } > =20 > > The backtrace from GDB is as follows: > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 0x2b7070afe1a0 (LWP 699)] > 0x00002b706fcc6905 in read () from /usr/lib64/libaimdb.so > (gdb) bt > #0 0x00002b706fcc6905 in read () from /usr/lib64/libaimdb.so > #1 0x00002b70703a4120 in unixRandomness (NotUsed=3D<value optimized > = > out>, > nBuf=3D<value optimized out>, zBuf=3D0x7fff3b203050 "") at > ../sqlite3.c:27932 > #2 0x00002b707035b0f5 in sqlite3_randomness (N=3D4, pBuf=3D<value = > optimized > out>) > at ../sqlite3.c:13876 > #3 0x00002b707035b28f in writeJournalHdr (pPager=3D0x62b788) > at ../sqlite3.c:36096 > #4 0x00002b707035b4fb in pager_write (pPg=3D0x639e08) at > ../sqlite3.c:39815 > #5 0x00002b7070366195 in sqlite3PagerWrite (pDbPage=3D0x7) at > ../sqlite3.c:40151 > #6 0x00002b7070368466 in newDatabase (pBt=3D0x62b6d8) at > ../sqlite3.c:47668 > #7 0x00002b707037a18c in sqlite3BtreeBeginTrans (p=3D0x62b678, = > wrflag=3D1) > at ../sqlite3.c:47798 > #8 0x00002b707037fa78 in sqlite3Step (p=3D0x63a988) at = > ../sqlite3.c:63062 > #9 0x00002b7070383803 in sqlite3_step (pStmt=3D<value optimized > out>) > at ../sqlite3.c:58768 > #10 0x00002b7070386592 in sqlite3_exec (db=3D0x62b078, > zSql=3D0x7fff3b203b10 "CREATE TABLE aim_db_table (hash4ADandDC = > INTEGER > PRIMARY KEY,entrytime DATE,state INTEGER,bwgain INTEGER,cctimestamp > INTEGER,foreignkeyAD TEXT,popclass TEXT,deviceclass TEXT,vdoBitrate > INTEGER,qualityI"..., > xCallback=3D0, pArg=3D0x0, pzErrMsg=3D0x7fff3b203e38) at > ../sqlite3.c:84165 > #11 0x00002b706fac52ac in aim_db_init () at aim_db_main.c:645 > #12 0x000000000040566d in main () > > > Regards, > Zaryab > > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users