C ++ SQLite simple use-Query

Source: Internet
Author: User
Bool cfileconfigure: loadsqliteconfig (const cstring & szfield, cfieldex * pfield) {uses_conversion; cstring szpath, szsql; szpath. format (_ T ("% s \ stat \ normal_conf.data"), capplication: configdir (); sqlite3 * PDB = NULL; sqlite3_stmt * pstmt = NULL; auto mbcstoutf8 = [] (const char * file)-> char * {wchar * pwchar = 0; char * pchar = 0; int Len = 0; int codePage = arefileapisansi ()? Cp_acp: cp_oemcp; Len = multibytetowidechar (codePage, 0, file,-1, null, 0); pwchar = new wchar [Len]; Assert (pwchar); If (pwchar! = 0) {Len = multibytetowidechar (codePage, 0, file,-1, pwchar, Len); If (Len! = 0) {Len = widechartomultibyte (cp_utf8, 0, pwchar,-1, 0, 0, 0, 0); pchar = new char [Len]; Assert (pchar ); if (pchar! = 0) {Len = widechartomultibyte (cp_utf8, 0, pwchar,-1, pchar, Len, 0, 0); If (Len! = 0) {Delete pwchar; return pchar ;}} Delete pwchar ;}return pchar ;}; // The Chinese path supports char * ppath = mbcstoutf8 (ct2ca (szpath )); if (sqlite3_open (ppath, & PDB )! = Sqlite_ OK) {Delete [] ppath; return false;} Delete [] ppath; szsql. format (_ T ("Select name, caption, \" Type \ ", formula, formulaname, formulaparam, drill, Lua from indexconfig where upper (name) = upper ('% s') "), szfield); int rc = sqlite3_prepare (PDB, ct2ca (szsql),-1, & pstmt, null ); rc = sqlite3_step (pstmt); If (rc = sqlite_row) {stformula * pformula = new stformula (); pformula-> szcaption = (tchar *) sqli Te3_column_text16 (pstmt, 1); pformula-> utype = sqlite3_column_int (pstmt, 2); pformula-> ulength = sqlite3_column_int (pstmt, 2) = 3? 64: 8; pformula-> uformulatype = sqlite3_column_int (pstmt, 3); pformula-> szformulaname = (tchar *) sqlite3_column_text16 (pstmt, 4 ); pformula-> szformulaparam = (tchar *) sqlite3_column_text16 (pstmt, 5); pformula-> szformulalua = (tchar *) sqlite3_column_text16 (pstmt, 7 ); pformula-> benabledrill = pfield-> icolflag & cfdelay? True: Average (pstmt, 6); pformula-> bisdim = pfield-> icolflag & cfdimension; m_vecindextrans [String (ct2ca (szfield)] = pformula;} average (pstmt ); sqlite3_close (PDB); Return rc = sqlite_row ;}

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.