Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
216 lines
6.5 KiB
C++
216 lines
6.5 KiB
C++
/**
|
|
* @file NFOLEDB.h
|
|
* @brief OLD DB 객체
|
|
* @remarks
|
|
* @author 강동명(edith2580@gmail.com)
|
|
* @date 2009-05-09
|
|
*/
|
|
#pragma once
|
|
|
|
#include <oledb.h>
|
|
#include <oledberr.h>
|
|
|
|
//#define _CHECK_OLEDB_PERFORMANCE // DB 퍼포먼스 체크
|
|
#ifdef _CHECK_OLEDB_PERFORMANCE
|
|
#define DB_PERFORMANCE_CHECK(x) x
|
|
#else
|
|
#define DB_PERFORMANCE_CHECK(x) (void*)0;
|
|
#endif
|
|
|
|
/*
|
|
SQL Server Data Type ADO Data Type SQLOLEDB data type
|
|
bigint adBigInt DBTYPE_I8
|
|
binary adBinary DBTYPE_BYTES
|
|
bit adBoolean DBTYPE_BOOL
|
|
char adChar DBTYPE_STR
|
|
datetime adDBTimeStamp DBTYPE_DBTIMESTAMP
|
|
decimal adNumeric DBTYPE_NUMERIC
|
|
float adDouble DBTYPE_R8
|
|
image adVarbinary DBTYPE_BYTES
|
|
int adInteger DBTYPE_I4
|
|
money adCurrency DBTYPE_CY
|
|
nchar adWChar DBTYPE_WSTR
|
|
ntext adWChar DBTYPE_WSTR
|
|
numeric adNumeric DBTYPE_NUMERIC
|
|
nvarchar adWChar DBTYPE_WSTR
|
|
real adSingle DBTYPE_R4
|
|
smalldatetime adTimeStamp DBTYPE_DBTIMESTAMP
|
|
smallint adSmallInt DBTYPE_I2
|
|
smallmoney adCurrency DBTYPE_CY
|
|
sql_variant adVariant DBTYPE_VARIANT, DBTYPE_SQLVARIANT*
|
|
sysname adWChar DBTYPE_WSTR
|
|
text adChar DBTYPE_STR
|
|
timestamp adBinary DBTYPE_BYTES
|
|
tinyint adVarbinary DBTYPE_UI1
|
|
uniqueidentifier adGUID DBTYPE_GUID
|
|
varbinary adVarBinary DBTYPE_BYTES
|
|
varchar adChar DBTYPE_STR
|
|
|
|
분류 데이터 타입 범위 저장소크기
|
|
|
|
정수
|
|
Bit O 또는 1 bit
|
|
Int -2,147,483,648 ~ 2,147,483,647 4 바이트
|
|
Smallint -32,768 ~ 32,767 2 바이트
|
|
Tinyint 0 ~ 255 1 바이트
|
|
Bigint -2^63 ~ 2^63-1 8 바이트
|
|
|
|
부동소수점
|
|
Float[n] -1.79E+308 ~ 1.79E+308
|
|
n = 1~24 4 바이트
|
|
Float[n] -1.79E+308 ~ 1.79E+308
|
|
n = 25~53 8 바이트
|
|
|
|
Real -3.40E + 38 ~ 3.40E + 38 4 바이트
|
|
|
|
문자데이터
|
|
char[n] n = 1~8000 n 바이트
|
|
Varchar[n] n = 1~8000 입력한 데이터의 길이
|
|
Text 최대 2,147,483,647자의가변길이
|
|
|
|
유니코드
|
|
문자데이터 Nchar n = 1~4000 n*2 바이트
|
|
nvarchar n = 1~4000 입력한 데이터의 길이*2 바이트
|
|
Ntext 최대 1,073,741,823자의 가변길이
|
|
|
|
이진데이터
|
|
binary n = 1~8000 n+4 바이트
|
|
varbinary n = 1~8000 입력한 데이터의 길이+4 바이트
|
|
Image 최대 2,147,483,647자의 가변길이
|
|
|
|
날짜와시간
|
|
datetime 1753/1/1~9999/12/31 8 바이트
|
|
smalldatetime 1900/1/1~2079/6/6 4 바이트
|
|
|
|
화폐
|
|
money -922,337,203,685,477.5808~
|
|
+922,337,203,685,477.5807 8 바이트
|
|
smallmoney -214,748.3648~214,748.3647 4 바이트
|
|
*/
|
|
|
|
namespace NaveServer {
|
|
|
|
/**
|
|
* @class NFOleDB
|
|
* @brief NFOleDB를 이용해 Database에 접근하기 위한 클래스
|
|
* @remarks
|
|
*
|
|
* @todo 현재 nchar와 nvarchar 즉 2byte 유니코드 문자형을 제대로 지원하지 못한다.
|
|
* 이부분을 테스트 해야한다. 2byte 문자열을 쿼리에 날릴때 문자앞에 유니코드
|
|
* 라고 지정하는게 있는데 이거랑 연관관계가 있는지 확인해야함
|
|
* @par
|
|
* @author Edith
|
|
* @date 2009-05-09
|
|
*/
|
|
class NFOleDB
|
|
{
|
|
public:
|
|
const static unsigned long MaxRowNum = 2000; /// 최대 열 숫자
|
|
const static unsigned long MaxErrorLen = 512; /// 최대 에러 길이
|
|
const static unsigned long MaxQueryTextLen = 8192; /// 최대 쿼리 문자열 길이
|
|
|
|
public:
|
|
/// DBConnect 타입을 말한다.
|
|
enum ConnType
|
|
{
|
|
ConnType_ODBC = 0,
|
|
ConnType_MSSQL = 1,
|
|
ConnType_ORACLE
|
|
};
|
|
|
|
// 쿼리 실행후 로우셋
|
|
enum Rowset
|
|
{
|
|
Rowset_Get = 0,
|
|
Rowset_Update = 1
|
|
};
|
|
|
|
/// 쿼리를 날릴때 파라메터로 쿼리를 날릴경우 사용한다.
|
|
typedef struct PARAM_INFO
|
|
{
|
|
const static unsigned short MaxColNum = 30; /// 최대 컬럼 이름 길이
|
|
|
|
unsigned long ColNum; /// 컬럼 숫자
|
|
DBPARAMIO eParamIO[MaxColNum]; /// 컬럼 파라미터 타입
|
|
unsigned long ColSize[MaxColNum]; /// 컬럼 사이즈
|
|
unsigned short ColType[MaxColNum]; /// 컬럼 타입
|
|
}*LPPARAM_INFO;
|
|
|
|
/// 바이너리의 정보를 전달할때 사용한다.
|
|
typedef struct SET_BINARY
|
|
{
|
|
unsigned long Size;
|
|
}*LPSET_BINARY;
|
|
|
|
/// 컬럼의 정보를 설정한다. (현재 지원하지 않는다.)
|
|
typedef struct COL_INFO
|
|
{
|
|
const static unsigned short MaxColNameLen = 100; /// 최대 컬럼 이름 길이
|
|
|
|
char ColName[MaxColNameLen]; /// 컬럼 이름
|
|
unsigned long ColSize; /// 컬럼 사이즈
|
|
}*LPCOL_INFO;
|
|
|
|
public:
|
|
NFOleDB(void);
|
|
virtual ~NFOleDB(void);
|
|
|
|
inline LPCWSTR GetErrorString(void) const { return m_ErrorString; }
|
|
inline LPCWSTR GetLastMessage(void) const { return m_LastMessage; }
|
|
inline HRESULT GetLastError(void) const { return m_dwLastError; }
|
|
|
|
bool ConnectDataSourcePrompt(HWND hWnd_In);
|
|
bool ConnectSQLServer(LPCWSTR ServerName_In, LPCWSTR DataBaseName_In, LPCWSTR UserID_In, LPCWSTR UserPass_In, ConnType ConnType_In);
|
|
bool DisconnectDataSource(void);
|
|
|
|
bool ExecuteQuery(LPCWSTR Query_In, Rowset Rowset_In = Rowset_Get);
|
|
bool ExecuteQueryWithParams(LPCWSTR Query_In, char *Data_In, const PARAM_INFO& ColInfo_In);
|
|
bool ExecuteQueryGetData(LPCWSTR Query_In, void *Buffer_Out);
|
|
|
|
bool GetData(void *Buffer_Out);
|
|
bool GetData(void **Buffer_Out, int RowSize_In, int Row_In, int *pGetRow_Out);
|
|
|
|
bool SetBinaryData(int ColNum_In, LPSET_BINARY lpSetBinary);
|
|
|
|
COL_INFO& GetColInfo(void) { return m_ColInfo; }
|
|
|
|
public:
|
|
IDBInitialize* m_pIDBInit;
|
|
IDBCreateSession* m_pIDBCreateSession;
|
|
IDBCreateCommand* m_pIDBCreateCommand;
|
|
IRowset* m_pIRowset;
|
|
IRowsetChange* m_pIRowsetChange;
|
|
|
|
HRESULT m_dwLastError;
|
|
|
|
WCHAR m_ErrorString[MaxErrorLen];
|
|
WCHAR m_LastMessage[MaxErrorLen];
|
|
|
|
private:
|
|
/// 컬럼 결과값을 지정한다.
|
|
typedef struct RESULT_COLS
|
|
{
|
|
unsigned long ColNum;
|
|
DBCOLUMNINFO* lpDBColumnInfo;
|
|
WCHAR* lpStringsBuffer;
|
|
}*LPRESULT_COLS;
|
|
|
|
WCHAR m_QueryText[MaxQueryTextLen]; /// 쿼리 문자열
|
|
COL_INFO m_ColInfo; /// 컬럼의 정보
|
|
|
|
private:
|
|
|
|
bool HandleError(int ErrorLine_In, HRESULT hResult_In, WCHAR *Buffer_In);
|
|
|
|
bool CreateSession(void);
|
|
bool DBCreateCommand(void);
|
|
|
|
bool AllocResultCols(IUnknown* lpIUnknown_In, RESULT_COLS &Rsult_Cols);
|
|
bool ReleaseResultCols(IUnknown* lpIUnknown_In, RESULT_COLS &Rsult_Cols);
|
|
|
|
bool SetConnectionProperties(LPCWSTR ServerName_In, LPCWSTR DataBaseName_In, LPCWSTR UserID_In, LPCWSTR UserPass_In);
|
|
DBBINDING* AllocBindGetData(int ColsNum_In, DBCOLUMNINFO* pDBColumnInfo_In);
|
|
DBBINDING* AllocBindParamInputData(const PARAM_INFO &ColInfo_In);
|
|
};
|
|
|
|
} |