From 24ed0dedcc5be918ee002c604467e43fb8e36bb1 Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Sat, 18 Jan 2020 11:10:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../car_dealer_util/car_dealer_util.vcxproj | 2 + .../car_dealer_util.vcxproj.filters | 12 ++++ .../oracle/ImportToOracle.cpp | 52 +++++++++++--- .../source/db/ocilib/db_oper.cpp | 67 +++++++++++++++++++ .../source/db/ocilib/db_oper.h | 18 +++++ 5 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 代码/cpp/car_dealer_util/source/db/ocilib/db_oper.cpp create mode 100644 代码/cpp/car_dealer_util/source/db/ocilib/db_oper.h diff --git a/代码/cpp/car_dealer_util/proj/vs2019/car_dealer_util/car_dealer_util.vcxproj b/代码/cpp/car_dealer_util/proj/vs2019/car_dealer_util/car_dealer_util.vcxproj index 432f98a..e40b5c1 100644 --- a/代码/cpp/car_dealer_util/proj/vs2019/car_dealer_util/car_dealer_util.vcxproj +++ b/代码/cpp/car_dealer_util/proj/vs2019/car_dealer_util/car_dealer_util.vcxproj @@ -24,6 +24,7 @@ + @@ -46,6 +47,7 @@ + diff --git a/代码/cpp/car_dealer_util/proj/vs2019/car_dealer_util/car_dealer_util.vcxproj.filters b/代码/cpp/car_dealer_util/proj/vs2019/car_dealer_util/car_dealer_util.vcxproj.filters index 9eb4cf8..3558515 100644 --- a/代码/cpp/car_dealer_util/proj/vs2019/car_dealer_util/car_dealer_util.vcxproj.filters +++ b/代码/cpp/car_dealer_util/proj/vs2019/car_dealer_util/car_dealer_util.vcxproj.filters @@ -65,6 +65,12 @@ {cfe6b511-cb09-441f-8496-69415615391a} + + {6e142c33-b01c-4c8d-b8a4-beaaee863cee} + + + {e5f3c3be-5fe7-471e-8dc7-d5889f5f87d9} + @@ -100,6 +106,9 @@ 数据\数据管理\导入导出\oracle + + 数据库\ocilib + @@ -154,5 +163,8 @@ 数据\数据管理\导入导出\oracle + + 数据库\ocilib + \ No newline at end of file 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 09d4b0e..2522324 100644 --- a/代码/cpp/car_dealer_util/source/Data/DataManipulation/oracle/ImportToOracle.cpp +++ b/代码/cpp/car_dealer_util/source/Data/DataManipulation/oracle/ImportToOracle.cpp @@ -6,6 +6,16 @@ using namespace std; using namespace ocilib; +void l_error_handler(OCI_Error* pError) +{ + string errorString = OCI_ErrorGetString(pError); + + std::runtime_error error(OCI_ErrorGetString(pError)); + + throw error; +} + +/* void ImportCarDealerAchievementToOracle( std::string userName, std::string password, std::string tnsName, @@ -72,15 +82,15 @@ void ImportCarDealerAchievementToOracle( std::string use string pinganAmount = QString( "%1" ).arg( iter->getPinganAmount() ).toStdString(); string othersAmount = QString( "%1" ).arg( iter->getOthersAmount() ).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", policyAmount, BindInfo::BindDirectionValues::In ); - pStmt->Bind( ":a_cpic_amount", cpicAmount, BindInfo::BindDirectionValues::In ); - pStmt->Bind( ":a_picc_amount", piccAmount, BindInfo::BindDirectionValues::In ); - pStmt->Bind( ":a_pingan_amount", pinganAmount, BindInfo::BindDirectionValues::In ); - pStmt->Bind( ":a_others_amount", othersAmount, BindInfo::BindDirectionValues::In ); + pStmt->Bind( ostring(":a_the_year"), ostring(QString::fromStdWString( iter->getTheYear() ).toStdString().c_str()), BindInfo::BindDirectionValues::In ); + pStmt->Bind(ostring(":a_the_month"), ostring(QString::fromStdWString( iter->getTheMonth() ).toStdString().c_str()), BindInfo::BindDirectionValues::In ); + pStmt->Bind(ostring(":a_car_dealer_code"), ostring(QString::fromStdWString( iter->getCarDealerCode() ).toStdString().c_str()), BindInfo::BindDirectionValues::In ); + pStmt->Bind(ostring(":a_checked_achievement"), ostring(checkedAchievement.c_str()), BindInfo::BindDirectionValues::In ); + pStmt->Bind(ostring(":a_policy_amount"), ostring(policyAmount.c_str()), BindInfo::BindDirectionValues::In ); + pStmt->Bind(ostring(":a_cpic_amount"), ostring(cpicAmount), BindInfo::BindDirectionValues::In ); + pStmt->Bind(ostring(":a_picc_amount"), ostring(piccAmount), BindInfo::BindDirectionValues::In ); + pStmt->Bind(ostring(":a_pingan_amount"), ostring(pinganAmount), BindInfo::BindDirectionValues::In ); + pStmt->Bind(ostring(":a_others_amount"), ostring(othersAmount), BindInfo::BindDirectionValues::In ); pStmt->ExecutePrepared(); } @@ -97,6 +107,30 @@ void ImportCarDealerAchievementToOracle( std::string use Environment::Cleanup(); } +*/ + +void ImportCarDealerAchievementToOracle( std::string userName, + std::string password, + std::string tnsName, + std::vector & achievementVector ) +{ + OCI_Connection * pConnection = nullptr; + OCI_Statement * pStatement = nullptr; + + 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; "; +} + void ImportRepairOrderToOracle( std::string userName, std::string password, diff --git a/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.cpp b/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.cpp new file mode 100644 index 0000000..2d39799 --- /dev/null +++ b/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.cpp @@ -0,0 +1,67 @@ + +#include +#include +#include "db_oper.h" + +const int ERROR_MESSAGE_LENGTH = 1001; + +using namespace std; + +void get_error_message(OCI_Error * pError, char * pszMessage, size_t length); + +void initOciLib() +{ + int returnCode = 0; + char * pszErrorMessage = (char *)malloc(sizeof(char) * ERROR_MESSAGE_LENGTH); + + returnCode = OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT); + + if (!returnCode ) + { + get_error_message(OCI_GetLastError(), pszErrorMessage, ERROR_MESSAGE_LENGTH - 1); + + string message("OCILIB初始化失败!\n"); + + message += pszErrorMessage; + + throw runtime_error(message); + } + + free(pszErrorMessage); +} + +void releaseOciLib() +{ + OCI_Cleanup(); +} + +void get_error_message(OCI_Error * pError, char * pszMessage, size_t length) +{ + //防御性验证 + if (pError == NULL) + { + pszMessage[0] = NULL; + + return; + } + + const otext * psz = OCI_ErrorGetString(pError); + + strcpy_s(pszMessage, length, psz); +} + +void error_handler(OCI_Error * pError) +{ + std::runtime_error error(OCI_ErrorGetString(pError)); + + OCI_Cleanup(); + + throw error; +} + +std::string get_last_error_message() +{ + OCI_Error * pError = OCI_GetLastError(); + + return std::string(OCI_ErrorGetString(pError)); +} \ No newline at end of file diff --git a/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.h b/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.h new file mode 100644 index 0000000..a1d1e6a --- /dev/null +++ b/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.h @@ -0,0 +1,18 @@ + +#ifndef _DB_OPER_H +#define _DB_OPER_H + +#include +#include +#include + +void initOciLib(); + +void releaseOciLib(); + +void error_handler(OCI_Error * pError); + +std::string get_last_error_message(); + + +#endif \ No newline at end of file