/** * @file NFOLEDB.h * @brief OLD DB °´Ã¼ * @remarks * @author °­µ¿¸í(edith2580@gmail.com) * @date 2009-05-09 */ #pragma once #include #include //#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); }; }