00001 #ifndef DBAPI_DRIVER_DBLIB___DBAPI_DRIVER_ODBC_UTILS__HPP
00002 #define DBAPI_DRIVER_DBLIB___DBAPI_DRIVER_ODBC_UTILS__HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <dbapi/driver/impl/dbapi_driver_utils.hpp>
00036
00037 #ifdef NCBI_OS_MSWIN
00038 #include <windows.h>
00039 #endif
00040
00041 #include <sql.h>
00042 #include <sqlext.h>
00043 #include <sqltypes.h>
00044
00045 BEGIN_NCBI_SCOPE
00046
00047
00048 class CODBCString : public CWString
00049 {
00050 public:
00051 explicit CODBCString(SQLCHAR* str,
00052 EEncoding enc = eEncoding_Unknown);
00053 explicit CODBCString(SQLCHAR* str,
00054 SQLINTEGER size,
00055 EEncoding enc = eEncoding_Unknown);
00056 explicit CODBCString(const char* str,
00057 string::size_type size = string::npos,
00058 EEncoding enc = eEncoding_Unknown);
00059 explicit CODBCString(const string& str, EEncoding enc = eEncoding_Unknown);
00060 #ifdef HAVE_WSTRING
00061
00062
00063 explicit CODBCString(SQLWCHAR* str,
00064 EEncoding enc = eEncoding_Unknown);
00065
00066
00067 explicit CODBCString(const wchar_t* str,
00068 wstring::size_type size = wstring::npos,
00069 EEncoding enc = eEncoding_Unknown);
00070
00071
00072 explicit CODBCString(const wstring& str,
00073 EEncoding enc = eEncoding_Unknown);
00074 #endif
00075 ~CODBCString(void);
00076
00077 public:
00078 operator LPCSTR(void) const
00079 {
00080 if (!(GetAvailableValueType() & eChar)) {
00081 x_MakeString();
00082 }
00083
00084 return reinterpret_cast<LPCSTR>(m_Char);
00085 }
00086 operator SQLCHAR*(void) const
00087 {
00088 if (!(GetAvailableValueType() & eChar)) {
00089 x_MakeString();
00090 }
00091
00092 return const_cast<SQLCHAR*>(reinterpret_cast<const SQLCHAR*>(m_Char));
00093 }
00094 operator const SQLCHAR*(void) const
00095 {
00096 if (!(GetAvailableValueType() & eChar)) {
00097 x_MakeString();
00098 }
00099
00100 return reinterpret_cast<const SQLCHAR*>(m_Char);
00101 }
00102 };
00103
00104
00105 #if defined(UNICODE)
00106 #ifndef __T
00107 # define __T(x) L ## x
00108 #endif
00109 #else
00110 #ifndef __T
00111 # define __T(x) x
00112 #endif
00113 #endif
00114
00115 #ifndef _T
00116 # define _T(x) __T(x)
00117 #endif
00118
00119 #ifdef HAVE_WSTRING
00120 inline
00121 wstring operator+(const wstring& str1, const string& str2)
00122 {
00123 return str1 + CStringUTF8(str2).AsUnicode();
00124 }
00125 #endif
00126
00127 namespace util
00128 {
00129 inline
00130 int strncmp(const char* str1, const char* str2, size_t count)
00131 {
00132 return ::strncmp(str1, str2, count);
00133 }
00134
00135 #ifdef HAVE_WSTRING
00136 inline
00137 int strncmp(const wchar_t* str1, const wchar_t* str2, size_t count)
00138 {
00139 return ::wcsncmp(str1, str2, count);
00140 }
00141 #endif
00142
00143 inline
00144 int strncmp(const SQLCHAR* str1, const char* str2, size_t count)
00145 {
00146 return strncmp((const char*)str1, str2, count);
00147 }
00148
00149 inline
00150 int strncmp(const char* str1, const SQLCHAR* str2, size_t count)
00151 {
00152 return strncmp(str1, (const char*)str2, count);
00153 }
00154
00155
00156 inline
00157 int strcmp(const char* str1, const char* str2)
00158 {
00159 return ::strcmp(str1, str2);
00160 }
00161
00162 #ifdef HAVE_WSTRING
00163 inline
00164 int strcmp(const wchar_t* str1, const wchar_t* str2)
00165 {
00166 return ::wcscmp(str1, str2);
00167 }
00168 #endif
00169
00170 }
00171
00172
00173 extern "C"
00174 {
00175
00176
00177 void
00178 NCBI_EntryPoint_xdbapi_odbc(
00179 CPluginManager<I_DriverContext>::TDriverInfoList& info_list,
00180 CPluginManager<I_DriverContext>::EEntryPointRequest method);
00181
00182 }
00183
00184
00185 END_NCBI_SCOPE
00186
00187
00188 #endif // DBAPI_DRIVER_DBLIB___DBAPI_DRIVER_ODBC_UTILS__HPP
00189
00190
00191
00192