In a computer system, there are generally two ways to save data:
1. common file Mode
2. Database mode
Using a database to manage large volumes of data is more efficient and more secure than normal file methods.
The database system is generally composed of 3 parts
1. Database
2. Database management System
3. Database Access applications
In the database, the data is stored as a table . There may be an association between the table and the table
SQL (Structured Query language) is a special programming language used to access the data in a database .
1. Create a table
CREATE TABLE TabName (col1 type1 [NOT NULL] [primary key],col2 type2 [Notnull],..)
2. Inserting data into the table
Insert INTO table1 (field1,field2) VALUES (value1,value2)
3. Querying the required data from the table
SELECT * FROM table1 where field1 like '%value1% '
4. Delete data from a table
Delete from table1 where range
SQLite database access application
#include <stdio.h>#include<sqlite3.h>Static intCallbackvoid*notused,intargcChar**ARGV,Char**azcolname) { inti; for(i=0; i<argc; i++) {printf ("%s =%s\n", Azcolname[i], argv[i]? Argv[i]:"NULL"); } printf ("\ n"); return 0;} intMainintargcChar**argv) {Sqlite3*DB; Char*zerrmsg =0; intRC; if(argc!=3) {fprintf (stderr,"Usage:%s DATABASE sql-statement\n", argv[0]); } /*Open Database*/RC= Sqlite3_open (argv[1], &db); if(RC) {fprintf (stderr,"Can ' t Open database:%s\n", sqlite3_errmsg (db)); Sqlite3_close (DB); } /*Execute SQL Language*/RC= Sqlite3_exec (db, argv[2], Callback,0, &zerrmsg); if(rc!=SQLITE_OK) {fprintf (stderr,"SQL Error:%s\n", zerrmsg); } /*Close the database*/sqlite3_close (DB); return 0; }
SQLite Embedded Database Explained