in memory SQLite in C/C++

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

in memory SQLite in C/C++

Rajan, Vivek K
Hello-

 

As I understand it is possible to us in-memory SQLite database. Does
someone have example C/C++ code to demonstrate techniques for using
in-memory SQLite database?

 

Thanks in advance.

 

Rajan

 

Reply | Threaded
Open this post in threaded view
|

Re: in memory SQLite in C/C++

Igor Tandetnik
Rajan, Vivek K wrote:
> As I understand it is possible to us in-memory SQLite database. Does
> someone have example C/C++ code to demonstrate techniques for using
> in-memory SQLite database?

You use sqlite3_open to open a database with a special name ":memory:".
Then just use it as you would a regular file-based database.

Igor Tandetnik

Reply | Threaded
Open this post in threaded view
|

RE: Re: in memory SQLite in C/C++

Rajan, Vivek K
In reply to this post by Rajan, Vivek K
Thanks Igor.

One question: So at any given point in time, one can only have _ONE_
SQLite database in-memory?

Rajan


>-----Original Message-----
>From: Igor Tandetnik [mailto:[hidden email]]
>Sent: Thursday, October 20, 2005 1:57 PM
>To: SQLite
>Subject: [sqlite] Re: in memory SQLite in C/C++
>
>Rajan, Vivek K wrote:
>> As I understand it is possible to us in-memory SQLite database. Does
>> someone have example C/C++ code to demonstrate techniques for using
>> in-memory SQLite database?
>
>You use sqlite3_open to open a database with a special name ":memory:".
>Then just use it as you would a regular file-based database.
>
>Igor Tandetnik

Reply | Threaded
Open this post in threaded view
|

Re: Re: in memory SQLite in C/C++

Dennis Cote
Rajan, Vivek K wrote:

>Thanks Igor.
>
>One question: So at any given point in time, one can only have _ONE_
>SQLite database in-memory?
>
>  
>
Rajan,

No, you get a new independent in-memory database for each call to
sqlite3_open() with a filename of ":memory:" Each call returns a
separate sqlite3* database pointer.

Dennis Cote
Reply | Threaded
Open this post in threaded view
|

Re: Re: in memory SQLite in C/C++

Igor Tandetnik
In reply to this post by Rajan, Vivek K
Rajan, Vivek K wrote:
> One question: So at any given point in time, one can only have _ONE_
> SQLite database in-memory?

If I understand it correctly, every sqlite3_open(":memory:") call
creates a separate, independent in-memory database. So you can have many
such databases open at the same time, but you can't have two handles
open on the same in-memory database (the way you can on a file).

Igor Tandetnik

Reply | Threaded
Open this post in threaded view
|

RE: Re: Re: in memory SQLite in C/C++

Rajan, Vivek K
In reply to this post by Rajan, Vivek K
Thanks guys. One more question: When is the memory of the in-memory
database released? Is it when the close() function is called?

Are there any other memory clean-up which needs to be done?

Rajan


>-----Original Message-----
>From: Igor Tandetnik [mailto:[hidden email]]
>Sent: Thursday, October 20, 2005 3:22 PM
>To: SQLite
>Subject: [sqlite] Re: Re: in memory SQLite in C/C++
>
>Rajan, Vivek K wrote:
>> One question: So at any given point in time, one can only have _ONE_
>> SQLite database in-memory?
>
>If I understand it correctly, every sqlite3_open(":memory:") call
>creates a separate, independent in-memory database. So you can have
many
>such databases open at the same time, but you can't have two handles
>open on the same in-memory database (the way you can on a file).
>
>Igor Tandetnik