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;