....
This commit is contained in:
parent
3d1ff9c9a9
commit
a9dce57cf3
@ -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,
|
||||
|
@ -1,11 +1,97 @@
|
||||
|
||||
//用户信息相关
|
||||
//用户信息相关
|
||||
#pragma once
|
||||
#include <QString>
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -1,2 +1,89 @@
|
||||
|
||||
#include "query_user.h"
|
||||
#include "query_user.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <ocilib.h>
|
||||
#include "../../db/ocilib/db_oper.h"
|
||||
#include "../Datastructure/UserInfo/UserInfo.h"
|
||||
#include <ocilib.hpp>
|
||||
|
||||
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<bool>(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<otext*>(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;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
//查询用户、权限等相关数据
|
||||
//查询用户、权限等相关数据
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user