Quantcast

sqlite3_open_v2("",... schema name?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

sqlite3_open_v2("",... schema name?

Olivier Mascia
Dear,

http://sqlite.org/c3ref/open.html says:

"If the filename is an empty string, then a private, temporary on-disk database will be created. This private database will be automatically deleted as soon as the database connection is closed."

On such a successfully opened database, sqlite3_db_filename(db, "main") returns a NOT null pointer (to '\0').
The same behavior is seen when the opened database is an in-memory one (using ":memory:" in the sqlite3_open_v2 call).

Yet http://sqlite.org/c3ref/db_filename.html says:

"If there is no attached database N on the database connection D, or if database N is a temporary or in-memory database, then a NULL pointer is returned."

So I would have expected (from the documentation) to get a NULL pointer, at least for the :memory: database. And for the on-disk but private temporary one, the documentation is mute about what to except from sqlite3_db_filename().

Could it be that schema name to pass to sqlite3_db_filename() would not be "main" in case of a ":memory:" database or "" temporary database ?

--
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia, http://integral.software


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sqlite3_open_v2("",... schema name?

Cezary H. Noweta
Hello,

On 2017-04-28 12:16, Olivier Mascia wrote:
> http://sqlite.org/c3ref/open.html says:

> "If the filename is an empty string, then a private, temporary on-disk database will be created. This private database will be automatically deleted as soon as the database connection is closed."

The same behavior is when filename is NULL. In both cases a pager's
filename is set to an empty string.

> On such a successfully opened database, sqlite3_db_filename(db, "main") returns a NOT null pointer (to '\0').
> The same behavior is seen when the opened database is an in-memory one (using ":memory:" in the sqlite3_open_v2 call).

Indeed, look at the code (``sqlite3PagerFilename''):

return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename;

> Yet http://sqlite.org/c3ref/db_filename.html says:

> "If there is no attached database N on the database connection D, or if database N is a temporary or in-memory database, then a NULL pointer is returned."

Actually, NULL means that there is no such schema (if provided N is
NULL, then "main"'s filename is returned). An empty string (ptr to '\0')
means that the schema is an on-disk temp, or an in-mem db, or ``temp''
schema.

> So I would have expected (from the documentation) to get a NULL pointer, at least for the :memory: database. And for the on-disk but private temporary one, the documentation is mute about what to except from sqlite3_db_filename().

I agree, that a minor DOC improvement would be nice in this case.

-- best regards

Cezary H. Noweta
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...