SQLite tutorial (10): Memory Database and temporary database, sqlite tutorial

Source: Internet
Author: User
Tags sqlite tutorial

SQLite tutorial (10): Memory Database and temporary database, sqlite tutorial

I. Memory Database:

In SQLite, databases are usually stored in disk files. However, in some cases, we can keep the database in the memory. The most common method is to pass ": memory:" To the database file name parameter when calling sqlite3_open (), for example:
 Copy codeThe Code is as follows:
Rc = sqlite3_open (": memory:", & db );
 
After the above functions are called, no disk files are generated. Instead, a new database is successfully created in pure memory. Because the database is not persistent, the database disappears immediately after the current database connection is closed. Note that although multiple database connections can be used to create memory databases, they are different databases and have no relationship with each other. In fact, we can also use the Attach command to Attach a memory database to the current connection like other common databases, such:
 Copy codeThe Code is as follows:
Attach database ': memory:' AS aux1;
 

Ii. Temporary database:

When you call the sqlite3_open () function or execute the ATTACH command, if the database file parameter is a Null String, a new temporary file will be created as the underlying file of the temporary database, such:
 Copy codeThe Code is as follows:
Rc = sqlite3_open ("", & db );
 
Or
 Copy codeThe Code is as follows:
Attach database ''AS aux2;
 
Similar to a memory database, the temporary databases created by the two databases are also independent. When the connection is closed, the temporary database will automatically disappear and the underlying files will also be deleted.
Although the disk file is created to store data information in the temporary database, the temporary database will usually reside in the memory like the memory database. The only difference is that, when the data volume in the temporary database is too large, SQLite writes some data in the temporary database to the disk file to ensure that more memory is available for other operations, memory databases always store data in the 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.