SQLite Tutorial (10): Memory Database and Staging database _sqlite

Source: Internet
Author: User
Tags sqlite sqlite tutorial


1, 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:


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:
Copy Code code as follows:

ATTACH DATABASE ': Memory: ' as aux1;


2. 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:


 code as follows:

rc = Sqlite3_open ("", &db);

Or
Copy Code ATABASE ' as aux2; 

and the memory database is very similar to the two database connections to create a temporary database is also separate, after the connection is closed, the temporary database will automatically disappear, and its underlying files will also be 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. As a result, some of the data in the staging database is written to a disk file, and the memory database always keeps 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.