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 006cf47..9a75e41 100644 --- a/代码/cpp/car_dealer_util/source/Data/DataManipulation/oracle/ImportToOracle.cpp +++ b/代码/cpp/car_dealer_util/source/Data/DataManipulation/oracle/ImportToOracle.cpp @@ -7,14 +7,14 @@ 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 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, diff --git a/代码/cpp/car_dealer_util/source/Data/Datastructure/UserInfo/UserInfo.h b/代码/cpp/car_dealer_util/source/Data/Datastructure/UserInfo/UserInfo.h index f724751..cb24ef8 100644 --- a/代码/cpp/car_dealer_util/source/Data/Datastructure/UserInfo/UserInfo.h +++ b/代码/cpp/car_dealer_util/source/Data/Datastructure/UserInfo/UserInfo.h @@ -1,11 +1,97 @@ - -//用户信息相关 +//用户信息相关 #pragma once #include class UserInfo { -private: - QString staff_p13; +public: + UserInfo( const std::string & staffP13, + const std::string & staffName, + const std::string & staffPost ) + : staff_p13( staffP13 ), + staff_name( staffName ), + staff_post( staffPost ) + { + } + + + UserInfo( const UserInfo & other ) + : staff_p13( other.staff_p13 ), + staff_name( other.staff_name ), + staff_post( other.staff_post ) + { + } + + UserInfo( UserInfo && other ) + : staff_p13( std::move(other.staff_p13) ), + staff_name( std::move(other.staff_name) ), + staff_post( std::move(other.staff_post) ) + { + } + + UserInfo & operator=( const UserInfo & other ) + { + if ( this == &other ) + return *this; + staff_p13 = other.staff_p13; + staff_name = other.staff_name; + staff_post = other.staff_post; + return *this; + } + + UserInfo & operator=( UserInfo && other ) + { + if ( this == &other ) + return *this; + staff_p13 = std::move( other.staff_p13 ); + staff_name = std::move( other.staff_name ); + staff_post = std::move( other.staff_post ); + return *this; + } + + + friend void swap( UserInfo & lhs, UserInfo & rhs ) noexcept + { + using std::swap; + swap( lhs.staff_p13, rhs.staff_p13 ); + swap( lhs.staff_name, rhs.staff_name ); + swap( lhs.staff_post, rhs.staff_post ); + } + + + std::string getStaffP13() const + { + return staff_p13; + } + + void setStaffP13( const std::string & staffP13 ) + { + staff_p13 = staffP13; + } + + std::string getStaffName() const + { + return staff_name; + } + + void setStaffName( const std::string & staffName ) + { + staff_name = staffName; + } + + std::string getStaffPost() const + { + return staff_post; + } + + void setStaffPost( const std::string & staffPost ) + { + staff_post = staffPost; + } + +private: + std::string staff_p13; + std::string staff_name; + std::string staff_post; }; diff --git a/代码/cpp/car_dealer_util/source/Data/query/query_user.cpp b/代码/cpp/car_dealer_util/source/Data/query/query_user.cpp index a61992f..8cd624c 100644 --- a/代码/cpp/car_dealer_util/source/Data/query/query_user.cpp +++ b/代码/cpp/car_dealer_util/source/Data/query/query_user.cpp @@ -1,2 +1,89 @@ - -#include "query_user.h" \ No newline at end of file +#include "query_user.h" + +#include +#include +#include "../../db/ocilib/db_oper.h" +#include "../Datastructure/UserInfo/UserInfo.h" +#include + +using namespace std; + + + +UserInfo queryUserInfo( const string & userName, + const string & password, + const string & tnsName, + const string & staffP13 ) +{ + OCI_Connection * pConn = nullptr; + OCI_Statement * pStmt = nullptr; + OCI_Resultset * pResult = nullptr; + int returnCode = 0; + + + otext szSqlQueryStaff[] = + "SELECT a.staff_p13, a.staff_name, b.staff_post \n" + "FROM staff_info a, \n" + "staff_post_code b \n" + "WHERE a.staff_post_code = b.staff_post_code \n" + "AND a.staff_p13 = :p13 "; + + returnCode = OCI_Initialize( l_error_handler, nullptr, OCI_ENV_DEFAULT ); + + if ( static_cast(returnCode) == false ) + { + string errorMessage( "ocilib初始化错误:" ); + errorMessage.append( get_last_error_message() ); + + throw runtime_error( errorMessage ); + } + + try + { + pConn = OCI_ConnectionCreate( tnsName.c_str(), + userName.c_str(), + password.c_str(), + OCI_SESSION_DEFAULT ); + } + catch ( runtime_error & error ) + { + OCI_Cleanup(); + + throw error; + } + + try + { + pStmt = OCI_StatementCreate( pConn ); + + OCI_AllowRebinding( pStmt, true ); + OCI_Prepare( pStmt, szSqlQueryStaff ); + + OCI_BindString( pStmt, ":p13", const_cast(staffP13.c_str()), staffP13.size() ); + OCI_Execute( pStmt ); + + pResult = OCI_GetResultset( pStmt ); + + //检查结果集,如果没有返回,则说明没有此用户 + if ( OCI_FetchFirst( pResult ) == false ) + { + throw runtime_error( "用户不存在!" ); + } + } + catch ( runtime_error & error ) + { + OCI_ConnectionFree( pConn ); + OCI_Cleanup(); + + throw error; + } + + UserInfo info( OCI_GetString( pResult, 1 ), + OCI_GetString( pResult, 2 ), + OCI_GetString( pResult, 3 ) ); + + OCI_ConnectionFree(pConn); + OCI_Cleanup(); + + return info; +} diff --git a/代码/cpp/car_dealer_util/source/Data/query/query_user.h b/代码/cpp/car_dealer_util/source/Data/query/query_user.h index 8f2695c..aa0c5f8 100644 --- a/代码/cpp/car_dealer_util/source/Data/query/query_user.h +++ b/代码/cpp/car_dealer_util/source/Data/query/query_user.h @@ -1,4 +1,5 @@ - -//查询用户、权限等相关数据 +//查询用户、权限等相关数据 #pragma once +#include + diff --git a/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.cpp b/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.cpp index 2d39799..3ccadbe 100644 --- a/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.cpp +++ b/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.cpp @@ -59,6 +59,15 @@ void error_handler(OCI_Error * pError) throw error; } +void l_error_handler(OCI_Error* pError) +{ + string errorString = OCI_ErrorGetString(pError); + + std::runtime_error error(OCI_ErrorGetString(pError)); + + throw error; +} + std::string get_last_error_message() { OCI_Error * pError = OCI_GetLastError(); diff --git a/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.h b/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.h index a1d1e6a..f4a29f8 100644 --- a/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.h +++ b/代码/cpp/car_dealer_util/source/db/ocilib/db_oper.h @@ -1,4 +1,4 @@ - + #ifndef _DB_OPER_H #define _DB_OPER_H @@ -11,6 +11,7 @@ void initOciLib(); void releaseOciLib(); void error_handler(OCI_Error * pError); +void l_error_handler(OCI_Error* pError); std::string get_last_error_message();