--- On Thu, 2/10/11, Pavel Ivanov <paiva...@gmail.com> wrote:
> From: Pavel Ivanov <paiva...@gmail.com> > Subject: Re: [sqlite] SIGSEGV Error when using sqlite3_exec( ) > To: "General Discussion of SQLite Database" <sqlite-users@sqlite.org> > Cc: "Zaryab Munir (zmunir)" <zmu...@cisco.com> > Date: Thursday, February 10, 2011, 12:28 PM > > [zm]: Based on the > documentation, applications can have multiple connections to > a file database by calling sqlite3_open() repeatedly. Is > there a way to have multiple connections to the ":memory:" > database. > > No. In-memory databases are special, see > http://www.sqlite.org/inmemorydb.html. > If you want several connections to the same database that > will be > completely in-memory you should consider placing your > database file > into /dev/shm. > > > [zm]: I did not change sqlite3 sources. > libaimdb.so is a library that I have compiled. This > includes my (application) code and links with > libsqlite3.so. > > Did you compile the whole glibc into your application > statically? Or > do you have some other completely unrelated function called > read()? If > the latter then you screwed up your application. Rename > your function > and I guess everything will work fine. [zm]: No there is no other function read() and I did compile glibc. I want to check if it is static or dynamic. Is static linking a requirement ? Thanks. > > > Pavel > > On Thu, Feb 10, 2011 at 2:22 PM, Zaryab M. Munir <zaryabmu...@yahoo.com> > wrote: > > Thanks, my reply inline: > > Sincerely, > > Zaryab > > > > > > --- On Thu, 2/10/11, Pavel Ivanov <paiva...@gmail.com> > wrote: > > > >> From: Pavel Ivanov <paiva...@gmail.com> > >> Subject: Re: [sqlite] SIGSEGV Error when using > sqlite3_exec( ) > >> To: "General Discussion of SQLite Database" <sqlite-users@sqlite.org> > >> Cc: "Zaryab Munir (zmunir)" <zmu...@cisco.com> > >> Date: Thursday, February 10, 2011, 5:11 AM > >> 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. > > [zm]: Based on the documentation, applications can > have multiple connections to a file database by calling > sqlite3_open() repeatedly. Is there a way to have multiple > connections to the ":memory:" database. > >> > >> > 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. > > [zm]: I did not change sqlite3 sources. > libaimdb.so is a library that I have compiled. This > includes my (application) code and links with > libsqlite3.so. > >> > >> > >> 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 > >> > > _______________________________________________ > > 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 > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users