On Thu, 24 Nov 2011 12:30:27 -0500, Pavel Ivanov <paiva...@gmail.com> wrote:
>>> P.S: I know that one can simply do a CREATE TABLE IF NOT EXISTS... but I >>> still need to know if a table exists or not. >> >> You can easily try this with the sqlite3 command line tool by omitting >> the database file name argument on the command line. >> Create a table, insert a row, check sqlite_master. > > When you omit database name on the command line you create a temporary > on-disk database, just the same way as you provide an empty database > name to sqlite3_open. I doubt it. I'm not poficient in C, but as far as I can tell the filename ":memory:" is supplied by the command line tool itself (when SQLITE_OMIT_MEMORYDB is not used). $ sqlite3 SQLite version 3.7.9 2011-11-01 00:52:41 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> pragma compile_options; ENABLE_FTS3 ENABLE_RTREE TEMP_STORE=1 THREADSAFE=1 sqlite> http://www.sqlite.org/compile.html#omit_memorydb (sources from autoconf_3070900) -------------------- shell.c line 2787 -------------------- if( i<argc ){ #if defined(SQLITE_OS_OS2) && SQLITE_OS_OS2 data.zDbFilename = (const char *)convertCpPathToUtf8( argv[i++] ); #else data.zDbFilename = argv[i++]; #endif }else{ #ifndef SQLITE_OMIT_MEMORYDB data.zDbFilename = ":memory:"; #else data.zDbFilename = 0; #endif } if( i<argc ){ zFirstCmd = argv[i++]; } if( i<argc ){ fprintf(stderr,"%s: Error: too many options: \"%s\"\n", Argv0, argv[i]); fprintf(stderr,"Use -help for a list of options.\n"); return 1; } data.out = stdout; #ifdef SQLITE_OMIT_MEMORYDB if( data.zDbFilename==0 ){ fprintf(stderr,"%s: Error: no database filename specified\n", Argv0); return 1; } #endif -------------------- ... and ... -------------------- sqlite.c line 49794 -------------------- /* True if opening an ephemeral, temporary database */ const int isTempDb = zFilename==0 || zFilename[0]==0; /* Set the variable isMemdb to true for an in-memory database, or ** false for a file-based database. */ #ifdef SQLITE_OMIT_MEMORYDB const int isMemdb = 0; #else const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0) || (isTempDb && sqlite3TempInMemory(db)); #endif -------------------- > To test in-memory database from sqlite3 command > line tool you should use ":memory:" as a database name on the command > line, just the same way as you do in sqlite3_open. That works, too. > >Pavel > > >On Thu, Nov 24, 2011 at 9:25 AM, Kees Nuyt <k.n...@zonnet.nl> wrote: >> On Thu, 24 Nov 2011 08:45:12 -0500, Dilip Ranganathan >> <misc.us...@gmail.com> wrote: >> >>> Currently I use sqlite to create a bunch of on-disk tables to store my >>> data. I use Sqlite's master table to determine if a table already exists >>> based on which I take certain decisions. >>> >>> Suppose I switch these to in-memory tables (:memory:), how do I go about >>> checking if a table exists? Do in-memory tables still get an entry in the >>> master table? >> >> Yes. >> >>> If not, how else should I go about with this? >> >> when you connect to the in-memory database you can be sure none of the >> tables exist because an in memory database is not persistent. >> >>> thanks! >>> >>> P.S: I know that one can simply do a CREATE TABLE IF NOT EXISTS... but I >>> still need to know if a table exists or not. >> >> You can easily try this with the sqlite3 command line tool by omitting >> the database file name argument on the command line. >> Create a table, insert a row, check sqlite_master. >> >> -- >> Regards, >> >> Kees Nuyt -- Regards, Kees Nuyt _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users