On Thu, Apr 21, 2016 at 8:20 PM, Dan Kennedy <danielk1977 at gmail.com> wrote:

>   Generally speaking, no matter how they are created, a given in-memory
>> database has one and only one connection.  You cannot, for example, use a
>> URI ?filename? with mode=memory to open the same in-memory database more
>> than once (I assume that?s what you mean by ?by name??).[...]
>>
>
Yes you can Jay, see Dan's answer.
And https://www.sqlite.org/sharedcache.html section 6.0:

Enabling shared-cache for an in-memory database allows two or more database
connections in the same process to have access to the same in-memory
database.
An in-memory database in shared cache is automatically deleted and memory
is reclaimed when the last connection to that database closes.


>> You can see that even though I?ve opened the same
>> ?file:data.db?mode=memory? database more than once, it is actually three
>> distinct databases.  I?m pretty sure that when mode=memory, the
>> path/filename are ignored.
>
>

> If you open the databases using "file:data.db?mode=memory&cache=shared"
> then db1, db2 and db3 will all refer to the same in-memory database. Which
> will fail, as you cannot attach the same db to a single handle more than
> once.




> But, if your process has two separate database handles and they both
> attach "file:data.db?mode=memory&cache=shared" then both handles will be
> connected to the same in-memory database.


This is exactly what we are doing. Now I keep on reading in this list
cache=shared is for constrained devices and one shouldn't use it ever.

But how else to use an in-memory database from multiple threads and
leverage table-level locking as opposed to DB-level locking?

We are heavy users of vtables and in-memory DBs, plural, within the same
process. And would like to have some //ism on tables.
I'd even wish for WAL-type MVCC for in-memory databases to avoid locks even
more. Is WAL mode supported for in-memory DBs?

What is "wrong" with shared cache that people keep saying don't use it?
Dan, Richard, is shared cache broken somehow?

Thanks, --DD

Reply via email to