First, download the relevant compression package to the official website
Https://www.sqlite.org/download.html
But to recompile one yourself, Bo master himself collected a bit, password: hixo
Https://pan.baidu.com/s/1Zdp0UMl2Mr4J2JUe28G7JQ
Put the package in the folder you want to put it in, which is the case
Then run cmd under this path, you can enter CMD directly in the Address bar and return
then enter the command
Sqlite3 databasename.db
If the database with the DatabaseName name exists under that path, the database is entered and if it does not exist, the database is created
It can then be used normally, such as using . Table to view all tables, . Exit can exit (it seems that the database command, not the SQL statement of SQLite is preceded by plus.)
This database allows Navicat connections, (Point connection, select Database location)
Then connect with C + +
Current sample database structure
table|user|user|2| CREATE TABLE "User" ("id" INTEGER not NULL, "account" text (+), " userName" text (+), " password" text (+), "Address" text (+), "IDNumber" text (+), "Opendate_year" INTEGER, "Opendate_month" Integer, "opendate_day" Integer, "islost" Integer, "lostdate_year" Integer, "Lostdate_month" Integer, "lostdate_day" Integer, "salt" text,primary KEY ("id" ASC))
Basic Read
BOOL Read () {
sqlite3_stmt* stmt; stored classes for compiled SQL statements and operations
SQLITE3 * CONN; Used to save the connection to the Sqlite3
if (Sqlite3_open ("d:\\c++ study\\nicobank\\niconicobank\\niconicobank\\database\\bank.db", &conn)! = SQLITE_OK) {
return false;
}//Open connection, parameters for database and Sqlite3 class
SQLITE3_PREPARE_V2 (conn, "select * from user where account = \" Test\ ";",-1, &stmt, 0);
Precompiled SQL statement, parameter is, Sqlite3 class connection (opened), SQL statement, may be data length, fill-1 will calculate itself, Sqlite3_stmt class, the last I do not know what
int result = Sqlite3_step (stmt);
while (Sqlite3_step (stmt) = = Sqlite_row) {//performs related execution steps, each call can fetch a row of values, so it can be called multiple times
int id = sqlite3_column_int (stmt, 0);
cout << ID << endl; Gets the value of the specified column when the row
}
}
Basic Write
BOOL Write () {sqlite3 * CONN;IF (Sqlite3_open ("D:\\c++ study\\nicobank\\niconicobank\\niconicobank\\database\\ Bank.db ", &conn)! = SQLITE_OK) {return false;} sqlite3_stmt * stmt = null;string sql = "INSERT into user (account, userName, password, address, IDNumber, Opendate_year,o Pendate_month, Opendate_day, Islost, Lostdate_year, Lostdate_month, Lostdate_day) VALUES (?,?,?,?,?,?,?,?,?,?,?,?); /(ID, account, username, password, address, idnumber, Opendate_year,opendate_month, Opendate_day, Islost, lostdate_year , Lostdate_month, Lostdate_day) SQLITE3_PREPARE_V2 (conn, Sql.c_str (),-1, &stmt, 0);//The above content is explained with read ()//need attention? As a placeholder, you can bind the related value by a set of functions of type Sqlite3_bind_, while the question mark position is a string a = "test", which is calculated starting from 1, string tempstr[5];for (int i = 0; i < 5; i++) tempst R[i] = "str"; int tempint[7];for (int i = 0; i < 7; i++) Tempint[i] = 1;//Simple initialization Some values are used to transmit values for (int i = 1; I <= 5; i++) { Sqlite3_bind_text (stmt, I, Tempstr[i-1].c_str (),-1, NULL);//Binding 1th to 5th question marks//parameters are stmt class, question mark position, passed in value, string length, 1 The function computes itself, I don't know what it is, but I can fill in Nu.LL's Place}for (int i = 6; I <=; i++) {Sqlite3_bind_int (stmt, I, tempint[i-6]);//bound integer, stmt class, question mark position, incoming value}int result = Sqlite3 _step (stmt); Execute command sqlite3_finalize (stmt);//close connection to avoid return false;}
Using C + + control Sqlite3