SQLite installation and post-encapsulation compilation

Source: Internet
Author: User
Tags sqlite

======================== installation sqlite=================
Download the installation package *.tar.gz format
./configure--prefix=/usr/server/sqlit Installation package Directory
Make
Make install

Test installation succeeded Sqlite3 test.db

======================= compiling ====================
Add parameter-i/usr/server/sqlite/include at compile time
-l/usr/server/sqlite/lib
-static if compiled as static

-lsqlite3 Join it on OK

======================= source program =================

Looking for it online.

/*Others: Sqlite3 Dynamic Library Gcc-o db DB.C required./libsqlite3.so//Not yet understood or gcc-o DB Db.c-lsqlite3//Not yet understood *************************************************/#include<stdio.h>#include<string.h>#include<stdlib.h>#include<sqlite3.h>intDbopendatabase (Char*strdbname, Sqlite3 * *Hdbcon) {    intIRet = Sqlite3_open (Strdbname,hdbcon);//Open Database    if(IRet! =SQLITE_OK) {        return 0; }    Else    {        return 1; }}voidDbclosedatabase (Sqlite3 *Hdbcon) {sqlite3_close (Hdbcon);}intDbchangedatarecord (Sqlite3 *hdbcon,Char*strSQL) {    Char*perrmsg =0;//error Message    intIRet = Sqlite3_exec (Hdbcon, strSQL, NULL, NULL, &perrmsg); if(IRet! =SQLITE_OK) {        //printf ("Query failed, error code ==>:%d, error Reason ==>:%s\n", ret, errmsg);        return-1; }    Else    {        returnIRet; }    }intDbexecutequerysql (Sqlite3 *Hdbcon,Char*strSQL,Char***Strresult,int*IRow,int*iColumn) {    Char*perrmsg = NULL;//error Log    intIreturn =0; intIresult = sqlite3_get_table (Hdbcon,strsql, Strresult, IRow, IColumn, &perrmsg); if(SQLITE_OK = =Iresult) {Ireturn=1; }    Else{Ireturn=0; }    returnIreturn;}voidDbfreeresources (Char**strresult) {sqlite3_free_table (strresult);}intDbsqlitecallback (Sqlite3 * Hdbcon,Const Char*strsql,int(*queryresultback) ()){    Char*perrmsg; intIretdb =0; Iretdb= Sqlite3_exec (hdbcon,strsql,queryresultback,null,&perrmsg); if(Iretdb! =SQLITE_OK) {        return 0; }    return 1;}//callback Function Example test/*static int queryresultback (void *para,int Icolumn,char **cvalue,char **ccolumnvaluename) {int iCn; for (ICN = 0; ICN < IColumn; icn++) {//printf ("%s =%s\n", Ccolumnvaluename[i], cvalue[i]? Cvalue[i]: "NU         LL ");    printf ("%s =%s\n", Ccolumnvaluename[i], cvalue[i]); } return 0;}*/intMainintargcChar*argv[]) {    Char*dbname="dtmsg.db"; Sqlite3*DB; intIreturn=dbopendatabase (dbname,&db); printf ("-1->%d<---\ n", Ireturn); if(ireturn==1)    {        //Add, modify, delete        Char*sql="INSERT INTO t_msg (Msg,msg_buff) VALUES (' Test ', ' testing Information one ')"; //char * sql= "update t_msg set msg_buff= ' test information 2222222 ' where msg= ' test '"; //char * sql= "delete from t_msg where msg= ' test '";printf"-2-->%s<--\n", SQL); intisqlret=Dbchangedatarecord (Db,sql); printf ("-3-->%d<--\n", Isqlret); //Enquiry//char *sql= "SELECT * from t_msg";Sql="SELECT * from T_msg"; Char**Dbresult; intNrow,ncolumn,index; inti,j; intIqret=dbexecutequerysql (db,sql,&dbresult,&nrow,&ncolumn); if(iqret==1) {Index=Ncolumn;  for(i =0; i < Nrow; i++) {printf ("article ====================>%d record \ n", i+1 );  for(j =0; J < Ncolumn; J + +) {printf ("Field Name:%s ==> field value:%s\n", Dbresult[j],dbresult[index]?dbresult[index]:"" ); ++index; }            }        }        //regardless of the success of the database query, release the char** query results and use the functionality provided by SQLite to release//freeresources (dbresult);sqlite3_free_table (Dbresult);    } dbclosedatabase (db); return 1;}
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.