c++ Sqlite 简单使用-查询

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;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值