NCBI C++ ToolKit
odbc_utils.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef DBAPI_DRIVER_ODBC___DBAPI_DRIVER_ODBC_UTILS__HPP
2 #define DBAPI_DRIVER_ODBC___DBAPI_DRIVER_ODBC_UTILS__HPP
3 
4 /* $Id: odbc_utils.hpp 81003 2018-01-29 14:12:00Z ucko $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Sergey Sikorskiy
30  *
31  * File Description: Small utility classes common to the odbc driver.
32  *
33  */
34 
37 
39 
40 /////////////////////////////////////////////////////////////////////////////
41 class CODBCString : public CWString
42 {
43 public:
44  explicit CODBCString(SQLCHAR* str,
46  explicit CODBCString(SQLCHAR* str,
49  explicit CODBCString(const char* str,
50  string::size_type size = string::npos,
52  explicit CODBCString(const string& str, EEncoding enc = eEncoding_Unknown);
53 #ifdef HAVE_WSTRING
54  // Seconnd parameter is redundant and will be ignored,
55  // but we need it as syntactical sugar.
56  explicit CODBCString(SQLWCHAR* str,
58  // Seconnd parameter is redundant and will be ignored,
59  // but we need it as syntactical sugar.
60  explicit CODBCString(const wchar_t* str,
61  wstring::size_type size = wstring::npos,
63  // Seconnd parameter is redundant and will be ignored,
64  // but we need it as syntactical sugar.
65  explicit CODBCString(const wstring& str,
67 #endif
68  ~CODBCString(void);
69 
70 public:
71  operator LPCSTR(void) const
72  {
73  if (!(GetAvailableValueType() & eChar)) {
74  x_MakeString();
75  }
76 
77  return reinterpret_cast<LPCSTR>(m_Char);
78  }
79  operator SQLCHAR*(void) const
80  {
81  if (!(GetAvailableValueType() & eChar)) {
82  x_MakeString();
83  }
84 
85  return const_cast<SQLCHAR*>(reinterpret_cast<const SQLCHAR*>(m_Char));
86  }
87  operator const SQLCHAR*(void) const
88  {
89  if (!(GetAvailableValueType() & eChar)) {
90  x_MakeString();
91  }
92 
93  return reinterpret_cast<const SQLCHAR*>(m_Char);
94  }
95 };
96 
97 /////////////////////////////////////////////////////////////////////////////
98 #if defined(UNICODE)
99 # define _T_NCBI_ODBC(x) L ## x
100 #else
101 # define _T_NCBI_ODBC(x) x
102 #endif
103 
104 using odbc::TSqlChar;
106 inline
108 {
109 #if defined(UNICODE) || defined(_UNICODE) || defined(UCS2)
110  return CUtf8::AsBasicString<TSqlChar>(CUtf8::AsUTF8(s, enc));
111 #else
112  if (enc == eEncoding_Unknown || enc == eEncoding_UTF8) {
115  } else {
116  return CSqlString(s.data(), s.size());
117  }
118 #endif
119 }
120 
121 
122 #ifdef HAVE_WSTRING
123 inline
124 wstring operator+(const wstring& str1, const string& str2)
125 {
126  return str1 + CUtf8::AsBasicString<wchar_t>( CUtf8::AsUTF8(str2, eEncoding_ISO8859_1));
127 }
128 #endif
129 
130 namespace util
131 {
132  inline
133  int strncmp(const char* str1, const char* str2, size_t count)
134  {
135  return ::strncmp(str1, str2, count);
136  }
137 
138 #ifdef HAVE_WSTRING
139  inline
140  int strncmp(const wchar_t* str1, const wchar_t* str2, size_t count)
141  {
142  return ::wcsncmp(str1, str2, count);
143  }
144 #endif
145 
146  inline
147  int strncmp(const SQLCHAR* str1, const char* str2, size_t count)
148  {
149  return strncmp((const char*)str1, str2, count);
150  }
151 
152  inline
153  int strncmp(const char* str1, const SQLCHAR* str2, size_t count)
154  {
155  return strncmp(str1, (const char*)str2, count);
156  }
157 
158  ///////////////////////////////////////////////////////////////////////////
159  inline
160  int strcmp(const char* str1, const char* str2)
161  {
162  return ::strcmp(str1, str2);
163  }
164 
165 #ifdef HAVE_WSTRING
166  inline
167  int strcmp(const wchar_t* str1, const wchar_t* str2)
168  {
169  return ::wcscmp(str1, str2);
170  }
171 #endif
172 
173 }
174 
175 
176 extern "C"
177 {
178 
180 void
184 
185 } // extern C
186 
187 
189 
190 
191 #endif // DBAPI_DRIVER_ODBC___DBAPI_DRIVER_ODBC_UTILS__HPP
192 
193 
Convenience extension of basic_string, supporting implicit conversion to const TChar* in most situati...
Definition: types.hpp:99
~CODBCString(void)
Definition: odbc_utils.cpp:95
CODBCString(SQLCHAR *str, EEncoding enc=eEncoding_Unknown)
Definition: odbc_utils.cpp:40
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
SQLCHAR TSqlChar
Definition: interfaces.hpp:76
const char * LPCSTR
Definition: sqlfront.h:39
const char * m_Char
Definition: types.hpp:277
CGenericSqlString< char > CSqlString
Definition: types.hpp:119
void x_MakeString(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.cpp:276
int GetAvailableValueType(void) const
Definition: types.hpp:249
@ eChar
Definition: types.hpp:267
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
EEncoding
Definition: ncbistr.hpp:199
static string AsSingleByteString(const CTempString &src, EEncoding encoding, const char *substitute_on_error=0, EValidate validate=eNoValidate)
Convert UTF8 string into a single-byte character representation.
Definition: ncbistr.cpp:6979
const char * data(void) const
Return a pointer to the array represented.
Definition: tempstr.hpp:313
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3889
size_type size(void) const
Return the length of the represented array.
Definition: tempstr.hpp:327
@ eEncoding_ISO8859_1
Note: From the point of view of the C++.
Definition: ncbistr.hpp:203
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
@ eEncoding_Unknown
Definition: ncbistr.hpp:200
#define NCBI_DBAPIDRIVER_ODBC_EXPORT
Definition: ncbi_export.h:416
const struct ncbi::grid::netcache::search::fields::SIZE size
int strncmp(const char *str1, const SQLCHAR *str2, size_t count)
Definition: odbc_utils.hpp:153
int strncmp(const char *str1, const char *str2, size_t count)
Definition: odbc_utils.hpp:133
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
int strcmp(const wchar_t *str1, const wchar_t *str2)
Definition: odbc_utils.hpp:167
void NCBI_EntryPoint_xdbapi_odbc(CPluginManager< I_DriverContext >::TDriverInfoList &info_list, CPluginManager< I_DriverContext >::EEntryPointRequest method)
Definition: context.cpp:595
TSqlString x_MakeTSqlString(const CTempString &s, EEncoding enc)
Definition: odbc_utils.hpp:107
wstring operator+(const wstring &str1, const string &str2)
Definition: odbc_utils.hpp:124
CGenericSqlString< TSqlChar > TSqlString
Definition: odbc_utils.hpp:105
WCHAR SQLWCHAR
Definition: sqltypes.h:458
long SQLINTEGER
Definition: sqltypes.h:176
unsigned char SQLCHAR
Definition: sqltypes.h:125
static const char * str(char *buf, int n)
Definition: stats.c:84
Modified on Thu Mar 28 17:09:48 2024 by modify_doxy.py rev. 669887