diff --git a/代码/cpp/car_dealer_util/source/Data/DataManipulation/oracle/ImportToOracle.cpp b/代码/cpp/car_dealer_util/source/Data/DataManipulation/oracle/ImportToOracle.cpp index 4ef4462..39238a0 100644 --- a/代码/cpp/car_dealer_util/source/Data/DataManipulation/oracle/ImportToOracle.cpp +++ b/代码/cpp/car_dealer_util/source/Data/DataManipulation/oracle/ImportToOracle.cpp @@ -1,14 +1,90 @@ -#include +#include #include #include #include "ImportToOracle.h" using namespace std; +using namespace ocilib; void ImportCarDealerAchievementToOracle( std::string userName, std::string password, std::string tnsName, std::vector & achievementVector ) { - + ostring sqlImport = + "BEGIN " + " car_dealer.data_import_util_pkg.import_cardealer_achvmnt( :a_the_year, " + " :a_the_month, " + " :a_car_dealer_code, " + " :a_checked_achievement, " + " :a_policy_amount, " + " :a_cpic_amount, " + " :a_picc_amount , " + " :a_pingan_amount, " + " :a_others_amount ); " + "END; "; + + //初始化 + try + { + Environment::Initialize(); + } + catch ( exception & error ) + { + string errorMessage = "ocilib初始化失败!"; + errorMessage.append( error.what() ); + + throw runtime_error( errorMessage ); + } + + Connection * pConn = nullptr; + Statement * pStmt = nullptr; + + try + { + pConn = new Connection( userName, password, tnsName ); + } + catch ( exception & error ) + { + string errorMessage = "连接oracle失败!"; + errorMessage.append( error.what() ); + + Environment::Cleanup(); + + throw runtime_error( errorMessage ); + } + + try + { + pStmt = new Statement( *pConn ); + + pStmt->Prepare( sqlImport ); + pStmt->AllowRebinding( true ); + + for ( auto iter = achievementVector.begin(); + iter != achievementVector.end(); + ++iter ) + { + string checkedAchievement = QString("%1").arg( static_cast(iter->getCheckedAchievement())).toStdString(); + + pStmt->Bind( ":a_the_year", QString::fromStdWString( iter->getTheYear() ).toStdString(), BindInfo::BindDirectionValues::In ); + pStmt->Bind( ":a_the_month", QString::fromStdWString( iter->getTheMonth() ).toStdString(), BindInfo::BindDirectionValues::In ); + pStmt->Bind( ":a_car_dealer_code", QString::fromStdWString( iter->getCarDealerCode() ).toStdString(), BindInfo::BindDirectionValues::In ); + pStmt->Bind( ":a_checked_achievement", checkedAchievement, BindInfo::BindDirectionValues::In ); + pStmt->Bind( ":a_policy_amount", QString::fromStdWString( iter->getTheYear() ).toStdString(), BindInfo::BindDirectionValues::In ); + pStmt->Bind( ":a_cpic_amount", QString::fromStdWString( iter->getTheYear() ).toStdString(), BindInfo::BindDirectionValues::In ); + pStmt->Bind( ":a_picc_amount", QString::fromStdWString( iter->getTheYear() ).toStdString(), BindInfo::BindDirectionValues::In ); + pStmt->Bind( ":a_pingan_amount", QString::fromStdWString( iter->getTheYear() ).toStdString(), BindInfo::BindDirectionValues::In ); + pStmt->Bind( ":a_others_amount", QString::fromStdWString( iter->getTheYear() ).toStdString(), BindInfo::BindDirectionValues::In ); + } + } + catch ( exception & error ) + { + string errorMessage = "语句执行失败!"; + errorMessage.append( error.what() ); + + Environment::Cleanup(); + + throw runtime_error( errorMessage ); + } }