Sqlite3 programming only need a header file with a library file, install see sqlite3 on Linux system installation
/* filename:insert.c */#include <stdio.h> #include <sqlite3.h>int main () {sqlite3 *db; Sqlite3_open ("Stu.db", &db); Char *sql = "INSERT into student values (' James ', 99)"; SQLITE3_EXEC (DB, SQL, NULL, NULL, NULL); Sqlite3_close (DB); return 0;}
As above code, the simplest operation, only need a structure "SQLite *db",
Three functions, "Sqlite3_open ()" "Sqlite_exec ()" "Sqlite_close ()".
Compile just add a library link
$ gcc Insert.c-o insert-lsqlite3
Sqlite3 is a small database, command, interface is very simple, manual can go to the official website www.sqlite.org view, also can download, offline view.
Getting Started basic functions: documentation, SQLITE programming Interfaces, Introduction to the C + + API
Reference manual: Documentation, SQlite programming Interfaces-C + + API Reference
Database structure Body:
typedef struct SQLITE3 Sqlite3;sqlite3 *db;
There is no need to say much about this struct, as long as the reputation of a pointer can be, how the operation is encapsulated in the library function.
Switches for the database:
int Sqlite3_open (const char *filename, sqlite3 **ppdb); int sqlite3_close (sqlite3*);
"Sqlite3_open ()" has two parameters, the first is the file name of the database, and the second is the address of the previous named pointer.
if (Sqlite3_open ("stu.db", &db)) {puts (sqlite_errmsg (db)); Exit (1);}
The usual way, as above, is to keep the function in the Sqlite3
Not finished, to be continued ...
Sqlite3 C language Programming