Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:25:37+00:00 2026-06-02T23:25:37+00:00

I have created an in memory database using the statement: rc = sqlite3_open(:memory:, &db);

  • 0

I have created an in memory database using the statement:

rc = sqlite3_open(":memory:", &db);

I need to access this database in other thread (for reading data).
Is there any way to access this in memory database in other thread?

The documentation says:

Every :memory: database is distinct from every other. So, opening two
database connections each with the filename :memory: will create two
independent in-memory databases.

If I create multiple in memory database, how can I access these databases from other thread?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:25:39+00:00Added an answer on June 2, 2026 at 11:25 pm

    The db variable in your code becomes the pointer to the SQLite db object created:

    int sqlite3_open(
      const char *filename,   /* Database filename (UTF-8) */
      sqlite3 **ppDb          /* OUT: SQLite db handle */
    );
    

    Ref.: http://www.sqlite.org/capi3ref.html#sqlite3_open

    This is the pointer you will use in your different threads to execute statements. For example, you prepare statements with the following function to which you’ll pass your db pointer:

    int sqlite3_prepare(
      sqlite3 *db,            /* Database handle */
      const char *zSql,       /* SQL statement, UTF-8 encoded */
      int nByte,              /* Maximum length of zSql in bytes. */
      sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
      const char **pzTail     /* OUT: Pointer to unused portion of zSql */
    );
    

    Ref.: http://www.sqlite.org/c3ref/prepare.html

    EDIT:

    I don’t know if you can change the name of the memory database that you open with sqlite3_open(":memory:", ...), but it does have a name. Also you can attach additional in-memory databases.

    There is a good chance that the initially opened in-memory database name is main. You can verify that by running the statement pragma database_list.

    You can attach more in-memory database by running statements such as ATTACH DATABASE ':memory:' AS db2;.

    Here is a quick demo of the above using the sqlite3 client:

    [someone@somewhere ~]$ sqlite3
    SQLite version 3.7.7.1 2011-06-28 17:39:05
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> .headers on
    sqlite> pragma database_list;
    seq|name|file
    0|main|
    sqlite> attach database ':memory:' AS db2;
    sqlite> pragma database_list;
    seq|name|file
    0|main|
    2|db2|
    sqlite> create table main.foo (bar int);
    sqlite> create table db2.foo (bar int);
    sqlite> insert into main.foo values (5);
    sqlite> insert into db2.foo select * from main.foo;
    sqlite> select * from db2.foo;
    bar
    5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an sqlite database in my app. I have this dbhelper class in
Im using Moq to create mocks of a data set. I have created a
I have a program that starts up and creates an in-memory data model and
I have created the following C library for reading an image: typedef struct {
I have created a basic site using ASP.NET routing according to Mike Ormond's example
I have created one table using the below command: create table Table1( Id int
I have created an MS Access 2003 application, set up as a split front-end/back-end
I have an existing SQL Server database, where I store data from large specific
I have to create such a mechanism: Create in-memory (H2DB) database; Create tables and
I would like to create an in-memory database for testing purposes using Derby/JavaDB. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.