SQLite Memory Database (from: http://www.cr173.com/html/6965_1.html)

Source: Internet
Author: User

SQLite Introduction
I. SQLite is an embedded database that implements a large subset of SQL 92 standards. it combines database engines and interfaces in a database, and is famous for storing all data in a single file. I think SQLite functions are between MySQL and PostgreSQL to some extent. in terms of performance, SQLite is usually 2-3 times faster (or even more ). this benefits the highly-adjusted internal architecture because it removes the communication between the server and the client and the server.

II. the impressive feature is that you can place your entire database system in it. with very efficient Memory organization, SQLite only needs to maintain a small size in a small memory, far smaller than any other database system. these features make it a very convenient tool in tasks that require efficient database application.

Advantages of SQLite
I. in addition to speed and efficiency, SQLite has many other advantages that make it an ideal solution for many tasks. because SQLite databases are simple files, it is not necessary for a management team to take the time to construct a complex permission structure to protect users' databases. because the permission is automatically implemented through the file system. this also means that (the size of the database space is only related to the environment and has nothing to do with itself) there are no special rules to understand the user's disk space. users can benefit from creating any number of databases they want and their absolute control over these databases.

II. the fact that a database is a file can be easily moved between servers using SQLite. SQLite also removes the waiting process that requires a large amount of memory and other system resources. this is true even when the database is used in a large amount.

Create a memory database

1. Due to business needs, I use the SQLite memory database to create a cache, and all data in the IIS Memory Database is lost. I wonder if SQLite can be used for distributed memory data management.

2. Add system. Data. sqlclient reference, assembly please Here http://sqlite.phxsoftware.com/download

3. create a memory database, data source =: Memory:; version = 3; this connection string has been tossing for a long time. Of course, you can also use files to store data here. You only need to modify data source =: memory: Data Source = cache. DB is OK! Of course, this table needs to be created in global.

Code

Sqliteconnection conn = (sqliteconnection) New sqliteconnection ("Data Source =: Memory:; version = 3; cache size = 3000; new = true; pooling = false; Max pool size = 100; longnames = 0; timeout = 1000; notxn = 0; syncpragma = normal; stepapi = 0 "); Conn. open (); idbcommand dbcmd = Conn. createcommand (); // create a memory table string SQL = "CREATE TABLE [avtable] ([ID] integer primary key not null, [citypair] varchar (6) null, [flightno] varchar (50) null, [flightdate] varchar (10) null, [cachetime] varchar (2000) null, [avnote] varchar (2000) null) "; dbcmd. commandtext = SQL; dbcmd. connection = conn; dbcmd. executenonquery (); sqliteconn = conn;

 

Global attribute. After you open the database connection, create a table and assign this attribute to it. Later, use this connection for operation data.

public static SQLiteConnection SQLiteConn { get; set; }

Use SQL statements to operate the table as follows. SQL statements represent SQL statements.

string sql = "Update AVTable Set CityPair='" + av.CityPair + "',CacheTime='" + DateTime.Now.ToString() + "',AVNote='" + av.AVNote + "' Where FlightNo='" + av.FlightNo + "' And FlightDate='" + av.FlightDate + "'";IDbCommand dbcmd = MemoryDatabse.SQLiteConn.CreateCommand();dbcmd.CommandText = sql;dbcmd.Connection = MemoryDatabse.SQLiteConn;int count = dbcmd.ExecuteNonQuery(); 

The query syntax of SQLite is different from that of SQL Server.

Extract data from avcache Table 11-20.

Select * From avcache Limit 9 Offset 10;

The preceding statement retrieves data from the avcache table, skipping 10 rows and taking 9 rows.

Another method is to extract 9 pieces of data from 10.

select * from avcache limit10,9

Syntax

SQL = "select * From avcache where" + condition + "order by" + sorting + "Limit" + how many records to display + "offset" + how many records to skip;

Example

select * from avcache limit 15 offset 20

This means that 15 records are selected by skipping 20 records from the avcache table.

Since I have recently started to learn SQLite, it is inevitable that I write something rough. I hope you can correct it and provide a better way!

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.