Using C language to connect SQLite under Linux

Source: Internet
Author: User

1. Create a new folder named SQLite in/home/

#cd/Home

#mkdir SQLite

2. Write the C language code, the name is SQL.C, the code is as follows

    //name:sql.c//This prog was used to test C + + API for sqlite3.       It is very simple,ha! //Author:zieckey All rights reserved. //DATA:2006/11/13#include<stdio.h>#include<stdlib.h>#include"sqlite3.h"           intMainvoid) {sqlite3*db=NULL; Char*zerrmsg =0; intRC; //opens the specified database file and creates a database file with the same name if it does not existrc = Sqlite3_open ("zieckey.db", &db); if(RC) {fprintf (stderr,"Can ' t Open database:%s", sqlite3_errmsg (db));       Sqlite3_close (DB); Exit (1); }       Elseprintf"You have opened a sqlite3 database named Zieckey.db successfully! congratulations! There's fun! ^-^ "); Sqlite3_close (DB); //Close the database     return 0; }  

3. Download the source code on the Internet and put it under the new SQLite folder. http://www.sqlite.org/

4. Unzip the source code under the sqlite-autoconf-3080600.tar.gz

#tar-ZXVF sqlite-autoconf-3080600.tar.gz

There will be one more folder under the/home/sqlite/folder sqlite-autoconf-3080600

5. Compiling the code is also the most important step

# gcc-o Sql.out-l/home/sqlite/sqlite-autoconf-3080600/.libs-i/home/sqlite/sqlite-autoconf-3080600 sql.c-lsqlite3

The main meaning of the above:-L for you to install the Sqlite3 class library where the path,-I for the installation of Sqlite3 header file path and-L represents the name of the executable program, through the above compilation, can be successful.

Sql.out is the generated executable file, SQL.C is the original file

Executing the generated code

#./sql.out

Output the following information to indicate success

You have opened a sqlite3 database named Zieckey.db successfully! congratulations! There's fun! ^-^

Using C language to connect SQLite under Linux

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.