Sqlite3 C language Programming

Source: Internet
Author: User
Tags sqlite

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

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.