Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
8.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // SQLOBJ.CPP
  4. //
  5. // SQL Wrapper Object
  6. //
  7. // Copyright (c) Microsoft Corporation 1998
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. #include "precomp.h"
  11. #include "sqlobj.h"
  12. SQL::SQL(void)
  13. {
  14. TCHAR path[_MAX_PATH];
  15. GetSystemDirectory(path, sizeof(path)/sizeof(TCHAR));
  16. lstrcat(path, TEXT("\\odbccp32.dll"));
  17. m_hODBCCP = LoadLibrary(path);
  18. m_hODBC = NULL;
  19. if (m_hODBCCP)
  20. {
  21. GetSystemDirectory(path, sizeof(path)/sizeof(TCHAR));
  22. lstrcat(path, TEXT("\\odbc32.dll"));
  23. m_hODBC = LoadLibrary(path);
  24. if (m_hODBC == NULL)
  25. {
  26. FreeLibrary(m_hODBCCP);
  27. }
  28. }
  29. if (m_hODBCCP && m_hODBC)
  30. {
  31. m_pfnSetPos = (SQ_SETPOS) GetProcAddress( m_hODBC, "SQLSetPos");
  32. m_pfnExtendedFetch = (SQ_EXTENDEDFETCH) GetProcAddress( m_hODBC, "SQLExtendedFetch");
  33. m_pfnFreeStmt = (SQ_FREESTMT) GetProcAddress( m_hODBC, "SQLFreeStmt");
  34. m_pfnSetStmtOption = (SQ_SETSTMTOPTION) GetProcAddress( m_hODBC, "SQLSetStmtOption");
  35. m_pfnBindCol = (SQ_BINDCOL) GetProcAddress( m_hODBC, "SQLBindCol");
  36. m_pfnAllocStmt = (SQ_ALLOCSTMT) GetProcAddress( m_hODBC, "SQLAllocStmt");
  37. m_pfnFreeConnect = (SQ_FREECONNECT) GetProcAddress( m_hODBC, "SQLFreeConnect");
  38. m_pfnFreeEnv = (SQ_FREEENV) GetProcAddress( m_hODBC, "SQLFreeEnv");
  39. m_pfnDisconnect = (SQ_DISCONNECT) GetProcAddress( m_hODBC, "SQLDisconnect");
  40. m_pfnAllocConnect = (SQ_ALLOCCONNECT) GetProcAddress( m_hODBC, "SQLAllocConnect");
  41. m_pfnAllocEnv = (SQ_ALLOCENV) GetProcAddress( m_hODBC, "SQLAllocEnv");
  42. m_pfnTransact = (SQ_TRANSACT) GetProcAddress( m_hODBC, "SQLTransact");
  43. m_pfnFetch = (SQ_FETCH) GetProcAddress( m_hODBC, "SQLFetch");
  44. #ifdef UNICODE
  45. m_pfnConfigDataSource = (SQ_CONFIGDATASOURCE) GetProcAddress( m_hODBCCP, "SQLConfigDataSourceW");
  46. m_pfnConnect = (SQ_CONNECT) GetProcAddress( m_hODBC, "SQLConnectW");
  47. m_pfnError = (SQ_ERROR) GetProcAddress( m_hODBC, "SQLErrorW");
  48. m_pfnExecDirect = (SQ_EXECDIRECT) GetProcAddress( m_hODBC, "SQLExecDirectW");
  49. m_pfnSetConnectOption = (SQ_SETCONNECTOPTION) GetProcAddress( m_hODBC, "SQLSetConnectOptionW");
  50. m_pfnStatistics = (SQ_STATISTICS) GetProcAddress( m_hODBC, "SQLStatisticsW");
  51. m_pfnDescribeCol = (SQ_DESCRIBECOL) GetProcAddress( m_hODBC, "SQLDescribeColW");
  52. #else
  53. //for some reason, there is no "A" on odbc's export of SQLConfigDataSource
  54. m_pfnConfigDataSource = (SQ_CONFIGDATASOURCE) GetProcAddress( m_hODBCCP, "SQLConfigDataSource");
  55. m_pfnConnect = (SQ_CONNECT) GetProcAddress( m_hODBC, "SQLConnectA");
  56. m_pfnError = (SQ_ERROR) GetProcAddress( m_hODBC, "SQLErrorA");
  57. m_pfnExecDirect = (SQ_EXECDIRECT) GetProcAddress( m_hODBC, "SQLExecDirectA");
  58. m_pfnSetConnectOption = (SQ_SETCONNECTOPTION) GetProcAddress( m_hODBC, "SQLSetConnectOptionA");
  59. m_pfnStatistics = (SQ_STATISTICS) GetProcAddress( m_hODBC, "SQLStatisticsA");
  60. m_pfnDescribeCol = (SQ_DESCRIBECOL) GetProcAddress( m_hODBC, "SQLDescribeColA");
  61. #endif
  62. if (!m_pfnConfigDataSource || !m_pfnSetPos || !m_pfnExtendedFetch || !m_pfnFreeStmt || !m_pfnExecDirect ||
  63. !m_pfnSetStmtOption || !m_pfnBindCol || !m_pfnError || !m_pfnAllocStmt || !m_pfnFreeConnect ||
  64. !m_pfnFreeEnv || !m_pfnDisconnect || !m_pfnConnect || !m_pfnAllocConnect || !m_pfnAllocEnv ||
  65. !m_pfnSetConnectOption || !m_pfnTransact || !m_pfnFetch || !m_pfnStatistics || !m_pfnDescribeCol)
  66. {
  67. FreeLibrary(m_hODBC);
  68. FreeLibrary(m_hODBCCP);
  69. m_hODBC = NULL;
  70. m_hODBCCP = NULL;
  71. }
  72. }
  73. }
  74. SQL::~SQL(void)
  75. {
  76. if (m_hODBC)
  77. {
  78. FreeLibrary(m_hODBC);
  79. }
  80. if (m_hODBCCP)
  81. {
  82. FreeLibrary(m_hODBCCP);
  83. }
  84. }
  85. BOOL SQL::Initialize(void)
  86. {
  87. return (m_hODBC != NULL);
  88. }
  89. BOOL INSTAPI SQL::ConfigDataSource(HWND hwndParent, WORD fRequest,LPCTSTR lpszDriver, LPCTSTR lpszAttributes)
  90. {
  91. return m_pfnConfigDataSource(hwndParent, fRequest, lpszDriver, lpszAttributes);
  92. }
  93. SQLRETURN SQL_API SQL::SetPos( SQLHSTMT hstmt, SQLUSMALLINT irow, SQLUSMALLINT fOption, SQLUSMALLINT fLock)
  94. {
  95. return m_pfnSetPos( hstmt, irow, fOption, fLock);
  96. }
  97. SQLRETURN SQL_API SQL::ExtendedFetch( SQLHSTMT hstmt, SQLUSMALLINT fFetchType, SQLINTEGER irow, SQLUINTEGER *pcrow, SQLUSMALLINT *rgfRowStatus)
  98. {
  99. return m_pfnExtendedFetch( hstmt, fFetchType, irow, pcrow, rgfRowStatus);
  100. }
  101. SQLRETURN SQL_API SQL::FreeStmt(SQLHSTMT StatementHandle, SQLUSMALLINT Option)
  102. {
  103. return m_pfnFreeStmt(StatementHandle, Option);
  104. }
  105. SQLRETURN SQL_API SQL::ExecDirect(SQLHSTMT StatementHandle, SQLCHAR *StatementText, SQLINTEGER TextLength)
  106. {
  107. return m_pfnExecDirect(StatementHandle, StatementText, TextLength);
  108. }
  109. SQLRETURN SQL_API SQL::SetStmtOption(SQLHSTMT StatementHandle, SQLUSMALLINT Option, SQLUINTEGER Value)
  110. {
  111. return m_pfnSetStmtOption(StatementHandle, Option, Value);
  112. }
  113. SQLRETURN SQL_API SQL::BindCol(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType, SQLPOINTER TargetValue, SQLINTEGER BufferLength, SQLINTEGER *StrLen_or_Ind)
  114. {
  115. return m_pfnBindCol(StatementHandle, ColumnNumber, TargetType, TargetValue, BufferLength, StrLen_or_Ind);
  116. }
  117. SQLRETURN SQL_API SQL::Error(SQLHENV EnvironmentHandle, SQLHDBC ConnectionHandle, SQLHSTMT StatementHandle, SQLCHAR *Sqlstate, SQLINTEGER *NativeError, SQLCHAR *MessageText, SQLSMALLINT BufferLength, SQLSMALLINT *TextLength)
  118. {
  119. return m_pfnError(EnvironmentHandle, ConnectionHandle, StatementHandle, Sqlstate, NativeError, MessageText, BufferLength, TextLength);
  120. }
  121. SQLRETURN SQL_API SQL::AllocStmt(SQLHDBC ConnectionHandle, SQLHSTMT *StatementHandle)
  122. {
  123. return m_pfnAllocStmt(ConnectionHandle, StatementHandle);
  124. }
  125. SQLRETURN SQL_API SQL::FreeConnect(SQLHDBC ConnectionHandle)
  126. {
  127. return m_pfnFreeConnect(ConnectionHandle);
  128. }
  129. SQLRETURN SQL_API SQL::FreeEnv(SQLHENV EnvironmentHandle)
  130. {
  131. return m_pfnFreeEnv(EnvironmentHandle);
  132. }
  133. SQLRETURN SQL_API SQL::Disconnect(SQLHDBC ConnectionHandle)
  134. {
  135. return m_pfnDisconnect(ConnectionHandle);
  136. }
  137. SQLRETURN SQL_API SQL::Connect(SQLHDBC ConnectionHandle, SQLCHAR *ServerName, SQLSMALLINT NameLength1, SQLCHAR *UserName, SQLSMALLINT NameLength2, SQLCHAR *Authentication, SQLSMALLINT NameLength3)
  138. {
  139. return m_pfnConnect(ConnectionHandle, ServerName, NameLength1, UserName, NameLength2, Authentication, NameLength3);
  140. }
  141. SQLRETURN SQL_API SQL::AllocConnect(SQLHENV EnvironmentHandle, SQLHDBC *ConnectionHandle)
  142. {
  143. return m_pfnAllocConnect(EnvironmentHandle, ConnectionHandle);
  144. }
  145. SQLRETURN SQL_API SQL::AllocEnv(SQLHENV *EnvironmentHandle)
  146. {
  147. return m_pfnAllocEnv(EnvironmentHandle);
  148. }
  149. SQLRETURN SQL_API SQL::SetConnectOption(SQLHDBC ConnectionHandle, SQLUSMALLINT Option, SQLUINTEGER Value)
  150. {
  151. return m_pfnSetConnectOption(ConnectionHandle, Option, Value);
  152. }
  153. SQLRETURN SQL_API SQL::Transact(SQLHENV EnvironmentHandle, SQLHDBC ConnectionHandle, SQLUSMALLINT CompletionType)
  154. {
  155. return m_pfnTransact(EnvironmentHandle, ConnectionHandle, CompletionType);
  156. }
  157. SQLRETURN SQL_API SQL::Fetch(SQLHSTMT StatementHandle)
  158. {
  159. return m_pfnFetch(StatementHandle);
  160. }
  161. SQLRETURN SQL_API SQL::Statistics(SQLHSTMT StatementHandle, SQLCHAR *CatalogName, SQLSMALLINT NameLength1, SQLCHAR *SchemaName, SQLSMALLINT NameLength2, SQLCHAR *TableName, SQLSMALLINT NameLength3, SQLUSMALLINT Unique, SQLUSMALLINT Reserved)
  162. {
  163. return m_pfnStatistics(StatementHandle, CatalogName, NameLength1, SchemaName, NameLength2, TableName, NameLength3, Unique, Reserved);
  164. }
  165. SQLRETURN SQL_API SQL::DescribeCol(SQLHSTMT StatementHandle, SQLSMALLINT ColumnNumber, SQLCHAR * ColumnName, SQLSMALLINT BufferLength, SQLSMALLINT * NameLengthPtr, SQLSMALLINT * DataTypePtr, SQLUINTEGER * ColumnSizePtr, SQLSMALLINT * DecimalDigitsPtr, SQLSMALLINT * NullablePtr)
  166. {
  167. return m_pfnDescribeCol(StatementHandle, ColumnNumber, ColumnName, BufferLength, NameLengthPtr, DataTypePtr, ColumnSizePtr, DecimalDigitsPtr, NullablePtr);
  168. }