SQLite Memory Database Learning manual _sqlite

Source: Internet
Author: User
Tags sqlite

One, Memory database:

In SQLite, a database is usually stored in a disk file. In some cases, however, we can make the database always reside in memory. One of the most common ways is when calling Sqlite3_open (), the database filename parameter passes ": Memory:" such as:

Copy Code code as follows:

rc = Sqlite3_open (": Memory:", &db);

After you call the above function, no disk files are generated, and instead, a new database is created successfully in pure memory. Because there is no persistence, the database disappears immediately after the current database connection is closed. It should be noted that although multiple database connections can create memory databases through the above methods, they are different databases and have no relationship to each other. In fact, we can also attach the memory database, like other normal databases, to the current connection through the attach command, such as:

ATTACH DATABASE ': Memory: ' as aux1;

Ii. Provisional database:

    When you invoke the Sqlite3_open () function or execute the attach command, if the database file parameter passes an empty string, a new temporary file is created as the underlying file for the staging database, such as:
     rc = Sqlite3_open ("", &db);
    or
    ATTACH DATABASE ' as aux2;
    and memory databases are very similar, and the temporary databases created by two database connections are separate, and the staging database automatically disappears after the connection is closed, and the underlying files are automatically deleted.
    Although disk files are created to store data information in the staging database, the staging database usually resides in memory as well as the memory database, except that when the amount of data in the staging database is too large, SQLite to ensure that more memory is available for other operations, some of the data in the staging database is written to a disk file, while the memory database always stores the data in memory.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.