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

Go to the SVN repository for this file.

1 #ifndef DBAPI_DRIVER___TYPES__HPP
2 #define DBAPI_DRIVER___TYPES__HPP
3 
4 /* $Id: types.hpp 95716 2021-12-13 20:24:33Z 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: Vladimir Soussov
30  *
31  * File Description: DB types
32  *
33  */
34 
35 
36 #include <corelib/ncbitime.hpp>
37 #include <corelib/ncbi_param.hpp>
38 
39 
40 /** @addtogroup DbTypes
41  *
42  * @{
43  */
44 
45 
47 
48 
49 // Set of supported types
50 //
51 
52 enum EDB_Type {
74 
76 };
77 
78 enum EBlobType {
82 };
83 
84 
85 enum EBulkEnc {
86  eBulkEnc_RawBytes, // Raw bytes, perhaps already encoded in UCS-2.
87  eBulkEnc_RawUCS2, // Directly specified UCS-2, for nvarchar or ntext.
88  eBulkEnc_UCS2FromChar // Character data to be reencoded as UCS-2.
89 };
90 
91 
92 /////////////////////////////////////////////////////////////////////////////
93 
94 /// Convenience extension of basic_string, supporting implicit
95 /// conversion to const TChar* in most situations (but alas not within
96 /// variadic argument lists, as for printf and the like).
97 template <typename TChar>
98 class CGenericSqlString : public basic_string<TChar>
99 {
100 public:
101  typedef basic_string<TChar> TBasicString;
102  typedef typename TBasicString::size_type size_type;
104 
109  : TBasicString(data, len) { }
110 
111  size_type byte_count(void) const
112  { return this->size() * sizeof(value_type); }
113 
115  operator const value_type*(void) const;
116  // { return this->c_str(); } // defined out-of-line to reduce warnings
117 };
118 
120 #ifdef HAVE_WSTRING
122 #endif
123 
124 
125 /////////////////////////////////////////////////////////////////////////////
127 {
128 public:
129  CWString(void);
130  CWString(const CWString& str);
131 
132  explicit CWString(const char* str,
133  string::size_type size = string::npos,
135  explicit CWString(const string& str,
137 #ifdef HAVE_WSTRING
138  explicit CWString(const wchar_t* str,
139  wstring::size_type size = wstring::npos);
140  explicit CWString(const wstring& str);
141 #endif
142 
143  ~CWString(void);
144 
145  CWString& operator=(const CWString& str);
146 
147 public:
148  operator const CSqlString&(void) const
149  {
150  if (!(GetAvailableValueType() & eString)) {
151  x_MakeString();
152  }
153 
154  return m_String;
155  }
156  NCBI_DEPRECATED operator char*(void) const;
157  NCBI_DEPRECATED operator const char*(void) const;
158  const char* AsCString(EEncoding str_enc = eEncoding_Unknown) const
159  {
160  if (!(GetAvailableValueType() & eChar)) {
161  x_MakeString(str_enc);
162  }
163 
164  return m_Char;
165  }
166 #ifdef HAVE_WSTRING
167  operator const wstring&(void) const
168  {
169  if (!(GetAvailableValueType() & eWString)) {
170  x_MakeWString();
171  }
172 
173  return m_WString;
174  }
175  NCBI_DEPRECATED operator wchar_t*(void) const;
176  NCBI_DEPRECATED operator const wchar_t*(void) const;
177  const wchar_t* AsCWString(EEncoding str_enc = eEncoding_Unknown) const
178  {
179  if (!(GetAvailableValueType() & eWChar)) {
180  x_MakeWString(str_enc);
181  }
182 
183  return m_WChar;
184  }
185 #endif
186 
187 public:
188  // str_enc - expected string encoding.
189  const string& AsLatin1(EEncoding str_enc = eEncoding_Unknown) const
190  {
191  if (!(GetAvailableValueType() & eString)) {
192  x_MakeString(str_enc);
193  }
194 
195  return m_String;
196  }
197  const string& AsUTF8(EEncoding str_enc = eEncoding_Unknown) const
198  {
199  if (!(GetAvailableValueType() & eUTF8String)) {
200  x_MakeUTF8String(str_enc);
201  }
202 
203  return m_UTF8String;
204  }
206  {
207  if (!(GetAvailableValueType() & eUCS2LEString)) {
208  x_MakeUCS2LEString(str_enc);
209  }
210 
211  return m_UCS2LEString;
212  }
213 #ifdef HAVE_WSTRING
214  const wstring& AsUnicode(EEncoding str_enc = eEncoding_Unknown) const
215  {
216  if (!(GetAvailableValueType() & eWString)) {
217  x_MakeWString(str_enc);
218  }
219 
220  return m_WString;
221  }
222 #endif
223  const string& ConvertTo(EEncoding to_enc,
224  EEncoding from_enc = eEncoding_Unknown) const
225  {
226  if (to_enc == eEncoding_UTF8) {
227  return AsUTF8(from_enc);
228  }
229 
230  return AsLatin1(from_enc);
231  }
232 
233  size_t GetSymbolNum(void) const;
234 
235 public:
236  void Clear(void);
237  void Assign(const char* str,
238  string::size_type size = string::npos,
240  void Assign(const string& str,
242 #ifdef HAVE_WSTRING
243  void Assign(const wchar_t* str,
244  wstring::size_type size = wstring::npos);
245  void Assign(const wstring& str);
246 #endif
247 
248 protected:
249  int GetAvailableValueType(void) const
250  {
251  return m_AvailableValueType;
252  }
253 
254  void x_MakeString(EEncoding str_enc = eEncoding_Unknown) const;
255 #ifdef HAVE_WSTRING
256  void x_MakeWString(EEncoding str_enc = eEncoding_Unknown) const;
257 #endif
258  void x_MakeUTF8String(EEncoding str_enc = eEncoding_Unknown) const;
259  void x_MakeUCS2LEString(EEncoding str_enc = eEncoding_Unknown) const;
260 
261  void x_CalculateEncoding(EEncoding str_enc) const;
262  void x_UTF8ToString(EEncoding str_enc = eEncoding_Unknown) const;
263  void x_StringToUTF8(EEncoding str_enc = eEncoding_Unknown) const;
264 
265 protected:
266  enum {
267  eChar = 0x1,
268  eWChar = 0x2,
269  eString = 0x4,
270  eWString = 0x8,
271  eUTF8String = 0x10,
272  eUCS2LEString = 0x20
273  };
274 
275  mutable int m_AvailableValueType;
276  mutable EEncoding m_StringEncoding; // Source string encoding.
277  mutable const char* m_Char;
278 #ifdef HAVE_WSTRING
279  mutable const wchar_t* m_WChar;
280 #endif
282 #ifdef HAVE_WSTRING
283  mutable wstring m_WString;
284 #endif
287 };
288 
289 /////////////////////////////////////////////////////////////////////////////
290 //
291 // CDB_Object::
292 //
293 // Base class for all "type objects" to support database NULL value
294 // and provide the means to get the type and to clone the object.
295 //
296 
298 {
299 public:
300  CDB_Object(bool is_null = true);
301  virtual ~CDB_Object();
302 
303  bool IsNULL() const { return m_Null; }
304  virtual void AssignNULL();
305 
306  virtual EDB_Type GetType() const = 0;
307  virtual CDB_Object* Clone() const = 0;
308  virtual CDB_Object* ShallowClone() const { return Clone(); }
309  virtual void AssignValue(const CDB_Object& v) = 0;
310 
311  // Create and return a new object (with internal value NULL) of type "type".
312  // NOTE: "size" matters only for eDB_Char, eDB_Binary, eDB_LongChar, eDB_LongBinary.
313  static CDB_Object* Create(EDB_Type type, size_t size = 1);
314 
315  // Get human-readable type name for db_type
316  static const char* GetTypeName(EDB_Type db_type,
317  bool throw_on_unknown = true);
318 
319  static EBlobType GetBlobType(EDB_Type db_type);
320  static bool IsBlobType (EDB_Type db_type)
321  { return GetBlobType(db_type) != eBlobType_none; }
322 
323  string GetLogString(void) const;
324 
325 protected:
326  void SetNULL(bool flag = true) { m_Null = flag; }
327 
328 private:
329  bool m_Null;
330 };
331 
332 
333 
334 /////////////////////////////////////////////////////////////////////////////
335 //
336 // CDB_Int::
337 // CDB_SmallInt::
338 // CDB_TinyInt::
339 // CDB_BigInt::
340 // CDB_VarChar::
341 // CDB_Char::
342 // CDB_VarBinary::
343 // CDB_Binary::
344 // CDB_Float::
345 // CDB_Double::
346 // CDB_Stream::
347 // CDB_Image::
348 // CDB_Text::
349 // CDB_SmallDateTime::
350 // CDB_DateTime::
351 // CDB_BigDateTime::
352 // CDB_Bit::
353 // CDB_Numeric::
354 //
355 // Classes to represent objects of different types (derived from CDB_Object::)
356 //
357 
358 
359 /////////////////////////////////////////////////////////////////////////////
361 {
362 public:
363  CDB_Int();
364  CDB_Int(const Int4& i);
365  virtual ~CDB_Int(void);
366 
368  SetNULL(false);
369  m_Val = i;
370  return *this;
371  }
372 
373  Int4 Value() const { return IsNULL() ? 0 : m_Val; }
374  void* BindVal() const { return (void*) &m_Val; }
375 
376  virtual EDB_Type GetType() const;
377  virtual CDB_Object* Clone() const;
378  virtual void AssignValue(const CDB_Object& v);
379 
380 protected:
382 };
383 
384 
385 
386 /////////////////////////////////////////////////////////////////////////////
388 {
389 public:
390  CDB_SmallInt();
391  CDB_SmallInt(const Int2& i);
392  virtual ~CDB_SmallInt(void);
393 
395  SetNULL(false);
396  m_Val = i;
397  return *this;
398  }
399 
400  Int2 Value() const { return IsNULL() ? 0 : m_Val; }
401  void* BindVal() const { return (void*) &m_Val; }
402 
403  virtual EDB_Type GetType() const;
404  virtual CDB_Object* Clone() const;
405  virtual void AssignValue(const CDB_Object& v);
406 
407 protected:
409 };
410 
411 
412 
413 /////////////////////////////////////////////////////////////////////////////
415 {
416 public:
417  CDB_TinyInt();
418  CDB_TinyInt(const Uint1& i);
419  virtual ~CDB_TinyInt(void);
420 
422  SetNULL(false);
423  m_Val = i;
424  return *this;
425  }
426 
427  Uint1 Value() const { return IsNULL() ? 0 : m_Val; }
428  void* BindVal() const { return (void*) &m_Val; }
429 
430  virtual EDB_Type GetType() const;
431  virtual CDB_Object* Clone() const;
432  virtual void AssignValue(const CDB_Object& v);
433 
434 protected:
436 };
437 
438 
439 
440 /////////////////////////////////////////////////////////////////////////////
442 {
443 public:
444  CDB_BigInt();
445  CDB_BigInt(const Int8& i);
446  virtual ~CDB_BigInt(void);
447 
449  SetNULL(false);
450  m_Val = i;
451  return *this;
452  }
453 
454  Int8 Value() const { return IsNULL() ? 0 : m_Val; }
455  void* BindVal() const { return (void*) &m_Val; }
456 
457 
458  virtual EDB_Type GetType() const;
459  virtual CDB_Object* Clone() const;
460  virtual void AssignValue(const CDB_Object& v);
461 
462 protected:
464 };
465 
466 
467 /////////////////////////////////////////////////////////////////////////////
469 {
470 public:
471  CDB_String(void);
472  CDB_String(const CDB_String& other, bool share_data = false);
473  explicit CDB_String(const string& s,
475  explicit CDB_String(const char* s,
476  string::size_type size = string::npos,
478  explicit CDB_String(const string& s,
479  string::size_type size = string::npos,
481  explicit CDB_String(const TStringUCS2& s,
482  TStringUCS2::size_type size = TStringUCS2::npos);
483  // Accepting const TCharUCS2* in addition to const char* leads to
484  // ambiguity errors when passed NULL.
485  // explicit CDB_String(const TCharUCS2* s,
486  // string::size_type size = TStringUCS2::npos);
487  virtual ~CDB_String(void);
488 
489 public:
490  // Assignment operators
491  CDB_String& operator= (const CDB_String& other);
492  CDB_String& operator= (const string& s);
493  CDB_String& operator= (const char* s);
494  CDB_String& operator= (const TStringUCS2& s);
495  // CDB_String& operator= (const TCharUCS2* s);
496 
497 public:
498  // Conversion operators
499  NCBI_DEPRECATED operator const char*(void) const;
500 
501  operator const string&(void) const
502  {
503  return *m_WString;
504  }
505 
506 public:
507 #if defined(HAVE_WSTRING)
508  // enc - expected source string encoding.
509  const wstring& AsWString(EEncoding enc) const
510  {
511  return IsNULL() ? kEmptyWStr : m_WString->AsUnicode(enc);
512  }
513 
514  NCBI_DEPRECATED const wchar_t* AsUnicode(EEncoding enc) const;
515 #endif
516 
517  const string& AsString(void) const
518  {
519  return IsNULL() ? kEmptyStr : x_GetWString();
520  }
521 
522  size_t Size(void) const
523  {
524  return IsNULL() ? 0 : m_WString->GetSymbolNum();
525  }
526 
527  const char* Data(void) const
528  {
529  return IsNULL() ? NULL : x_GetWString().data();
530  }
531 
532  const char* AsCString(void) const
533  {
534  return IsNULL() ? NULL : x_GetWString().c_str();
535  }
536 
537  const char* Value(void) const { return AsCString(); }
538 
539 public:
540  // set-value methods
541  void Assign(const CDB_String& other);
542  void Assign(const char* s,
543  string::size_type size = string::npos,
545  void Assign(const string& s,
546  string::size_type size = string::npos,
548  // void Assign(const TCharUCS2* s,
549  // TStringUCS2::size_type size = TStringUCS2::npos);
550  void Assign(const TStringUCS2& s,
551  TStringUCS2::size_type size = TStringUCS2::npos);
552 
553  // Simplify bulk insertion into NVARCHAR columns, which require
554  // explicit handling.
555  EBulkEnc GetBulkInsertionEnc(void) const { return m_BulkInsertionEnc; }
556  void SetBulkInsertionEnc(EBulkEnc e) { m_BulkInsertionEnc = e; }
557  void GetBulkInsertionData(CTempString* ts,
558  bool convert_raw_bytes = false) const;
559 
560 private:
563 
564  // Avoid explicit static_cast<const string&>(m_WString) constructs,
565  // which trigger internal errors under ICC 12.
566  const string& x_GetWString() const { return *m_WString; }
567 };
568 
569 
570 /////////////////////////////////////////////////////////////////////////////
572 {
573 public:
574  CDB_VarChar(void);
575  CDB_VarChar(const CDB_VarChar& v, bool share_data = false);
576  CDB_VarChar(const string& s,
578  CDB_VarChar(const char* s,
580  CDB_VarChar(const char* s,
581  size_t l,
583  CDB_VarChar(const TStringUCS2& s, size_t l = TStringUCS2::npos);
584  // CDB_VarChar(const TCharUCS2* s, size_t l);
585  virtual ~CDB_VarChar(void);
586 
587 public:
588  // assignment operators
589  CDB_VarChar& operator= (const string& s) { return SetValue(s); }
590  CDB_VarChar& operator= (const char* s) { return SetValue(s); }
591  CDB_VarChar& operator= (const TStringUCS2& s) { return SetValue(s); }
592  // CDB_VarChar& operator= (const TCharUCS2* s) { return SetValue(s); }
593 
594 public:
595  // set-value methods
596  CDB_VarChar& SetValue(const string& s,
598  CDB_VarChar& SetValue(const char* s,
600  CDB_VarChar& SetValue(const char* s, size_t l,
602  CDB_VarChar& SetValue(const TStringUCS2& s);
603  // CDB_VarChar& SetValue(const TCharUCS2* s, size_t l);
604 
605 public:
606  virtual EDB_Type GetType() const;
607  virtual CDB_Object* Clone() const;
608  virtual CDB_Object* ShallowClone() const;
609  virtual void AssignValue(const CDB_Object& v);
610 };
611 
612 /////////////////////////////////////////////////////////////////////////////
614 {
615 public:
616  CDB_Char(size_t s = 1);
617  CDB_Char(size_t s,
618  const string& v,
620  // This ctor copies a string.
621  CDB_Char(size_t s,
622  const char* str,
624  CDB_Char(size_t s, const TStringUCS2& v);
625  // CDB_Char(size_t s, const TCharUCS2* str);
626  CDB_Char(const CDB_Char& v, bool share_data = false);
627  virtual ~CDB_Char(void);
628 
629 public:
630  CDB_Char& operator= (const CDB_Char& v);
631  CDB_Char& operator= (const string& v);
632  // This operator copies a string.
633  CDB_Char& operator= (const char* v);
634  CDB_Char& operator= (const TStringUCS2& v);
635  // CDB_Char& operator= (const TCharUCS2* v);
636 
637 public:
638  // This method copies a string.
639  void SetValue(const char* str,
640  size_t len,
642  void SetValue(const TStringUCS2& v, size_t len);
643  // void SetValue(const TCharUCS2* v, size_t len);
644 
645 public:
646  virtual EDB_Type GetType() const;
647  virtual CDB_Object* Clone() const;
648  virtual CDB_Object* ShallowClone() const;
649 
650  virtual void AssignValue(const CDB_Object& v);
651 
652 protected:
653  size_t m_Size; // Number of characters (not bytes)
654 };
655 
656 
657 /////////////////////////////////////////////////////////////////////////////
658 #define K8_1 8191
659 
661 {
662 public:
663 
664  CDB_LongChar(size_t s = K8_1);
665  CDB_LongChar(size_t s,
666  const string& v,
668  // This ctor copies a string.
669  CDB_LongChar(size_t len,
670  const char* str,
672  CDB_LongChar(size_t s, const TStringUCS2& v);
673  // CDB_LongChar(size_t len, const TCharUCS2* str);
674  CDB_LongChar(const CDB_LongChar& v, bool share_data = false);
675  virtual ~CDB_LongChar();
676 
677 public:
679  CDB_LongChar& operator= (const string& v);
680  // This operator copies a string.
681  CDB_LongChar& operator= (const char* v);
683  // CDB_LongChar& operator= (const TCharUCS2* v);
684 
685  // This method copies a string.
686  void SetValue(const char* str,
687  size_t len,
689  void SetValue(const TStringUCS2& str, size_t len);
690  // void SetValue(const TCharUCS2* str, size_t len);
691 
692  //
693  size_t Size() const { return IsNULL() ? 0 : m_Size; }
694  size_t DataSize() const { return CDB_String::Size(); }
695 
696  virtual EDB_Type GetType() const;
697  virtual CDB_Object* Clone() const;
698  virtual CDB_Object* ShallowClone() const;
699 
700  virtual void AssignValue(const CDB_Object& v);
701 
702 protected:
703  size_t m_Size; // Number of characters (not bytes)
704 };
705 
706 
707 
708 /////////////////////////////////////////////////////////////////////////////
710 {
711 public:
712  CDB_VarBinary();
713  CDB_VarBinary(const CDB_VarBinary& v, bool share_data = false);
714  CDB_VarBinary(const void* v, size_t l);
715  virtual ~CDB_VarBinary(void);
716 
717 public:
718  void SetValue(const void* v, size_t l);
719 
721 
722  //
723  const void* Value() const
724  { return IsNULL() ? NULL : (void*) m_Value->GetData().data(); }
725  const void* Data() const { return Value(); }
726  size_t Size() const
727  { return IsNULL() ? 0 : m_Value->GetData().size(); }
728 
729  virtual EDB_Type GetType() const;
730  virtual CDB_Object* Clone() const;
731  virtual CDB_Object* ShallowClone() const;
732  virtual void AssignValue(const CDB_Object& v);
733 
734 protected:
737 };
738 
739 
740 
741 /////////////////////////////////////////////////////////////////////////////
743 {
744 public:
745  CDB_Binary(size_t s = 1);
746  CDB_Binary(size_t s, const void* v, size_t v_size);
747  CDB_Binary(const CDB_Binary& v, bool share_data = false);
748  virtual ~CDB_Binary();
749 
750 public:
751  void SetValue(const void* v, size_t v_size);
752 
753  CDB_Binary& operator= (const CDB_Binary& v);
754 
755  //
756  const void* Value() const
757  { return IsNULL() ? NULL : (void*) m_Value->GetData().data(); }
758  const void* Data() const { return Value(); }
759  size_t Size() const
760  { return IsNULL() ? 0 : m_Value->GetData().size(); }
761 
762  virtual EDB_Type GetType() const;
763  virtual CDB_Object* Clone() const;
764  virtual CDB_Object* ShallowClone() const;
765 
766  virtual void AssignValue(const CDB_Object& v);
767 
768 protected:
770 
771  size_t m_Size;
773 };
774 
775 
776 /////////////////////////////////////////////////////////////////////////////
778 {
779 public:
780 
781  CDB_LongBinary(size_t s = K8_1);
782  CDB_LongBinary(size_t s, const void* v, size_t v_size);
783  CDB_LongBinary(const CDB_LongBinary& v, bool share_data = false);
784  virtual ~CDB_LongBinary();
785 
786 public:
787  void SetValue(const void* v, size_t v_size);
788 
790 
791  //
792  const void* Value() const
793  { return IsNULL() ? NULL : (void*) m_Value->GetData().data(); }
794  const void* Data() const { return Value(); }
795  size_t Size() const
796  { return IsNULL() ? 0 : m_Value->GetData().size(); }
797  size_t DataSize() const { return m_DataSize; }
798 
799  virtual EDB_Type GetType() const;
800  virtual CDB_Object* Clone() const;
801  virtual CDB_Object* ShallowClone() const;
802 
803  virtual void AssignValue(const CDB_Object& v);
804 
805 protected:
807 
808  size_t m_Size;
809  size_t m_DataSize;
811 };
812 
813 
814 /////////////////////////////////////////////////////////////////////////////
816 {
817 public:
818  CDB_Float();
819  CDB_Float(float i);
820  virtual ~CDB_Float(void);
821 
822  CDB_Float& operator= (const float& i);
823 public:
824 
825  float Value() const { return IsNULL() ? 0 : m_Val; }
826  void* BindVal() const { return (void*) &m_Val; }
827 
828  virtual EDB_Type GetType() const;
829  virtual CDB_Object* Clone() const;
830  virtual void AssignValue(const CDB_Object& v);
831 
832 protected:
833  float m_Val;
834 };
835 
836 
837 
838 /////////////////////////////////////////////////////////////////////////////
840 {
841 public:
842  CDB_Double();
843  CDB_Double(double i);
844  virtual ~CDB_Double(void);
845 
846 public:
847  CDB_Double& operator= (const double& i);
848 
849  //
850  double Value() const { return IsNULL() ? 0 : m_Val; }
851  void* BindVal() const { return (void*) &m_Val; }
852 
853  virtual EDB_Type GetType() const;
854  virtual CDB_Object* Clone() const;
855  virtual void AssignValue(const CDB_Object& v);
856 
857 protected:
858  double m_Val;
859 };
860 
861 
862 /////////////////////////////////////////////////////////////////////////////
863 class CMemStore;
864 
866 {
867 public:
868  virtual ~CDB_Stream();
869 
870  // assignment
871  virtual void AssignNULL();
872  CDB_Stream& Assign(const CDB_Stream& v);
873 
874  // data manipulations
875  virtual size_t Read (void* buff, size_t nof_bytes);
876  virtual size_t Peek (void* buff, size_t nof_bytes) const;
877  virtual size_t PeekAt (void* buff, size_t start, size_t nof_bytes) const;
878  virtual size_t Append (const void* buff, size_t nof_bytes);
879  virtual void Truncate (size_t nof_bytes = kMax_Int);
880  virtual bool MoveTo (size_t byte_number);
881 
882  // current size of data
883  virtual size_t Size() const;
884  virtual void AssignValue(const CDB_Object& v);
885 
886 protected:
887  // constructors (destructor is public for compatibility with smart ptrs)
888  CDB_Stream();
889  CDB_Stream(const CDB_Stream& s, bool share_data = false);
890 
891  // common CDB_Text and CDB_VarCharMax functionality
892  void x_SetEncoding(EBulkEnc e);
893  size_t x_Append(const void* buff, size_t nof_bytes);
894  size_t x_Append(const CTempString& s, EEncoding enc);
895  size_t x_Append(const TStringUCS2& s, size_t l = TStringUCS2::npos);
896 
898 
899 private:
900  // data storage
902 };
903 
904 
905 
906 /////////////////////////////////////////////////////////////////////////////
908 {
909 public:
910  CDB_Image(void);
911  CDB_Image(const CDB_Image& image, bool share_data = false);
912  virtual ~CDB_Image(void);
913 
914 public:
915  CDB_Image& operator= (const CDB_Image& image);
916 
917  virtual EDB_Type GetType() const;
918  virtual CDB_Object* Clone() const;
919  virtual CDB_Object* ShallowClone() const;
920 };
921 
922 
923 /////////////////////////////////////////////////////////////////////////////
925 {
926 public:
927  CDB_VarBinaryMax(void);
928  CDB_VarBinaryMax(const CDB_VarBinaryMax& v, bool share_data = false);
929  CDB_VarBinaryMax(const void* v, size_t l);
930  virtual ~CDB_VarBinaryMax(void);
931 
932 public:
933  void SetValue(const void* v, size_t l) { Truncate(); Append(v, l); }
934 
936 
937  virtual EDB_Type GetType() const;
938  virtual CDB_Object* Clone() const;
939  virtual CDB_Object* ShallowClone() const;
940 };
941 
942 
943 
944 /////////////////////////////////////////////////////////////////////////////
946 {
947 public:
948  CDB_Text(void);
949  CDB_Text(const CDB_Text& text, bool share_data = false);
950  virtual ~CDB_Text(void);
951 
952 public:
953  // Get and set the encoding to be used by subsequent Append operations.
954  EBulkEnc GetEncoding(void) const { return m_Encoding; }
955  void SetEncoding(EBulkEnc e);
956 
957  virtual size_t Append(const void* buff, size_t nof_bytes);
958  virtual size_t Append(const CTempString& s,
960  virtual size_t Append(const TStringUCS2& s);
961 
962  CDB_Text& operator= (const CDB_Text& text);
963 
964  virtual EDB_Type GetType() const;
965  virtual CDB_Object* Clone() const;
966  virtual CDB_Object* ShallowClone() const;
967 };
968 
969 
970 /////////////////////////////////////////////////////////////////////////////
972 {
973 public:
974  CDB_VarCharMax(void);
975  CDB_VarCharMax(const CDB_VarCharMax& v, bool share_data = false);
976  CDB_VarCharMax(const string& s, EEncoding enc = eEncoding_Unknown);
977  CDB_VarCharMax(const char* s, EEncoding enc = eEncoding_Unknown);
978  CDB_VarCharMax(const char* s, size_t l, EEncoding enc = eEncoding_Unknown);
979  CDB_VarCharMax(const TStringUCS2& s, size_t l = TStringUCS2::npos);
980  virtual ~CDB_VarCharMax(void);
981 
982 public:
983  // Get and set the encoding to be used by subsequent Append operations.
984  EBulkEnc GetEncoding(void) const { return m_Encoding; }
985  void SetEncoding(EBulkEnc e);
986 
987  virtual size_t Append(const void* buff, size_t nof_bytes);
988  virtual size_t Append(const CTempString& s,
990  virtual size_t Append(const TStringUCS2& s, size_t l = TStringUCS2::npos);
991 
992  CDB_VarCharMax& SetValue(const string& s,
994  { Truncate(); Append(s, enc); return *this; }
995  CDB_VarCharMax& SetValue(const char* s,
997  { Truncate(); Append(s, enc); return *this; }
998  CDB_VarCharMax& SetValue(const char* s, size_t l,
1000  { Truncate(); Append(CTempString(s, l), enc); return *this; }
1002  size_t l = TStringUCS2::npos)
1003  { Truncate(); Append(s, l); return *this; }
1004 
1005  CDB_VarCharMax& operator= (const string& s) { return SetValue(s); }
1006  CDB_VarCharMax& operator= (const char* s) { return SetValue(s); }
1007  CDB_VarCharMax& operator= (const TStringUCS2& s) { return SetValue(s); }
1009 
1010  virtual EDB_Type GetType() const;
1011  virtual CDB_Object* Clone() const;
1012  virtual CDB_Object* ShallowClone() const;
1013 };
1014 
1015 
1016 
1017 /////////////////////////////////////////////////////////////////////////////
1019 {
1020 public:
1022  CDB_SmallDateTime(const CTime& t);
1023  CDB_SmallDateTime(Uint2 days, Uint2 minutes);
1024  virtual ~CDB_SmallDateTime(void);
1025 
1026 public:
1028 
1029  CDB_SmallDateTime& Assign(Uint2 days, Uint2 minutes);
1030  const CTime& Value(void) const;
1031  Uint2 GetDays(void) const;
1032  Uint2 GetMinutes(void) const;
1033 
1034  virtual EDB_Type GetType(void) const;
1035  virtual CDB_Object* Clone(void) const;
1036  virtual void AssignValue(const CDB_Object& v);
1037 
1038 protected:
1041  // which of m_NCBITime(0x1), m_DBTime(0x2) is valid; they both can be valid
1042  mutable unsigned int m_Status;
1043 };
1044 
1045 
1046 
1047 /////////////////////////////////////////////////////////////////////////////
1049 {
1050 public:
1052  CDB_DateTime(const CTime& t);
1053  CDB_DateTime(Int4 d, Int4 s300);
1054  virtual ~CDB_DateTime(void);
1055 
1056 public:
1057  CDB_DateTime& operator= (const CTime& t);
1058 
1059  CDB_DateTime& Assign(Int4 d, Int4 s300);
1060  const CTime& Value(void) const;
1061 
1062  Int4 GetDays(void) const;
1063  Int4 Get300Secs(void) const;
1064 
1065  virtual EDB_Type GetType(void) const;
1066  virtual CDB_Object* Clone(void) const;
1067  virtual void AssignValue(const CDB_Object& v);
1068 
1069 protected:
1072  // which of m_NCBITime(0x1), m_DBTime(0x2) is valid; they both can be valid
1073  mutable unsigned int m_Status;
1074 };
1075 
1076 
1077 
1078 /////////////////////////////////////////////////////////////////////////////
1080 {
1081 public:
1082  enum ESQLType {
1083  eDate = 1, ///< DATE (MS, Sybase)
1084  eTime = 2, ///< TIME (MS), (BIG)TIME (Sybase)
1085  eDateTime = 3, ///< DATETIME2 (MS), BIGDATETIME (Sybase)
1086  eDateTimeOffset = 7 ///< DATETIMEOFFSET (MS); no Sybase equivalent
1087  };
1088 
1089  enum ESyntax {
1092  eSyntax_Sybase
1093  };
1094 
1095  typedef CNullable<short> TOffset; ///< offset in minutes from GMT, if known
1096 
1098  ESQLType sql_type = eDateTime, TOffset offset = null);
1099  CDB_BigDateTime(const CTime& t, ESQLType sql_type = eDateTime,
1100  TOffset offset = null);
1101 
1102  CDB_BigDateTime& Assign(const CTime& t, ESQLType sql_type = eDateTime,
1103  TOffset offset = null);
1105  { return Assign(t); }
1106 
1107  const CTime& GetCTime(void) const
1108  { return m_Time; }
1109  const TOffset& GetOffset(void) const
1110  { return m_Offset; }
1111  ESQLType GetSQLType(void) const
1112  { return m_SQLType; }
1113  const char* GetSQLTypeName(ESyntax syntax);
1114 
1115  virtual EDB_Type GetType(void) const;
1116  virtual CDB_Object* Clone(void) const;
1117  virtual void AssignValue(const CDB_Object& v);
1118 
1119  static CTimeFormat GetTimeFormat(ESyntax syntax,
1120  ESQLType sql_type = eDateTime,
1121  TOffset offset = null);
1122  static pair<ESyntax, ESQLType> Identify(const CTempString& s);
1123 
1124 protected:
1128 };
1129 
1130 
1131 
1132 /////////////////////////////////////////////////////////////////////////////
1134 {
1135 public:
1136  CDB_Bit();
1137  CDB_Bit(int i);
1138  CDB_Bit(bool i);
1139  virtual ~CDB_Bit(void);
1140 
1141 public:
1142  CDB_Bit& operator= (const int& i);
1143  CDB_Bit& operator= (const bool& i);
1144 
1145  int Value() const { return IsNULL() ? 0 : (int) m_Val; }
1146  void* BindVal() const { return (void*) &m_Val; }
1147 
1148  virtual EDB_Type GetType() const;
1149  virtual CDB_Object* Clone() const;
1150  virtual void AssignValue(const CDB_Object& v);
1151 
1152 protected:
1154 };
1155 
1156 
1157 
1158 /////////////////////////////////////////////////////////////////////////////
1160 {
1161 public:
1162  CDB_Numeric();
1163  CDB_Numeric(unsigned int precision, unsigned int scale);
1164  CDB_Numeric(unsigned int precision, unsigned int scale,
1165  const unsigned char* arr);
1166  CDB_Numeric(unsigned int precision, unsigned int scale, bool is_negative,
1167  const unsigned char* arr);
1168  CDB_Numeric(unsigned int precision, unsigned int scale, const char* val);
1169  CDB_Numeric(unsigned int precision, unsigned int scale, const string& val);
1170  virtual ~CDB_Numeric(void);
1171 
1172 public:
1173  CDB_Numeric& Assign(unsigned int precision, unsigned int scale,
1174  const unsigned char* arr);
1175  CDB_Numeric& Assign(unsigned int precision, unsigned int scale,
1176  bool is_negative, const unsigned char* arr);
1177 
1178  CDB_Numeric& operator= (const char* val);
1179  CDB_Numeric& operator= (const string& val);
1180 
1181  string Value() const;
1182 
1183  Uint1 Precision() const {
1184  return m_Precision;
1185  }
1186 
1187  Uint1 Scale() const {
1188  return m_Scale;
1189  }
1190 
1191  // This method is for internal use only. It is strongly recommended
1192  // to refrain from using this method in applications.
1193  const unsigned char* RawData() const { return m_Body; }
1194 
1195  virtual EDB_Type GetType() const;
1196  virtual CDB_Object* Clone() const;
1197  virtual void AssignValue(const CDB_Object& v);
1198 
1199 protected:
1200  void x_MakeFromString(unsigned int precision,
1201  unsigned int scale,
1202  const CTempString& s);
1205  unsigned char m_Body[33];
1206 };
1207 
1208 /////////////////////////////////////////////////////////////////////////////
1209 
1211 typedef NCBI_PARAM_TYPE(dbapi, max_logged_param_length) TDbapi_MaxLoggedParamLength;
1212 
1213 /////////////////////////////////////////////////////////////////////////////
1214 
1215 inline
1217 {
1218  switch (db_type) {
1219  case eDB_Text:
1220  case eDB_VarCharMax:
1221  return eBlobType_Text;
1222  case eDB_Image:
1223  case eDB_VarBinaryMax:
1224  return eBlobType_Binary;
1225  default:
1226  return eBlobType_none;
1227  }
1228 }
1229 
1231 
1232 #endif /* DBAPI_DRIVER___TYPES__HPP */
1233 
1234 
1235 /* @} */
1236 
int TOffset
Basic data type for offsets into a sequence.
Definition: base.hpp:49
Convenience extension of basic_string, supporting implicit conversion to const TChar* in most situati...
Definition: types.hpp:99
CObjectFor –.
Definition: ncbiobj.hpp:2335
CObject –.
Definition: ncbiobj.hpp:180
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTimeFormat –.
Definition: ncbitime.hpp:131
CTime –.
Definition: ncbitime.hpp:296
static char precision
Definition: genparams.c:28
static const char * str(char *buf, int n)
Definition: stats.c:84
int offset
Definition: replacements.h:160
char data[12]
Definition: iconv.c:80
#define NULL
Definition: ncbistd.hpp:225
void * BindVal() const
Definition: types.hpp:851
size_t m_DataSize
Definition: types.hpp:809
static bool IsBlobType(EDB_Type db_type)
Definition: types.hpp:320
CObjectFor< string > TValue
Definition: types.hpp:769
EDB_Type
Definition: types.hpp:52
unsigned dbapi
Definition: types.hpp:1210
Int4 m_Val
Definition: types.hpp:381
double Value() const
Definition: types.hpp:850
basic_string< TChar > TBasicString
Definition: types.hpp:101
const char * m_Char
Definition: types.hpp:277
const void * Value() const
Definition: types.hpp:756
CGenericSqlString< char > CSqlString
Definition: types.hpp:119
TOffset m_Offset
Definition: types.hpp:1127
CGenericSqlString(const value_type *data)
Definition: types.hpp:107
static EBlobType GetBlobType(EDB_Type db_type)
Definition: types.hpp:1216
float Value() const
Definition: types.hpp:825
void SetBulkInsertionEnc(EBulkEnc e)
Definition: types.hpp:556
size_t Size() const
Definition: types.hpp:726
void * BindVal() const
Definition: types.hpp:374
size_t m_Size
Definition: types.hpp:703
Uint1 m_Val
Definition: types.hpp:1153
const TOffset & GetOffset(void) const
Definition: types.hpp:1109
TBasicString::size_type size_type
Definition: types.hpp:102
size_t m_Size
Definition: types.hpp:808
TDBTimeU m_DBTime
Definition: types.hpp:1040
NCBI_DBAPIDRIVER_EXPORT
Definition: types.hpp:1210
CGenericSqlString(void)
Definition: types.hpp:105
const unsigned char * RawData() const
Definition: types.hpp:1193
EBulkEnc
Definition: types.hpp:85
TStringUCS2 m_UCS2LEString
Definition: types.hpp:286
EBulkEnc GetEncoding(void) const
Definition: types.hpp:954
TDBTimeI m_DBTime
Definition: types.hpp:1071
typedef NCBI_PARAM_TYPE(dbapi, max_logged_param_length) TDbapi_MaxLoggedParamLength
TBasicString::value_type value_type
Definition: types.hpp:103
EBlobType
Definition: types.hpp:78
@ eBlobType_Binary
Definition: types.hpp:81
@ eBlobType_none
Definition: types.hpp:79
@ eBlobType_Text
Definition: types.hpp:80
Uint1 m_Precision
Definition: types.hpp:1203
size_type byte_count(void) const
Definition: types.hpp:111
const char * Value(void) const
Definition: types.hpp:537
const void * Value() const
Definition: types.hpp:723
CSqlString m_String
Definition: types.hpp:281
const wchar_t * m_WChar
Definition: types.hpp:279
ESQLType m_SQLType
Definition: types.hpp:1126
void * BindVal() const
Definition: types.hpp:401
CTime m_NCBITime
Definition: types.hpp:1070
size_t Size() const
Definition: types.hpp:693
const string & ConvertTo(EEncoding to_enc, EEncoding from_enc=eEncoding_Unknown) const
Definition: types.hpp:223
const char * AsCString(void) const
Definition: types.hpp:532
CGenericSqlString(const TBasicString &s)
Definition: types.hpp:106
unsigned int m_Status
Definition: types.hpp:1042
EBulkEnc GetEncoding(void) const
Definition: types.hpp:984
unsigned max_logged_param_length
Definition: types.hpp:1210
size_t Size() const
Definition: types.hpp:759
virtual EDB_Type GetType() const =0
CDB_VarCharMax & SetValue(const TStringUCS2 &s, size_t l=TStringUCS2::npos)
Definition: types.hpp:1001
const void * Data() const
Definition: types.hpp:758
const TStringUCS2 & AsUCS2_LE(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.hpp:205
#define K8_1
Definition: types.hpp:658
const wstring & AsWString(EEncoding enc) const
Definition: types.hpp:509
const CTime & GetCTime(void) const
Definition: types.hpp:1107
CGenericSqlString(const value_type *data, size_type len)
Definition: types.hpp:108
const string & AsUTF8(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.hpp:197
wstring m_WString
Definition: types.hpp:283
bool m_Null
Definition: types.hpp:329
void * BindVal() const
Definition: types.hpp:826
size_t DataSize() const
Definition: types.hpp:797
size_t Size() const
Definition: types.hpp:795
Int4 Value() const
Definition: types.hpp:373
unsigned int m_Status
Definition: types.hpp:1073
CRef< TValue > m_Value
Definition: types.hpp:772
const wstring & AsUnicode(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.hpp:214
const wchar_t * AsCWString(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.hpp:177
Int2 Value() const
Definition: types.hpp:400
CObjectFor< string > TValue
Definition: types.hpp:735
size_t m_Size
Definition: types.hpp:771
CGenericSqlString< wchar_t > CWSqlString
Definition: types.hpp:121
CNullable< short > TOffset
offset in minutes from GMT, if known
Definition: types.hpp:1095
Uint1 Scale() const
Definition: types.hpp:1187
size_t Size(void) const
Definition: types.hpp:522
virtual void AssignValue(const CDB_Object &v)=0
int GetAvailableValueType(void) const
Definition: types.hpp:249
int Value() const
Definition: types.hpp:1145
Uint1 Value() const
Definition: types.hpp:427
CObjectFor< string > TValue
Definition: types.hpp:806
Int2 m_Val
Definition: types.hpp:408
ESQLType GetSQLType(void) const
Definition: types.hpp:1111
virtual CDB_Object * ShallowClone() const
Definition: types.hpp:308
const string & AsString(void) const
Definition: types.hpp:517
void SetValue(const void *v, size_t l)
Definition: types.hpp:933
void SetNULL(bool flag=true)
Definition: types.hpp:326
int m_AvailableValueType
Definition: types.hpp:275
EBulkEnc m_BulkInsertionEnc
Definition: types.hpp:562
Uint1 m_Val
Definition: types.hpp:435
float m_Val
Definition: types.hpp:833
CMemStore * m_Store
Definition: types.hpp:901
double m_Val
Definition: types.hpp:858
EEncoding m_StringEncoding
Definition: types.hpp:276
size_t DataSize() const
Definition: types.hpp:694
CDB_VarCharMax & SetValue(const char *s, size_t l, EEncoding enc=eEncoding_Unknown)
Definition: types.hpp:998
void * BindVal() const
Definition: types.hpp:428
const void * Data() const
Definition: types.hpp:725
virtual CDB_Object * Clone() const =0
Uint1 m_Scale
Definition: types.hpp:1204
EBulkEnc m_Encoding
Definition: types.hpp:897
CDB_VarCharMax & SetValue(const char *s, EEncoding enc=eEncoding_Unknown)
Definition: types.hpp:995
CRef< TValue > m_Value
Definition: types.hpp:736
EBulkEnc GetBulkInsertionEnc(void) const
Definition: types.hpp:555
const char * AsCString(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.hpp:158
const char * Data(void) const
Definition: types.hpp:527
CDB_VarCharMax & SetValue(const string &s, EEncoding enc=eEncoding_Unknown)
Definition: types.hpp:992
const string & AsLatin1(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.hpp:189
CRef< TValue > m_Value
Definition: types.hpp:810
void * BindVal() const
Definition: types.hpp:1146
Uint1 Precision() const
Definition: types.hpp:1183
CStringUTF8 m_UTF8String
Definition: types.hpp:285
size_t m_Size
Definition: types.hpp:653
const void * Data() const
Definition: types.hpp:794
Int8 m_Val
Definition: types.hpp:463
const string & x_GetWString() const
Definition: types.hpp:566
Int8 Value() const
Definition: types.hpp:454
bool IsNULL() const
Definition: types.hpp:303
void * BindVal() const
Definition: types.hpp:455
CRef< CWString > m_WString
Definition: types.hpp:561
const void * Value() const
Definition: types.hpp:792
@ eDB_Bit
Definition: types.hpp:68
@ eDB_Char
Definition: types.hpp:58
@ eDB_UnsupportedType
Definition: types.hpp:75
@ eDB_SmallDateTime
Definition: types.hpp:65
@ eDB_VarChar
Definition: types.hpp:57
@ eDB_TinyInt
Definition: types.hpp:55
@ eDB_LongChar
Definition: types.hpp:70
@ eDB_Double
Definition: types.hpp:62
@ eDB_Image
Definition: types.hpp:67
@ eDB_Float
Definition: types.hpp:61
@ eDB_Int
Definition: types.hpp:53
@ eDB_VarCharMax
Definition: types.hpp:72
@ eDB_Numeric
Definition: types.hpp:69
@ eDB_BigInt
Definition: types.hpp:56
@ eDB_BigDateTime
Definition: types.hpp:64
@ eDB_Binary
Definition: types.hpp:60
@ eDB_Text
Definition: types.hpp:66
@ eDB_SmallInt
Definition: types.hpp:54
@ eDB_DateTime
Definition: types.hpp:63
@ eDB_LongBinary
Definition: types.hpp:71
@ eDB_VarBinary
Definition: types.hpp:59
@ eDB_VarBinaryMax
Definition: types.hpp:73
@ eBulkEnc_RawBytes
Definition: types.hpp:86
@ eBulkEnc_RawUCS2
Definition: types.hpp:87
@ eBulkEnc_UCS2FromChar
Definition: types.hpp:88
@ eDateTimeOffset
Definition: variant.hpp:87
void Read(CObjectIStream &in, TObjectPtr object, const CTypeRef &type)
Definition: serial.cpp:60
CObject & operator=(const CObject &src) THROWS_NONE
Assignment operator.
Definition: ncbiobj.hpp:482
#define NCBI_PARAM_DECL_EXPORT(expname, type, section, name)
Same as NCBI_PARAM_DECL but with export specifier (e.g.
Definition: ncbi_param.hpp:164
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
#define NCBI_DEPRECATED
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
#define kMax_Int
Definition: ncbi_limits.h:184
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
std::string CStringUTF8
Definition: ncbistl.hpp:254
EEncoding
Definition: ncbistr.hpp:199
#define kEmptyStr
Definition: ncbistr.hpp:123
#define kEmptyWStr
Definition: ncbistr.hpp:127
basic_string< TCharUCS2 > TStringUCS2
Type for string in UCS-2 encoding.
Definition: ncbistr.hpp:3849
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
@ eEncoding_Unknown
Definition: ncbistr.hpp:200
EInitMode
Which initial value to use for time.
Definition: ncbitime.hpp:299
CTime Truncate(const CTime &t)
Definition: ncbitime.hpp:2194
@ eEmpty
Use "empty" time.
Definition: ncbitime.hpp:301
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
int i
int len
static void text(MDB_val *v)
Definition: mdb_dump.c:62
mdb_mode_t mode
Definition: lmdb++.h:38
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
const struct ncbi::grid::netcache::search::fields::SIZE size
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2107
EIPRangeType t
Definition: ncbi_localip.c:101
Defines: CTimeFormat - storage class for time format.
Database format for time where day and time is signed 32 bit.
Definition: ncbitime.hpp:114
Database format for time where day and time is unsigned 16 bit.
Definition: ncbitime.hpp:108
Definition: type.c:6
Modified on Sat Jun 22 10:41:35 2024 by modify_doxy.py rev. 669887