C ++ simple example of calling SQLite

Source: Internet
Author: User

Go to the official website of SQLite, download source code. http://www.sqlite.org/

After compilation (my Microsoft vs), generate two files: sqlite3.lib and sqlite3.dll.

Create a Win32 project in vs. Copy the sqlite3.h, sqlite3.lib, and sqlite3.dll files to the project directory and delete all the automatically generated code.

 

Add a CPP file in the project, arwensqlite. cpp, and input the following code:

 

# Include <string. h>

# Include "sqlite3.h"

# Pragma comment (Lib, ". \ sqlite3.lib ")

 

Int main (INT argc, char
* Argv [])

{

Sqlite3 * dB;

Int ret;

Char * errmsg = NULL;

Ret = sqlite3_open ("D: \ Temp. DB", & dB); // open the database tmep. DB. If it does not exist, create the file temp. DB.

 

// Create a table and insert data

Ret = sqlite3_exec (dB, "create table arwentable (name nvarchar (20), age integer)", null, null, & errmsg );

Ret = sqlite3_exec (dB, "insert into arwentable values ('weiwenhp ', 25)", null, null, & errmsg );

 

 

Sqlite3_close (db); // close the database

Return 0;

 

}

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.