C + + calls SQLite3 's common use method;

Source: Internet
Author: User
Tags sprintf sqlite

The following are the examples of sqlite used for testing, you can refer to the use;

1   1#include"CppSQLite3.h"2   2 3   3Class testsqlite{4   4     5   5     //defining the DB pointer6   6 Private:7   7cppsqlite3db*m_psqldb;8   8Testsqlite ()9   9     {Ten  TenM_psqldb =NULL; One   OneInit (); A   A     } -   -      -   -~Testsqlite () the   the     { -   -         if(M_PSQLDB) -   -         { -   -m_psqldb.close (); +   +             Deletem_psqldb; -   -M_psqldb =NULL; +   +         }     A   A     } at   at     //Initialize -   -BOOL Init () -   -     { -   -         //Initialize the SQLite pointer -   -         if(M_psqldb | |! (M_psqldb =Newcppsqlite3db)) -   -         { in   in             returnFALSE; -   -         } to   to          +   +         Try -   -         { the   the             stringStrdbfile ="d:\\chunk.s3db"; *   *M_psqldb->open (Strdbfile.c_str ());//open a local database at the specified location $   $         }Panax Notoginseng  Panax Notoginseng         Catch(cppsqlite3exception& e)//Handling SQLite Exceptions -   -         { the   the             returnFALSE; +   +         } A   A          the   the         returnTRUE; +   +     } -   -  Public: $   $     //read the table data for the specified name in db $   $     voidReadallline (map<int,int>& Mpdbinfo,Const string&tblname) -   -     { -   -         Try the   the         { -   -             Charszcmd[ the];Wuyi  Wuyisprintf (Szcmd,"SELECT id,testnum from%s;", tblname); the   theCppsqlite3query query = M_psqldb->execquery (szcmd);//Execute Query Statement -   -              while(!query.eof ()) Wu   Wu             { -   -                 intid = Query.getintfield ("ID");//value of the column entry as ID About   About                 intTestnum = Query.getintfield ("Testnum");//the value of the column item Testnum $   $                  -   -Mpdbinfo.insert (Make_pair (id,testnum));//Insert Map -   -Query.nextrow ();//continue to the next line -   -             } A   AQuery.finalize ();//end query, freeing memory +   +         }     the   the         Catch(cppsqlite3exception&e) -   -         {         $   $             return; the   the         } the   the     } the   the      the   the     //Update specified data -   -BOOL Deleteline (Const string& Tblname,Const int& ID,Const int&num) in   in     { the   the         Try the   the         { About   About             Charszcmd[ the]; the   thesprintf (Szcmd,"Update%s Set num =%d WHERE id=%d;", Tblname,num,id);//Update Content the   theM_psqldb->execdml (szcmd); the   the         } +   +         Catch(cppsqlite3exception&e) -   -         {         the   the             returnFALSE;Bayi  Bayi         } the   the         returnTRUE; the   the     } -   -      -   -     //Delete specified data the   theBOOL Deleteline (Const string& Tblname,Const int&ID) the   the     { the   the         Try the   the         { -   -             Charszcmd[ the]; the   thesprintf (Szcmd,"DELETE from%d WHERE id=%d;", Tblname,id);//DELETE statement the   theM_psqldb->execdml (szcmd); the   the         }94  94         Catch(cppsqlite3exception&e) the   the         {         the   the             returnFALSE; the   the         }98  98         returnTRUE; About   About     } -  - };101 102  

C + + calls SQLite3 's common use method;

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.