Use of SQLite in VC

Source: Internet
Author: User
Tags sql error
I. SQLite introduction SQLite is an open source database written in C language. It is mainly used for Embedded purposes. You can also integrate it into your own desktop. Program Some people use access as the background database. SQLite supports most sql92 standards, such as indexes, restrictions, triggers, and views. Supports null, integer, real, text, and BLOB data types and transactions. 2. To download sqlitesqlite, you can go to the official site to download the compiled files in windows and Source code And help documentation. Iii. SQLite simple use 3.1 create database c: \ sqlite-3_6_11> sqlite3.exe dbname.dbsqlite3.exe followed by database file name 3.2 Create data table SQLite> Create Table users (userid varchar (20) primary Key,...> age int,...> birthday datetime); 3.3 Add record insert into users values ('wang', 20, '2017-5-4 '); insert into users values ('lil', 22, '2017-11-16 '); 1987 query record select * from users order by birthday; 3.4 Delete record Delete from users where userid = 'wang'; 3.5 Exit sqlitesqlite>. The data structure of the exitsqlite database is stored in the "sqlite_master" table. For example, you can enter "tables". Take vs 2008 as an example: Under the doscommand line: Path = D: \ Program Files \ Microsoft Visual Studio 9.0 \ Vc \ bin; % PATH = D: \ Program Files \ Microsoft Visual Studio 9.0 \ common7 \ ide; % PATH % lib/DEF: sqlite3.def/machine: ix86 v. Use # include "in VC ".. /sqlite3_lib/sqlite3.h "# pragma comment (Lib ,".. /sqlite3_lib/sqlite3.lib ") Static int _ SQL _callback (void * notused, int argc, char ** argv, char ** szcolname) {int I; for (I = 0; I <argc; I ++) {printf ("% s = % s \ n", szcolname [I], argv [I] = 0? "NUL": argv [I]);} return 0;} int main (INT argc, char * argv []) {const char * ssql1 = "create table users (userid varchar (20) primary key, age int, birthday datetime );"; const char * ssql2 = "insert into users values ('wang', 20, '2017-5-4 ');"; const char * ssql3 = "select * from users ;"; sqlite3 * DB = 0; char * perrmsg = 0; int ret = 0; // connect to the database ret = sqlite3_open (". /test. DB ", & dB); If (Ret! = Sqlite_ OK) {fprintf (stderr, "the database cannot be opened: % s", sqlite3_errmsg (db); Return (1);} printf ("the database connection is successful! \ N "); // Execute SQL sqlite3_exec (dB, ssql1, 0, 0, & perrmsg) for table creation; If (Ret! = Sqlite_ OK) {fprintf (stderr, "SQL error: % s \ n", perrmsg); sqlite3_free (perrmsg);} // execute the SQL sqlite3_exec (dB, ssql2, 0, 0, & perrmsg); // query the data table sqlite3_exec (dB, ssql3, _ SQL _callback, 0, & perrmsg); // close the database sqlite3_close (db); DB = 0; return 0;} conclusion: SQLite has a suitable application environment, just like the name of SQLite. DBMS should be considered for websites with high traffic or massive data.
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.