搞定车商代码缓存!

This commit is contained in:
Kane Wang 2020-11-23 14:30:05 +08:00
parent a4d1e51da8
commit 6572379132
1 changed files with 38 additions and 0 deletions

View File

@ -50,6 +50,7 @@ void initCarDealerMap()
string errorMessage = "ocilib初始化失败";
}
//连接
try
{
pConnection = OCI_ConnectionCreate( tnsName.c_str(),
@ -60,8 +61,45 @@ void initCarDealerMap()
catch ( runtime_error & error )
{
//连接数据库失败
string errorMessage = "连接数据库失败!";
errorMessage.append(error.what());
OCI_Cleanup();
throw runtime_error(errorMessage.c_str());
}
//查询
try
{
pStatement = OCI_StatementCreate( pConnection );
OCI_ExecuteStmt( pStatement, sql.c_str() );
pResult = OCI_GetResultset( pStatement );
pCarDealerMap = new unordered_map<string, CarDealer>;
while ( OCI_FetchNext( pResult ) == true )
{
string carDealerCodeIndex = OCI_GetString( pResult, 1 );
QString carDealerCode = QString::fromLocal8Bit( OCI_GetString( pResult, 1 ) );
QString carDealerName = QString::fromLocal8Bit( OCI_GetString( pResult, 2 ) );
CarDealer dealer( carDealerCode, carDealerName );
pCarDealerMap->insert( pair<string, CarDealer>( carDealerCodeIndex, dealer ) );
}
}
catch ( runtime_error & error )
{
string errorMessage = "执行查询失败!";
errorMessage.append(error.what());
OCI_Cleanup();
throw runtime_error(errorMessage.c_str());
}
OCI_Cleanup();