c++ Sqlite 簡單使用-查詢

來源:互聯網
上載者: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;};// 中文路徑支援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*)sqlite3_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 : sqlite3_column_int( pStmt, 6);pFormula->bIsDim = pField->iColFlag & cfDimension;m_vecIndexTrans[ string(CT2CA(szField))] = pFormula;}sqlite3_finalize( pStmt);sqlite3_close( pDb);return rc == SQLITE_ROW;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.