src/dbapi/driver/odbc/odbc_utils.hpp

Go to the documentation of this file.
00001 #ifndef DBAPI_DRIVER_DBLIB___DBAPI_DRIVER_ODBC_UTILS__HPP
00002 #define DBAPI_DRIVER_DBLIB___DBAPI_DRIVER_ODBC_UTILS__HPP
00003 
00004 /* $Id: odbc_utils.hpp 169152 2009-08-26 16:47:29Z ivanovp $
00005  * ===========================================================================
00006  *
00007  *                            PUBLIC DOMAIN NOTICE
00008  *               National Center for Biotechnology Information
00009  *
00010  *  This software/database is a "United States Government Work" under the
00011  *  terms of the United States Copyright Act.  It was written as part of
00012  *  the author's official duties as a United States Government employee and
00013  *  thus cannot be copyrighted.  This software/database is freely available
00014  *  to the public for use. The National Library of Medicine and the U.S.
00015  *  Government have not placed any restriction on its use or reproduction.
00016  *
00017  *  Although all reasonable efforts have been taken to ensure the accuracy
00018  *  and reliability of the software and data, the NLM and the U.S.
00019  *  Government do not and cannot warrant the performance or results that
00020  *  may be obtained by using this software or data. The NLM and the U.S.
00021  *  Government disclaim all warranties, express or implied, including
00022  *  warranties of performance, merchantability or fitness for any particular
00023  *  purpose.
00024  *
00025  *  Please cite the author in any work or product based on this material.
00026  *
00027  * ===========================================================================
00028  *
00029  * Author:  Sergey Sikorskiy
00030  *
00031  * File Description:  Small utility classes common to the odbc driver.
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     // Seconnd parameter is redundant and will be ignored,
00062     // but we need it as syntactical sugar.
00063     explicit CODBCString(SQLWCHAR* str,
00064                          EEncoding enc = eEncoding_Unknown);
00065     // Seconnd parameter is redundant and will be ignored,
00066     // but we need it as syntactical sugar.
00067     explicit CODBCString(const wchar_t* str,
00068                          wstring::size_type size = wstring::npos,
00069                          EEncoding enc = eEncoding_Unknown);
00070     // Seconnd parameter is redundant and will be ignored,
00071     // but we need it as syntactical sugar.
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 } // extern C
00183 
00184 
00185 END_NCBI_SCOPE
00186 
00187 
00188 #endif // DBAPI_DRIVER_DBLIB___DBAPI_DRIVER_ODBC_UTILS__HPP
00189 
00190 
00191 
00192 

Generated on Sun Dec 6 22:23:22 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:20:59 2009 by modify_doxy.py rev. 173732