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

Go to the SVN repository for this file.

1 /* $Id: types.cpp 95716 2021-12-13 20:24:33Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Vladimir Soussov
27  *
28  * File Description: Type conversions
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbitime.hpp>
34 
38 #include "memory_store.hpp"
39 
40 #include <dbapi/driver/types.hpp>
41 #include <dbapi/error_codes.hpp>
42 
43 #include <string.h>
44 
45 
46 #define NCBI_USE_ERRCODE_X Dbapi_DrvrTypes
47 
48 
50 
51 
52 inline
54 {
55 #ifdef WORDS_BIGENDIAN
57  *it = (*it << 8) | (*it >> 8);
58  }
59 #endif
60 }
61 
62 
63 /////////////////////////////////////////////////////////////////////////////
64 template<>
65 CGenericSqlString<char>::operator const char*(void) const
66 {
67  return this->c_str();
68 }
69 
70 #ifdef HAVE_WSTRING
71 template<>
72 CGenericSqlString<wchar_t>::operator const wchar_t*(void) const
73 {
74  return this->c_str();
75 }
76 #endif
77 
78 
79 /////////////////////////////////////////////////////////////////////////////
81  m_AvailableValueType(0),
82  m_StringEncoding(eEncoding_Unknown),
83  m_Char(NULL)
84 #ifdef HAVE_WSTRING
85  , m_WChar(NULL)
86 #endif
87 {
88 }
89 
90 
92  m_AvailableValueType(str.m_AvailableValueType),
93  m_StringEncoding(str.m_StringEncoding),
94  m_Char(NULL),
95 #ifdef HAVE_WSTRING
96  m_WChar(NULL),
97 #endif
98  m_String(str.m_String),
99 #ifdef HAVE_WSTRING
100  m_WString(str.m_WString),
101 #endif
102  m_UTF8String(str.m_UTF8String)
103 {
104  // Assign m_Char even if m_String is empty ...
105  m_Char = m_String.c_str();
106 
107 #ifdef HAVE_WSTRING
108  // Assign m_WChar even if m_WString is empty ...
109  m_WChar = m_WString.c_str();
110 #endif
111 }
112 
113 
115  string::size_type size,
116  EEncoding enc) :
117  m_AvailableValueType(eChar),
118  m_StringEncoding(enc),
119  m_Char(NULL)
120 #ifdef HAVE_WSTRING
121  , m_WChar(NULL)
122 #endif
123 {
124  if (size == string::npos) {
125  m_Char = str;
126  } else {
127  if (str) {
128  m_String.assign(str, size);
129  m_Char = m_String.c_str();
130  }
132  }
133 }
134 
135 
136 #ifdef HAVE_WSTRING
137 CWString::CWString(const wchar_t* str,
138  wstring::size_type size) :
139  m_AvailableValueType(eWChar),
140  m_StringEncoding(eEncoding_Unknown),
141  m_Char(NULL),
142  m_WChar(NULL)
143 {
144  if (size == wstring::npos) {
145  m_WChar = str;
146  } else {
147  if (str) {
148  m_WString.assign(str, size);
149  m_WChar = m_WString.c_str();
150  }
152  }
153 }
154 #endif
155 
156 
157 CWString::CWString(const string& str, EEncoding enc) :
158  m_AvailableValueType(eString),
159  m_StringEncoding(enc),
160  m_Char(NULL),
161 #ifdef HAVE_WSTRING
162  m_WChar(NULL),
163 #endif
164  m_String(str)
165 {
166  m_Char = m_String.c_str();
168 }
169 
170 
171 #ifdef HAVE_WSTRING
172 CWString::CWString(const wstring& str) :
173  m_AvailableValueType(eWString),
174  m_Char(NULL),
175  m_WChar(NULL),
176  m_WString(str)
177 {
178  m_WChar = m_WString.c_str();
180 }
181 #endif
182 
183 
185 {
186 }
187 
188 
190 {
191  if (&str != this) {
192  m_AvailableValueType = str.m_AvailableValueType;
193  m_StringEncoding = str.m_StringEncoding;
194  m_Char = NULL;
195  m_String = str.m_String;
196  m_UTF8String = str.m_UTF8String;
197  m_Char = m_String.c_str();
198 
199 #ifdef HAVE_WSTRING
200  m_WChar = NULL;
201  m_WString = str.m_WString;
202  m_WChar = m_WString.c_str();
203 #endif
204  }
205 
206  return *this;
207 }
208 
209 // Deprecated conversions, defined out of line to reduce warnings
210 CWString::operator char*(void) const
211 {
212  return const_cast<char*>(AsCString());
213 }
214 
215 CWString::operator const char*(void) const
216 {
217  return AsCString();
218 }
219 
220 CWString::operator wchar_t*(void) const
221 {
222  return const_cast<wchar_t*>(AsCWString());
223 }
224 
225 CWString::operator const wchar_t*(void) const
226 {
227  return AsCWString();
228 }
229 
230 
232 {
233  if (str_enc != eEncoding_Unknown) {
234  m_StringEncoding = str_enc;
235  } else {
237  }
238 }
239 
241 {
243  x_CalculateEncoding(str_enc);
244  }
245 
248  } else {
250  }
251 
253 }
254 
255 
257 {
259  x_CalculateEncoding(str_enc);
260  }
261 
264  } else if (m_AvailableValueType & eChar) {
265  if (m_Char) {
267  } else {
268  m_UTF8String.erase();
269  }
270  }
271 
273 }
274 
275 
277 {
279  if (!(m_AvailableValueType & eChar)) {
280  if (m_String.empty()) {
281  m_Char = NULL;
282  } else {
283  m_Char = m_String.c_str();
284  }
286  }
287  } else if (m_AvailableValueType & eChar) {
288  if (m_Char) {
289  m_String.assign(m_Char);
290  } else {
291  m_String.erase();
292  }
294  } else if (m_AvailableValueType & eUTF8String) {
295  x_UTF8ToString(str_enc);
296  x_MakeString(str_enc);
297 #ifdef HAVE_WSTRING
298  } else if (m_AvailableValueType & eWString) {
301  x_UTF8ToString(str_enc);
302  x_MakeString(str_enc);
303  } else if (m_AvailableValueType & eWChar) {
304  if (m_WChar) {
307  x_UTF8ToString(str_enc);
308  } else {
309  m_String.erase();
311  }
312  x_MakeString(str_enc);
313 #endif
314  }
315 }
316 
317 #ifdef HAVE_WSTRING
319 {
321  if (!(m_AvailableValueType & eWChar)) {
322  if (m_WString.empty()) {
323  m_WChar = NULL;
324  } else {
325  m_WChar = m_WString.c_str();
326  }
328  }
329  } else if (m_AvailableValueType & eWChar) {
330  if (m_WChar) {
331  m_WString.assign(m_WChar);
332  } else {
333  m_WString.erase();
334  }
336  } else if (m_AvailableValueType & eUTF8String) {
337  m_WString = CUtf8::AsBasicString<wchar_t>(m_UTF8String);
339  x_MakeWString(str_enc);
340  } else if (m_AvailableValueType & eString) {
341  x_StringToUTF8(str_enc);
342  x_MakeWString(str_enc);
343  } else if (m_AvailableValueType & eChar) {
344  if (m_Char) {
345  x_StringToUTF8(str_enc);
346  x_MakeWString(str_enc);
347  } else {
348  m_WString.erase();
350  }
351  }
352 }
353 #endif
354 
356 {
358  return;
359  } else if (m_AvailableValueType & eString) {
360  x_StringToUTF8(str_enc);
361  } else if (m_AvailableValueType & eChar) {
362  x_StringToUTF8(str_enc);
363 #ifdef HAVE_WSTRING
364  } else if (m_AvailableValueType & eWString) {
367  } else if (m_AvailableValueType & eWChar) {
368  if (m_WChar) {
370  } else {
371  m_UTF8String.erase();
372  }
374 #endif
375  }
376 }
377 
379 {
381  return;
382  } else {
383  x_MakeUTF8String(str_enc);
384  m_UCS2LEString = CUtf8::AsBasicString<TCharUCS2>(m_UTF8String);
387  }
388 }
389 
390 size_t CWString::GetSymbolNum(void) const
391 {
392  size_t num = 0;
393 
395  num = m_String.size();
396 #ifdef HAVE_WSTRING
397  } else if (m_AvailableValueType & eWString) {
398  num = m_WString.size();
399 #endif
400  } else if (m_AvailableValueType & eChar) {
401  if (m_Char) {
402  num = strlen(m_Char);
403  }
404 #ifdef HAVE_WSTRING
405  } else if (m_AvailableValueType & eWChar) {
406  if (m_WChar) {
407  // ??? Should be a better solution ...
408  x_MakeWString();
409  num = m_WString.size();
410  }
411 #endif
412  } else if (m_AvailableValueType & eUTF8String) {
414  }
415 
416  return num;
417 }
418 
419 void CWString::Clear(void)
420 {
423  m_Char = NULL;
424  m_String.erase();
425 #ifdef HAVE_WSTRING
426  m_WChar = NULL;
427  m_WString.erase();
428 #endif
429  m_UTF8String.erase();
430 }
431 
432 void CWString::Assign(const char* str,
433  string::size_type size,
434  EEncoding enc)
435 {
436 #ifdef HAVE_WSTRING
437  m_WChar = NULL;
438  m_WString.erase();
439 #endif
440  m_UTF8String.erase();
441 
442  m_StringEncoding = enc;
443  if (size == string::npos) {
444  m_String.erase();
445  m_Char = str;
447  } else {
448  if (str) {
449  m_String.assign(str, size);
450  m_Char = m_String.c_str();
451  } else {
452  m_Char = NULL;
453  m_String.erase();
454  }
456  }
457 }
458 
459 #ifdef HAVE_WSTRING
460 void CWString::Assign(const wchar_t* str,
461  wstring::size_type size)
462 {
464  m_Char = NULL;
465  m_String.erase();
466  m_UTF8String.erase();
467 
468  if (size == wstring::npos) {
469  m_WString.erase();
470  m_WChar = str;
472  } else {
473  if (str) {
474  m_WString.assign(str, size);
475  m_WChar = m_WString.c_str();
476  } else {
477  m_WChar = NULL;
478  m_WString.erase();
479  }
481  }
482 }
483 #endif
484 
485 void CWString::Assign(const string& str,
486  EEncoding enc)
487 {
488 #ifdef HAVE_WSTRING
489  m_WChar = NULL;
490  m_WString.erase();
491 #endif
492  m_UTF8String.erase();
493 
494  m_StringEncoding = enc;
495  m_String = str;
496  m_Char = m_String.c_str();
498 }
499 
500 #ifdef HAVE_WSTRING
501 void CWString::Assign(const wstring& str)
502 {
504  m_Char = NULL;
505  m_String.erase();
506  m_UTF8String.erase();
507 
508  m_WString = str;
509  m_WChar = m_WString.c_str();
511 }
512 #endif
513 
514 
515 ////////////////////////////////////////////////////////////////////////////////
516 static
517 void CheckStringTruncation(size_t cur_len, size_t max_len)
518 {
519  if (cur_len > max_len) {
520  ERR_POST_X(1, Warning << "String of size " << cur_len <<
521  " was truncated to " << max_len << " character(s)");
522  }
523 }
524 
525 ////////////////////////////////////////////////////////////////////////////////
526 static
527 void CheckBinaryTruncation(size_t cur_len, size_t max_len)
528 {
529  if (cur_len > max_len) {
530  ERR_POST_X(2, Warning << "Binary data of size " << cur_len <<
531  " was truncated to " << max_len << " byte(s)");
532  }
533 }
534 
535 ////////////////////////////////////////////////////////////////////////////////
536 // CDB_Object::
537 //
538 
539 CDB_Object::CDB_Object(bool is_null) :
540  m_Null(is_null)
541 {
542  return;
543 }
544 
546 {
547  return;
548 }
549 
551 {
552  SetNULL();
553 }
554 
555 
557 {
558  switch ( type ) {
559  case eDB_Int : return new CDB_Int ();
560  case eDB_SmallInt : return new CDB_SmallInt ();
561  case eDB_TinyInt : return new CDB_TinyInt ();
562  case eDB_BigInt : return new CDB_BigInt ();
563  case eDB_VarChar : return new CDB_VarChar ();
564  case eDB_Char : return new CDB_Char (size);
565  case eDB_VarBinary : return new CDB_VarBinary ();
566  case eDB_Binary : return new CDB_Binary (size);
567  case eDB_Float : return new CDB_Float ();
568  case eDB_Double : return new CDB_Double ();
569  case eDB_DateTime : return new CDB_DateTime ();
570  case eDB_BigDateTime : return new CDB_BigDateTime ();
571  case eDB_SmallDateTime : return new CDB_SmallDateTime ();
572  case eDB_Text : return new CDB_Text ();
573  case eDB_Image : return new CDB_Image ();
574  case eDB_Bit : return new CDB_Bit ();
575  case eDB_Numeric : return new CDB_Numeric ();
576  case eDB_LongBinary : return new CDB_LongBinary(size);
577  case eDB_LongChar : return new CDB_LongChar (size);
578  case eDB_VarCharMax : return new CDB_VarCharMax ();
579  case eDB_VarBinaryMax : return new CDB_VarBinaryMax ();
580  case eDB_UnsupportedType : break;
581  }
582  DATABASE_DRIVER_ERROR("unknown type " + NStr::IntToString(type), 2);
583 }
584 
585 
586 const char* CDB_Object::GetTypeName(EDB_Type db_type, bool throw_on_unknown)
587 {
588  switch ( db_type ) {
589  case eDB_Int : return "DB_Int";
590  case eDB_SmallInt : return "DB_SmallInt";
591  case eDB_TinyInt : return "DB_TinyInt";
592  case eDB_BigInt : return "DB_BigInt";
593  case eDB_VarChar : return "DB_VarChar";
594  case eDB_Char : return "DB_Char";
595  case eDB_VarBinary : return "DB_VarBinary";
596  case eDB_Binary : return "DB_Binary";
597  case eDB_Float : return "DB_Float";
598  case eDB_Double : return "DB_Double";
599  case eDB_DateTime : return "DB_DateTime";
600  case eDB_BigDateTime : return "DB_BigDateTime";
601  case eDB_SmallDateTime : return "DB_SmallDateTime";
602  case eDB_Text : return "DB_Text";
603  case eDB_Image : return "DB_Image";
604  case eDB_Bit : return "DB_Bit";
605  case eDB_Numeric : return "DB_Numeric";
606  case eDB_LongBinary : return "DB_LongBinary";
607  case eDB_LongChar : return "DB_LongChar";
608  case eDB_VarCharMax : return "DB_VarCharMax";
609  case eDB_VarBinaryMax : return "DB_VarBinaryMax";
610  case eDB_UnsupportedType : return "DB_UnsupportedType";
611  }
612 
613  if (throw_on_unknown) {
614  DATABASE_DRIVER_ERROR("unknown type " + NStr::IntToString(db_type), 2);
615  }
616 
617  return "DB_???";
618 }
619 
620 
622 
623 
624 string CDB_Object::GetLogString(void) const
625 {
626  if (IsNULL()) {
627  return "NULL";
628  }
629 
630  unsigned int max_length = TDbapi_MaxLoggedParamLength::GetDefault();
631  string result;
632 
633  if (IsBlobType(GetType())) {
634  const CDB_Stream& s = static_cast<const CDB_Stream&>(*this);
635  AutoArray<char> buff(max_length + 1);
636  result.assign(buff.get(), s.PeekAt(buff.get(), 0, max_length + 1));
637  } else {
638  try {
639  result = (string)ConvertSQL(*this);
640  } catch (exception& e) {
641  ERR_POST(Warning << "Exception converting from "
642  << GetTypeName(GetType()) << ": " << e.what());
643  return "???";
644  }
645  }
646 
647  if (result.length() > max_length) {
648  result.resize(max_length);
649  if (max_length > 3) {
650  result[max_length - 1] = result[max_length - 2] =
651  result[max_length - 3] = '.';
652  }
653  }
654  // XXX - retrim?
655  return NStr::PrintableString
657 }
658 
659 
660 /////////////////////////////////////////////////////////////////////////////
661 // CDB_Int::
662 //
663 
665  CDB_Object(true),
666  m_Val(0)
667 {
668  return;
669 }
670 
672  CDB_Object(false),
673  m_Val(i)
674 {
675  return;
676 }
677 
679 {
680  return;
681 }
682 
684 {
685  return eDB_Int;
686 }
687 
689 {
690  return IsNULL() ? new CDB_Int : new CDB_Int(m_Val);
691 }
692 
694 {
695  switch( v.GetType() ) {
696  case eDB_Int : *this = static_cast<const CDB_Int&>(v); break;
697  case eDB_SmallInt: *this = static_cast<const CDB_SmallInt&>(v).Value(); break;
698  case eDB_TinyInt : *this = static_cast<const CDB_TinyInt &>(v).Value(); break;
699  default:
700  DATABASE_DRIVER_ERROR( "wrong type of CDB_Object", 2 );
701  }
702 
703 }
704 
705 
706 /////////////////////////////////////////////////////////////////////////////
707 // CDB_SmallInt::
708 //
709 
711  CDB_Object(true),
712  m_Val(0)
713 {
714  return;
715 }
716 
718  CDB_Object(false),
719  m_Val(i)
720 {
721  return;
722 }
723 
725 {
726  return;
727 }
728 
730 {
731  return eDB_SmallInt;
732 }
733 
735 {
736  return IsNULL() ? new CDB_SmallInt : new CDB_SmallInt(m_Val);
737 }
738 
740 {
741  switch( v.GetType() ) {
742  case eDB_SmallInt: *this= (const CDB_SmallInt&)v; break;
743  case eDB_TinyInt : *this= ((const CDB_TinyInt &)v).Value(); break;
744  default:
745  DATABASE_DRIVER_ERROR(string("wrong type of CDB_Object: ")
746  + GetTypeName(v.GetType(), false),
747  2);
748  }
749  *this= (CDB_SmallInt&)v;
750 }
751 
752 /////////////////////////////////////////////////////////////////////////////
753 // CDB_TinyInt::
754 //
755 
757  CDB_Object(true),
758  m_Val(0)
759 {
760  return;
761 }
762 
764  CDB_Object(false),
765  m_Val(i)
766 {
767  return;
768 }
769 
771 {
772  return;
773 }
774 
776 {
777  return eDB_TinyInt;
778 }
779 
781 {
782  return IsNULL() ? new CDB_TinyInt : new CDB_TinyInt(m_Val);
783 }
784 
786 {
788  string("wrong type of CDB_Object: ")
789  + GetTypeName(v.GetType(), false),
790  2);
791 
792  *this= (const CDB_TinyInt&)v;
793 }
794 
795 
796 /////////////////////////////////////////////////////////////////////////////
797 // CDB_BigInt::
798 //
799 
801  CDB_Object(true),
802  m_Val(0)
803 {
804  return;
805 }
806 
808  CDB_Object(false),
809  m_Val(i)
810 {
811  return;
812 }
813 
815 {
816  return;
817 }
818 
820 {
821  return eDB_BigInt;
822 }
823 
825 {
826  return IsNULL() ? new CDB_BigInt : new CDB_BigInt(m_Val);
827 }
828 
830 {
831  switch( v.GetType() ) {
832  case eDB_BigInt : *this= (const CDB_BigInt&)v; break;
833  case eDB_Int : *this= ((const CDB_Int &)v).Value(); break;
834  case eDB_SmallInt: *this= ((const CDB_SmallInt&)v).Value(); break;
835  case eDB_TinyInt : *this= ((const CDB_TinyInt &)v).Value(); break;
836  default:
837  DATABASE_DRIVER_ERROR(string("wrong type of CDB_Object: ")
838  + GetTypeName(v.GetType(), false),
839  2);
840  }
841 }
842 
843 
844 template <typename TChar>
845 inline size_t my_strnlen(const TChar* str, size_t maxlen)
846 {
847  size_t len = 0;
848  while (len < maxlen && *str != 0) {
849  ++len;
850  ++str;
851  }
852  return len;
853 }
854 
855 
856 /////////////////////////////////////////////////////////////////////////////
857 inline
858 CRef<CWString> MakeString(const string& s, string::size_type size,
860 {
861  string value(s, 0, size);
862 
863  if (size != string::npos) {
864  value.resize(size, ' ');
865  }
866 
867  return CRef<CWString>(new CWString(value, enc));
868 }
869 
870 inline
871 CRef<CWString> MakeString(const TStringUCS2& s, TStringUCS2::size_type size,
873 {
874  _ASSERT(enc == eEncoding_Unknown);
875  TStringUCS2 value(s, 0, size);
876 
877  if (size != TStringUCS2::npos) {
878  value.resize(size, TCharUCS2(' '));
879  }
880 
882  return CRef<CWString>(new CWString((const char*)value.data(),
883  value.size() * sizeof(TCharUCS2)));
884 }
885 
886 template <typename TChar>
887 inline
889  typename basic_string<TChar>::size_type size,
891 {
892  typedef basic_string<TChar> TStr;
893  if (s == NULL) {
894  return MakeString(TStr(), size);
895  }
896 
897  TStr str;
898  if (size == TStr::npos)
899  str.assign(s);
900  else {
901  size_t str_size = my_strnlen(s, size);
902  str.assign(s, str_size);
903  }
904  return MakeString(str, size);
905 }
906 
907 /////////////////////////////////////////////////////////////////////////////
908 // CDB_String::
909 //
910 
912  : CDB_Object(true), m_BulkInsertionEnc(eBulkEnc_RawBytes)
913 {
914 }
915 
916 
917 CDB_String::CDB_String(const CDB_String& other, bool share_data)
918  : CDB_Object(other), m_WString(other.m_WString),
919  m_BulkInsertionEnc(other.m_BulkInsertionEnc)
920 {
921  if (other.m_WString.NotEmpty() && !share_data) {
922  m_WString.Reset(new CWString(*other.m_WString));
923  }
924 }
925 
926 
927 CDB_String::CDB_String(const string& s, EEncoding enc)
928  : CDB_Object(false), m_WString(new CWString(s, enc)),
929  m_BulkInsertionEnc(eBulkEnc_RawBytes)
930 {
931 }
932 
933 
935  string::size_type size,
936  EEncoding enc)
937  : CDB_Object(s == NULL), m_WString(MakeString(s, size, enc)),
938  m_BulkInsertionEnc(eBulkEnc_RawBytes)
939 {
940 }
941 
942 
943 CDB_String::CDB_String(const string& s,
944  string::size_type size,
945  EEncoding enc)
946  : CDB_Object(false), m_WString(MakeString(s, size, enc)),
947  m_BulkInsertionEnc(eBulkEnc_RawBytes)
948 {
949 }
950 
951 
952 CDB_String::CDB_String(const TStringUCS2& s, TStringUCS2::size_type size)
953  : CDB_Object(false), m_WString(MakeString(s, size)),
954  m_BulkInsertionEnc(eBulkEnc_RawUCS2)
955 {
956 }
957 
958 
959 /*
960 CDB_String::CDB_String(const TCharUCS2* s, string::size_type size)
961  : CDB_Object(s == NULL), m_WString(MakeString(s, size)),
962  m_BulkInsertionEnc(eBulkEnc_RawUCS2)
963 {
964 }
965 */
966 
967 
969 {
970 }
971 
972 
974 {
975  if (this != &other) {
976  Assign(other);
977  }
978 
979  return *this;
980 }
981 
982 
984 {
985  Assign(s);
986  return *this;
987 }
988 
989 
991 {
992  Assign(s);
993  return *this;
994 }
995 
996 
998 {
999  Assign(s);
1000  return *this;
1001 }
1002 
1003 
1004 CDB_String::operator const char*(void) const
1005 {
1006  return m_WString.Empty() ? kEmptyCStr : m_WString->AsCString();
1007 }
1008 
1009 
1010 #ifdef HAVE_WSTRING
1011 const wchar_t* CDB_String::AsUnicode(EEncoding enc) const
1012 {
1013  return IsNULL() ? NULL : m_WString->AsUnicode(enc).c_str();
1014 }
1015 #endif
1016 
1017 
1018 void CDB_String::Assign(const CDB_String& other)
1019 {
1020  SetNULL(other.IsNULL());
1021  m_WString.Reset((IsNULL() || other.m_WString.Empty()) ? NULL
1022  : new CWString(*other.m_WString));
1024 }
1025 
1026 
1027 void CDB_String::Assign(const char* s,
1028  string::size_type size,
1029  EEncoding enc)
1030 {
1031  if ( s ) {
1032  SetNULL(false);
1033 
1034  if (m_WString.NotEmpty() && size == string::npos) {
1035  m_WString->Assign(string(s), enc);
1036  } else {
1037  m_WString.Reset(MakeString(s, size, enc));
1038  }
1039  } else {
1040  SetNULL();
1041  }
1044  }
1045 }
1046 
1047 
1048 void CDB_String::Assign(const string& s,
1049  string::size_type size,
1050  EEncoding enc)
1051 {
1052  SetNULL(false);
1053  m_WString.Reset(MakeString(s, size, enc));
1056  }
1057 }
1058 
1059 
1060 /*
1061 void CDB_String::Assign(const TCharUCS2* s,
1062  TStringUCS2::size_type size)
1063 {
1064  if ( s ) {
1065  SetNULL(false);
1066  m_WString.Reset(MakeString(s, size));
1067  } else {
1068  SetNULL();
1069  }
1070  m_BulkInsertionEnc = eBulkEnc_RawUCS2;
1071 }
1072 */
1073 
1074 
1076  TStringUCS2::size_type size)
1077 {
1078  SetNULL(false);
1081 }
1082 
1083 
1084 void CDB_String::GetBulkInsertionData(CTempString* ts, bool convert_raw_bytes)
1085  const
1086 {
1087  _ASSERT(ts);
1088 
1089  if (IsNULL() || m_WString.Empty()) {
1090  ts->clear();
1091  return;
1092  }
1093 
1095  if (convert_raw_bytes && enc == eBulkEnc_RawBytes) {
1096  enc = eBulkEnc_UCS2FromChar;
1097  }
1098 
1099  switch (enc) {
1100  case eBulkEnc_RawBytes:
1101  case eBulkEnc_RawUCS2:
1102  *ts = x_GetWString();
1103  break;
1104  case eBulkEnc_UCS2FromChar:
1105  {
1106  const TStringUCS2& s2 = m_WString->AsUCS2_LE();
1107  ts->assign((char*) s2.data(), s2.size() * sizeof(TCharUCS2));
1108  break;
1109  }
1110  default:
1111  _TROUBLE;
1112  }
1113 }
1114 
1115 /////////////////////////////////////////////////////////////////////////////
1116 template <typename TChar>
1117 static
1118 typename basic_string<TChar>::size_type
1120  typename basic_string<TChar>::size_type len)
1121 {
1122  typedef basic_string<TChar> TStr;
1123 
1124  if (len == TStr::npos) {
1125  return len;
1126  } else if (str == NULL) {
1127  return 0;
1128  } else {
1129  return my_strnlen(str, len ? len : TStr::npos);
1130  }
1131 }
1132 
1133 /////////////////////////////////////////////////////////////////////////////
1134 // CDB_VarChar::
1135 //
1136 
1138 {
1139 }
1140 
1141 
1142 CDB_VarChar::CDB_VarChar(const CDB_VarChar& v, bool share_data)
1143 : CDB_String(v, share_data)
1144 {
1145 }
1146 
1147 
1149  EEncoding enc)
1150 : CDB_String(s, enc)
1151 {
1152 }
1153 
1154 
1156  EEncoding enc)
1157 : CDB_String(s, string::npos, enc)
1158 {
1159 }
1160 
1161 
1163  size_t l,
1164  EEncoding enc)
1165 : CDB_String(s, get_string_size_varchar(s, l), enc)
1166 {
1167 }
1168 
1169 
1172 {
1173 }
1174 
1175 
1176 /*
1177 CDB_VarChar::CDB_VarChar(const TCharUCS2* s, size_t l)
1178  : CDB_String(s, get_string_size_varchar(s, l))
1179 {
1180 }
1181 */
1182 
1183 
1185 {
1186 }
1187 
1188 
1190  EEncoding enc)
1191 {
1192  Assign(s, string::npos, enc);
1193 
1194  return *this;
1195 }
1196 
1197 
1199  EEncoding enc)
1200 {
1201  Assign(s, string::npos, enc);
1202 
1203  return *this;
1204 }
1205 
1206 
1207 CDB_VarChar& CDB_VarChar::SetValue(const char* s, size_t l,
1208  EEncoding enc)
1209 {
1210  Assign(s, l, enc);
1211 
1212  return *this;
1213 }
1214 
1215 
1217 {
1218  Assign(s, TStringUCS2::npos);
1219 
1220  return *this;
1221 }
1222 
1223 
1224 /*
1225 CDB_VarChar& CDB_VarChar::SetValue(const TCharUCS2* s, size_t l)
1226 {
1227  Assign(s, l);
1228 
1229  return *this;
1230 }
1231 */
1232 
1233 
1235 {
1236  return eDB_VarChar;
1237 }
1238 
1239 
1241 {
1242  return IsNULL() ? new CDB_VarChar() : new CDB_VarChar(*this);
1243 }
1244 
1245 
1247 {
1248  return IsNULL() ? new CDB_VarChar() : new CDB_VarChar(*this, true);
1249 }
1250 
1251 
1253 {
1255  string("wrong type of CDB_Object: ")
1256  + GetTypeName(v.GetType(), false),
1257  2);
1258 
1259  *this= (const CDB_VarChar&)v;
1260 }
1261 
1262 
1263 /////////////////////////////////////////////////////////////////////////////
1264 // CDB_Char::
1265 //
1266 
1267 
1269 : m_Size((s < 1) ? 1 : s)
1270 {
1271 }
1272 
1273 
1275  const string& v,
1276  EEncoding enc) :
1277  CDB_String(v, s, enc),
1278  m_Size(CDB_String::Size())
1279 {
1280 }
1281 
1282 
1284  const char* str,
1285  EEncoding enc) :
1286  CDB_String(str, s, enc),
1287  m_Size(CDB_String::Size())
1288 {
1289 }
1290 
1291 
1292 CDB_Char::CDB_Char(size_t s, const TStringUCS2& v)
1293  : CDB_String(v, s), m_Size(CDB_String::Size())
1294 {
1295 }
1296 
1297 
1298 CDB_Char::CDB_Char(const CDB_Char& v, bool share_data) :
1299  CDB_String(v, share_data),
1300  m_Size(v.m_Size)
1301 {
1302 }
1303 
1304 
1306 {
1307  if (this != &v) {
1308  m_Size = v.m_Size;
1309  Assign(v);
1310  }
1311 
1312  return *this;
1313 }
1314 
1315 
1317 {
1318  // Encoding of s ???
1319  CheckStringTruncation(s.size(), m_Size);
1320  Assign(s, m_Size);
1321 
1322  return *this;
1323 }
1324 
1325 
1327 {
1328  if (s) {
1329  // Encoding of s ???
1330  size_t len = strlen(s);
1332  Assign(s, m_Size);
1333  }
1334 
1335  return *this;
1336 }
1337 
1338 
1340 {
1341  CheckStringTruncation(s.size(), m_Size);
1342  Assign(s, m_Size);
1343 
1344  return *this;
1345 }
1346 
1347 
1348 void CDB_Char::SetValue(const char* str, size_t len, EEncoding enc)
1349 {
1350  CDB_VarChar vc_value(str, len, enc);
1351  CheckStringTruncation(vc_value.Size(), m_Size);
1352 
1353  Assign(vc_value.AsCString(), m_Size, enc);
1354 }
1355 
1356 
1357 void CDB_Char::SetValue(const TStringUCS2& v, size_t len)
1358 {
1359  CDB_VarChar vc_value(v, len);
1360  CheckStringTruncation(vc_value.Size(), m_Size);
1361 
1362  Assign(vc_value.Data(), m_Size);
1363 }
1364 
1365 
1367 {
1368  return eDB_Char;
1369 }
1370 
1372 {
1373  return new CDB_Char(*this);
1374 }
1375 
1377 {
1378  return new CDB_Char(*this, true);
1379 }
1380 
1382 {
1384  string("wrong type of CDB_Object: ")
1385  + GetTypeName(v.GetType(), false),
1386  2);
1387 
1388  const CDB_Char& cv = (const CDB_Char&)v;
1389  *this = cv;
1390 }
1391 
1393 {
1394 }
1395 
1396 /////////////////////////////////////////////////////////////////////////////
1397 static
1398 string::size_type
1399 get_string_size_longchar(const char* str, string::size_type len)
1400 {
1401  if (len == string::npos) {
1402  return len;
1403  }
1404 
1405  if (str != NULL) {
1406  if (len == 0) {
1407  return strlen(str); // Similar to string::npos ...
1408  } else {
1409  return max(len, my_strnlen(str, len)); // This line is "min(len, str_len)" in case of varchar ...
1410  }
1411  }
1412 
1413  return 0;
1414 }
1415 
1416 /////////////////////////////////////////////////////////////////////////////
1417 // CDB_LongChar::
1418 //
1419 
1420 
1422  : m_Size((s < 1) ? 1 : s)
1423 {
1424 }
1425 
1426 
1428  const string& v,
1429  EEncoding enc) :
1430  CDB_String(v, s, enc),
1431  m_Size(CDB_String::Size())
1432 {
1433 }
1434 
1435 
1437  const char* str,
1438  EEncoding enc) :
1440  m_Size(CDB_String::Size())
1441 {
1442 }
1443 
1444 
1446  const TStringUCS2& v)
1447  : CDB_String(v, s), m_Size(CDB_String::Size())
1448 {
1449 }
1450 
1451 
1452 CDB_LongChar::CDB_LongChar(const CDB_LongChar& v, bool share_data) :
1453  CDB_String(v, share_data),
1454  m_Size(v.m_Size)
1455 {
1456 }
1457 
1458 
1460 {
1461  if (this != &v) {
1462  m_Size = v.m_Size;
1463  Assign(v);
1464  }
1465 
1466  return *this;
1467 }
1468 
1469 
1471 {
1472  // Encoding of s ???
1473  CheckStringTruncation(s.size(), m_Size);
1474  Assign(s, m_Size);
1475 
1476  return *this;
1477 }
1478 
1479 
1481 {
1482  if (s) {
1483  // Encoding of s ???
1484  size_t len = strlen(s);
1486  Assign(s, m_Size);
1487  }
1488 
1489  return *this;
1490 }
1491 
1492 
1494 {
1495  CheckStringTruncation(s.size(), m_Size);
1496  Assign(s, m_Size);
1497 
1498  return *this;
1499 }
1500 
1501 
1502 void CDB_LongChar::SetValue(const char* str,
1503  size_t len,
1504  EEncoding enc)
1505 {
1506  CDB_VarChar vc(str, len, enc);
1508 
1509  Assign(vc.AsCString(), m_Size, enc);
1510 }
1511 
1512 
1514 {
1515  CDB_VarChar vc(str, len);
1517 
1518  Assign(vc.Data(), m_Size);
1519 }
1520 
1521 
1523 {
1524  return eDB_LongChar;
1525 }
1526 
1527 
1529 {
1530  return new CDB_LongChar(*this);
1531 }
1532 
1534 {
1535  return new CDB_LongChar(*this, true);
1536 }
1537 
1538 
1540 {
1542  string("wrong type of CDB_Object: ")
1543  + GetTypeName(v.GetType(), false),
1544  2);
1545 
1546  const CDB_LongChar& cv= (const CDB_LongChar&)v;
1547  *this = cv;
1548 }
1549 
1550 
1552 {
1553 }
1554 
1555 
1556 /////////////////////////////////////////////////////////////////////////////
1557 // CDB_VarBinary::
1558 //
1559 
1560 
1562 {
1563 }
1564 
1566  : CDB_Object(v), m_Value(v.m_Value)
1567 {
1568  if (v.m_Value.NotEmpty() && !share_data) {
1569  m_Value.Reset(new TValue(*v.m_Value));
1570  }
1571 }
1572 
1573 CDB_VarBinary::CDB_VarBinary(const void* v, size_t l)
1574 {
1575  SetValue(v, l);
1576 }
1577 
1579 {
1580 }
1581 
1582 void CDB_VarBinary::SetValue(const void* v, size_t l)
1583 {
1584  if (v != NULL) {
1585  if (m_Value.Empty()) {
1586  m_Value.Reset(new TValue);
1587  }
1588  m_Value->GetData().assign(static_cast<const char*>(v), l);
1589  SetNULL(false);
1590  } else {
1591  m_Value.Reset();
1592  SetNULL();
1593  }
1594 }
1595 
1596 
1598 {
1599  if (this != &v) {
1600  SetNULL(v.IsNULL());
1601  m_Value.Reset((IsNULL() || v.m_Value.Empty()) ? NULL
1602  : new TValue(*v.m_Value));
1603  }
1604 
1605  return *this;
1606 }
1607 
1608 
1610 {
1611  return eDB_VarBinary;
1612 }
1613 
1614 
1616 {
1617  return IsNULL() ? new CDB_VarBinary : new CDB_VarBinary(*this);
1618 }
1619 
1621 {
1622  return IsNULL() ? new CDB_VarBinary : new CDB_VarBinary(*this, true);
1623 }
1624 
1625 
1627 {
1629  string("wrong type of CDB_Object: ")
1630  + GetTypeName(v.GetType(), false),
1631  2);
1632 
1633  *this= (const CDB_VarBinary&)v;
1634 }
1635 
1636 /////////////////////////////////////////////////////////////////////////////
1637 // CDB_Binary::
1638 //
1639 
1640 
1642 {
1643  m_Size = (s < 1) ? 1 : s;
1644 }
1645 
1646 
1647 CDB_Binary::CDB_Binary(size_t s, const void* v, size_t v_size)
1648 {
1649  m_Size = (s == 0) ? 1 : s;
1650  SetValue(v, v_size);
1651 }
1652 
1653 
1654 CDB_Binary::CDB_Binary(const CDB_Binary& v, bool share_data)
1655  : CDB_Object(v), m_Size(v.m_Size), m_Value(v.m_Value)
1656 {
1657  if (v.m_Value.NotEmpty() && !share_data) {
1658  m_Value.Reset(new TValue(*v.m_Value));
1659  }
1660 }
1661 
1662 
1663 void CDB_Binary::SetValue(const void* v, size_t v_size)
1664 {
1665  if (v != NULL) {
1666  CheckBinaryTruncation(v_size, m_Size);
1667 
1668  if (m_Value.Empty()) {
1669  m_Value.Reset(new TValue);
1670  }
1671  m_Value->GetData().assign(static_cast<const char*>(v),
1672  min(v_size, m_Size));
1673  m_Value->GetData().resize(m_Size, '\0');
1674  SetNULL(false);
1675  } else {
1676  m_Value.Reset();
1677  SetNULL();
1678  }
1679 }
1680 
1681 
1683 {
1684  if (this != &v) {
1685  SetNULL(v.IsNULL());
1686  m_Size = v.m_Size;
1687  m_Value.Reset((IsNULL() || v.m_Value.Empty()) ? NULL
1688  : new TValue(*v.m_Value));
1689  }
1690 
1691  return *this;
1692 }
1693 
1694 
1696 {
1697  return eDB_Binary;
1698 }
1699 
1700 
1702 {
1703  return IsNULL() ? new CDB_Binary(m_Size) : new CDB_Binary(*this);
1704 }
1705 
1707 {
1708  return IsNULL() ? new CDB_Binary(m_Size) : new CDB_Binary(*this, true);
1709 }
1710 
1711 
1713 {
1715  string("wrong type of CDB_Object: ")
1716  + GetTypeName(v.GetType(), false),
1717  2);
1718 
1719  const CDB_Binary& cv = static_cast<const CDB_Binary&>(v);
1720  *this = cv;
1721 }
1722 
1723 
1725 {
1726 }
1727 
1728 /////////////////////////////////////////////////////////////////////////////
1729 // CDB_LongBinary::
1730 //
1731 
1732 
1734 : m_Size((s < 1) ? 1 : s)
1735 , m_DataSize(0)
1736 {
1737 }
1738 
1739 
1740 CDB_LongBinary::CDB_LongBinary(size_t s, const void* v, size_t v_size)
1741 : m_Size(s)
1742 {
1743  SetValue(v, v_size);
1744 }
1745 
1746 
1748 : CDB_Object(v)
1749 , m_Size(v.m_Size)
1750 , m_DataSize(v.m_DataSize)
1751 , m_Value(v.m_Value)
1752 {
1753  if (v.m_Value.NotEmpty() && !share_data) {
1754  m_Value.Reset(new TValue(*v.m_Value));
1755  }
1756 }
1757 
1758 
1759 void CDB_LongBinary::SetValue(const void* v, size_t v_size)
1760 {
1761  if (v != NULL) {
1762  m_DataSize = min(v_size, m_Size);
1763  CheckBinaryTruncation(v_size, m_Size);
1764  if (m_Value.Empty()) {
1765  m_Value.Reset(new TValue);
1766  }
1767  m_Value->GetData().assign(static_cast<const char*>(v), m_DataSize);
1768  m_Value->GetData().resize(m_Size, '\0');
1769  SetNULL(false);
1770  } else {
1771  m_Value.Reset();
1772  SetNULL();
1773  m_DataSize = 0;
1774  }
1775 }
1776 
1777 
1779 {
1780  if (this != &v) {
1781  SetNULL(v.IsNULL());
1782  m_Size = v.m_Size;
1783  m_DataSize = v.m_DataSize;
1784  m_Value = v.m_Value;
1785  m_Value.Reset((IsNULL() || v.m_Value.Empty()) ? NULL
1786  : new TValue(*v.m_Value));
1787  }
1788 
1789  return *this;
1790 }
1791 
1792 
1794 {
1795  return eDB_LongBinary;
1796 }
1797 
1798 
1800 {
1801  return new CDB_LongBinary(*this);
1802 }
1803 
1805 {
1806  return new CDB_LongBinary(*this, true);
1807 }
1808 
1809 
1811 {
1813  v.GetType() != eDB_LongBinary,
1814  string("wrong type of CDB_Object: ") + GetTypeName(v.GetType(), false),
1815  2 );
1816 
1817  const CDB_LongBinary& cv = static_cast<const CDB_LongBinary&>(v);
1818  *this = cv;
1819 }
1820 
1821 
1823 {
1824 }
1825 
1826 
1827 /////////////////////////////////////////////////////////////////////////////
1828 // CDB_Float::
1829 //
1830 
1831 
1833  CDB_Object(true),
1834  m_Val(0.0)
1835 {
1836  return;
1837 }
1838 
1840  CDB_Object(false),
1841  m_Val(i)
1842 {
1843  return;
1844 }
1845 
1847 {
1848 }
1849 
1850 
1852 {
1853  SetNULL(false);
1854  m_Val = i;
1855  return *this;
1856 }
1857 
1858 
1860 {
1861  return eDB_Float;
1862 }
1863 
1865 {
1866  return IsNULL() ? new CDB_Float : new CDB_Float(m_Val);
1867 }
1868 
1870 {
1871  switch( v.GetType() ) {
1872  case eDB_Float : *this = (const CDB_Float&)v; break;
1873  case eDB_SmallInt: *this = ((const CDB_SmallInt&)v).Value(); break;
1874  case eDB_TinyInt : *this = ((const CDB_TinyInt &)v).Value(); break;
1875  default:
1876  DATABASE_DRIVER_ERROR(string("wrong type of CDB_Object: ")
1877  + GetTypeName(v.GetType(), false),
1878  2);
1879  }
1880 }
1881 
1882 /////////////////////////////////////////////////////////////////////////////
1883 // CDB_Double::
1884 //
1885 
1886 
1888  CDB_Object(true),
1889  m_Val(0.0)
1890 {
1891  return;
1892 }
1893 
1895  CDB_Object(false),
1896  m_Val(i)
1897 {
1898  return;
1899 }
1900 
1902 {
1903 }
1904 
1906 {
1907  SetNULL(false);
1908  m_Val = i;
1909  return *this;
1910 }
1911 
1913 {
1914  return eDB_Double;
1915 }
1916 
1918 {
1919  return IsNULL() ? new CDB_Double : new CDB_Double(m_Val);
1920 }
1921 
1923 {
1924  switch( v.GetType() ) {
1925  case eDB_Double : *this = (const CDB_Double&)v; break;
1926  case eDB_Float : *this = ((const CDB_Float &)v).Value(); break;
1927  case eDB_Int : *this = ((const CDB_Int &)v).Value(); break;
1928  case eDB_SmallInt: *this = ((const CDB_SmallInt&)v).Value(); break;
1929  case eDB_TinyInt : *this = ((const CDB_TinyInt &)v).Value(); break;
1930  default:
1931  DATABASE_DRIVER_ERROR(string("wrong type of CDB_Object: ")
1932  + GetTypeName(v.GetType(), false),
1933  2);
1934  }
1935 }
1936 
1937 /////////////////////////////////////////////////////////////////////////////
1938 // CDB_Stream::
1939 //
1940 
1942  : CDB_Object(true), m_Encoding(eBulkEnc_RawBytes)
1943 
1944 {
1945  m_Store = new CMemStore;
1946  m_Store->AddReference();
1947 }
1948 
1949 CDB_Stream::CDB_Stream(const CDB_Stream& s, bool share_data)
1950  : CDB_Object(s), m_Encoding(s.m_Encoding), m_Store(s.m_Store)
1951 {
1952  if (share_data) {
1953  m_Store->AddReference();
1954  } else {
1955  m_Store = new CMemStore;
1956  m_Store->AddReference();
1957  Assign(s);
1958  }
1959 }
1960 
1962 {
1963  SetNULL(v.IsNULL());
1964  m_Store->Truncate();
1965  m_Encoding = v.m_Encoding;
1966  if ( !IsNULL() ) {
1967  char buff[1024];
1968  CMemStore* s = const_cast<CMemStore*>(&*v.m_Store);
1969  size_t pos = s->Tell();
1970  s->Seek(0L, C_RA_Storage::eHead);
1971  for (size_t n = s->Read((void*) buff, sizeof(buff));
1972  n > 0;
1973  n = s->Read((void*) buff, sizeof(buff))) {
1974  Append((void*) buff, n);
1975  }
1976  s->Seek((long) pos, C_RA_Storage::eHead);
1977  }
1978  return *this;
1979 }
1980 
1982 {
1984  Truncate();
1985 }
1986 
1987 size_t CDB_Stream::Read(void* buff, size_t nof_bytes)
1988 {
1989  return m_Store->Read(buff, nof_bytes);
1990 }
1991 
1992 size_t CDB_Stream::Peek(void* buff, size_t nof_bytes) const
1993 {
1994  return m_Store->Peek(buff, nof_bytes);
1995 }
1996 
1997 size_t CDB_Stream::PeekAt(void* buff, size_t start, size_t nof_bytes) const
1998 {
1999  return m_Store->PeekAt(buff, start, nof_bytes);
2000 }
2001 
2002 size_t CDB_Stream::Append(const void* buff, size_t nof_bytes)
2003 {
2004  /* if (buff && (nof_bytes > 0)) */ SetNULL(false);
2005  return m_Store->Append(buff, nof_bytes);
2006 }
2007 
2008 bool CDB_Stream::MoveTo(size_t byte_number)
2009 {
2010  return m_Store->Seek((long) byte_number, C_RA_Storage::eHead)
2011  == (long) byte_number;
2012 }
2013 
2014 size_t CDB_Stream::Size() const
2015 {
2016  return m_Store->GetDataSize();
2017 }
2018 
2019 void CDB_Stream::Truncate(size_t nof_bytes)
2020 {
2021  m_Store->Truncate(nof_bytes);
2022  SetNULL(m_Store->GetDataSize() <= 0);
2023 }
2024 
2026 {
2028  string("wrong type of CDB_Object: ") + GetTypeName(v.GetType(), false),
2029  2
2030  );
2031  Assign(static_cast<const CDB_Stream&>(v));
2032 }
2033 
2035 {
2036  try {
2038  }
2040 }
2041 
2043 {
2044  if (e == eBulkEnc_UCS2FromChar) {
2045  e = eBulkEnc_RawUCS2;
2046  }
2047  if (e != m_Encoding && Size() > 0) {
2048  // Alternatively, arrange to recode existing text?
2049  ERR_POST_X(8, string("Creating a mixed-encoding C")
2050  + GetTypeName(GetType()) + " object.");
2051  }
2052  m_Encoding = e;
2053 }
2054 
2055 size_t CDB_Stream::x_Append(const void* buff, size_t nof_bytes)
2056 {
2057  if (buff == NULL) {
2058  // return 0;
2059  buff = kEmptyCStr;
2060  }
2061  // Warn if nof_bytes == 0?
2062  return CDB_Stream::Append
2063  (buff, nof_bytes ? nof_bytes : strlen((const char*) buff));
2064 }
2065 
2067 {
2068  switch (m_Encoding) {
2069  case eBulkEnc_RawBytes:
2070  return Append(s.data(), s.size());
2071  case eBulkEnc_RawUCS2:
2072  {
2073  TStringUCS2 s2 = CUtf8::AsBasicString<TCharUCS2>
2074  (CUtf8::AsUTF8(s, enc));
2075  s_MakeLittleEndian(s2);
2076  return Append(s2.data(), s2.size() * sizeof(TCharUCS2));
2077  }
2078  default:
2079  _TROUBLE;
2080  return 0;
2081  }
2082 }
2083 
2084 size_t CDB_Stream::x_Append(const TStringUCS2& s, size_t l)
2085 {
2087 #ifdef WORDS_BIGENDIAN
2088  if (l == TStringUCS2::npos) {
2089  l = s.size();
2090  }
2091  TStringUCS2 s2(s, l);
2092  s_MakeLittleEndian(s2);
2093  return Append(s2.data(), s2.size() * sizeof(TCharUCS2));
2094 #else
2095  return Append(s.data(), s.size() * sizeof(TCharUCS2));
2096 #endif
2097 }
2098 
2099 /////////////////////////////////////////////////////////////////////////////
2100 // CDB_Image::
2101 //
2102 
2104 {
2105 }
2106 
2107 CDB_Image::CDB_Image(const CDB_Image& image, bool share_data)
2108  : CDB_Stream(image, share_data)
2109 {
2110 }
2111 
2113 {
2114 }
2115 
2117 {
2118  return dynamic_cast<CDB_Image&> (Assign(image));
2119 }
2120 
2122 {
2123  return eDB_Image;
2124 }
2125 
2127 {
2128  return new CDB_Image(*this);
2129 }
2130 
2132 {
2133  return new CDB_Image(*this, true);
2134 }
2135 
2136 
2137 /////////////////////////////////////////////////////////////////////////////
2138 // CDB_VarBinaryMax::
2139 //
2140 
2142 {
2143 }
2144 
2146  : CDB_Stream(v, share_data)
2147 {
2148 }
2149 
2150 CDB_VarBinaryMax::CDB_VarBinaryMax(const void* v, size_t l)
2151 {
2152  Append(v, l);
2153 }
2154 
2156 {
2157 }
2158 
2160 {
2161  return dynamic_cast<CDB_VarBinaryMax&>(Assign(v));
2162 }
2163 
2165 {
2166  return eDB_VarBinaryMax;
2167 }
2168 
2170 {
2171  return new CDB_VarBinaryMax(*this);
2172 }
2173 
2175 {
2176  return new CDB_VarBinaryMax(*this, true);
2177 }
2178 
2179 
2180 /////////////////////////////////////////////////////////////////////////////
2181 // CDB_Text::
2182 //
2183 
2185 {
2186 }
2187 
2188 CDB_Text::CDB_Text(const CDB_Text& text, bool share_data)
2189  : CDB_Stream(text, share_data)
2190 {
2191 }
2192 
2194 {
2195 }
2196 
2198 {
2199  x_SetEncoding(e);
2200 }
2201 
2202 size_t CDB_Text::Append(const void* buff, size_t nof_bytes)
2203 {
2204  return x_Append(buff, nof_bytes);
2205 }
2206 
2208 {
2209  return x_Append(s, enc);
2210 }
2211 
2212 
2214 {
2215  return x_Append(s);
2216 }
2217 
2219 {
2220  m_Encoding = text.m_Encoding;
2221  return dynamic_cast<CDB_Text&> (Assign(text));
2222 }
2223 
2225 {
2226  return eDB_Text;
2227 }
2228 
2230 {
2231  return new CDB_Text(*this);
2232 }
2233 
2235 {
2236  return new CDB_Text(*this, true);
2237 }
2238 
2239 
2240 /////////////////////////////////////////////////////////////////////////////
2241 // CDB_VarCharMax::
2242 //
2243 
2245 {
2246 }
2247 
2249  : CDB_Stream(v, share_data)
2250 {
2251 }
2252 
2254 {
2255  SetValue(s, enc);
2256 }
2257 
2259 {
2260  SetValue(s, enc);
2261 }
2262 
2263 CDB_VarCharMax::CDB_VarCharMax(const char* s, size_t l, EEncoding enc)
2264 {
2265  SetValue(s, l, enc);
2266 }
2267 
2269 {
2270  SetValue(s);
2271 }
2272 
2274 {
2275 }
2276 
2278 {
2279  x_SetEncoding(e);
2280 }
2281 
2282 size_t CDB_VarCharMax::Append(const void* buff, size_t nof_bytes)
2283 {
2284  return x_Append(buff, nof_bytes);
2285 }
2286 
2288 {
2289  return x_Append(s, enc);
2290 }
2291 
2292 size_t CDB_VarCharMax::Append(const TStringUCS2& s, size_t l)
2293 {
2294  return x_Append(s);
2295 }
2296 
2298 {
2299  m_Encoding = v.m_Encoding;
2300  return dynamic_cast<CDB_VarCharMax&>(Assign(v));
2301 }
2302 
2304 {
2305  return eDB_VarCharMax;
2306 }
2307 
2309 {
2310  return new CDB_VarCharMax(*this);
2311 }
2312 
2314 {
2315  return new CDB_VarCharMax(*this, true);
2316 }
2317 
2318 
2319 
2320 /////////////////////////////////////////////////////////////////////////////
2321 // CDB_SmallDateTime::
2322 //
2323 
2324 
2326 : m_NCBITime(mode)
2327 , m_Status( 0x1 )
2328 {
2329  m_DBTime.days = 0;
2330  m_DBTime.time = 0;
2332 }
2333 
2334 
2336 : m_NCBITime( t )
2337 , m_Status( 0x1 )
2338 {
2339  m_DBTime.days = 0;
2340  m_DBTime.time = 0;
2341  SetNULL(t.IsEmpty());
2342 }
2343 
2344 
2346 : m_Status( 0x2 )
2347 {
2348  m_DBTime.days = days;
2349  m_DBTime.time = minutes;
2350  SetNULL(false);
2351 }
2352 
2353 
2355 {
2356 }
2357 
2359 {
2360  m_DBTime.days = days;
2361  m_DBTime.time = minutes;
2362  m_Status = 0x2;
2363  SetNULL(false);
2364 
2365  return *this;
2366 }
2367 
2368 
2370 {
2371  m_NCBITime = t;
2372  m_DBTime.days = 0;
2373  m_DBTime.time = 0;
2374  m_Status = 0x1;
2375  SetNULL(t.IsEmpty());
2376 
2377  return *this;
2378 }
2379 
2380 
2382 {
2383  if((m_Status & 0x1) == 0) {
2385  m_Status |= 0x1;
2386  }
2387  return m_NCBITime;
2388 }
2389 
2390 
2392 {
2393  if((m_Status & 0x2) == 0) {
2395  m_Status |= 0x2;
2396  }
2397  return m_DBTime.days;
2398 }
2399 
2400 
2402 {
2403  if((m_Status & 0x2) == 0) {
2405  m_Status |= 0x2;
2406  }
2407  return m_DBTime.time;
2408 }
2409 
2410 
2412 {
2413  return eDB_SmallDateTime;
2414 }
2415 
2417 {
2418  return IsNULL() ? new CDB_SmallDateTime : new CDB_SmallDateTime(Value());
2419 }
2420 
2422 {
2424  v.GetType() != eDB_SmallDateTime,
2425  string("wrong type of CDB_Object: ") + GetTypeName(v.GetType(), false),
2426  2 );
2427  *this= (const CDB_SmallDateTime&)v;
2428 }
2429 
2430 
2431 /////////////////////////////////////////////////////////////////////////////
2432 // CDB_DateTime::
2433 //
2434 
2435 
2437 : m_NCBITime(mode)
2438 , m_Status(0x1)
2439 {
2440  m_DBTime.days = 0;
2441  m_DBTime.time = 0;
2443 }
2444 
2445 
2447 : m_NCBITime( t )
2448 , m_Status( 0x1 )
2449 {
2450  m_DBTime.days = 0;
2451  m_DBTime.time = 0;
2452  SetNULL(t.IsEmpty());
2453 }
2454 
2455 
2457 : m_Status( 0x2 )
2458 {
2459  m_DBTime.days = d;
2460  m_DBTime.time = s300;
2461  SetNULL(false);
2462 }
2463 
2464 
2466 {
2467 }
2468 
2469 
2471 {
2472  m_NCBITime = t;
2473  m_DBTime.days = 0;
2474  m_DBTime.time = 0;
2475  m_Status = 0x1;
2476  SetNULL(t.IsEmpty());
2477  return *this;
2478 }
2479 
2480 
2482 {
2483  m_DBTime.days = d;
2484  m_DBTime.time = s300;
2485  m_Status = 0x2;
2486  SetNULL(false);
2487  return *this;
2488 }
2489 
2490 
2491 const CTime& CDB_DateTime::Value(void) const
2492 {
2493  if((m_Status & 0x1) == 0) {
2495  m_Status |= 0x1;
2496  }
2497  return m_NCBITime;
2498 }
2499 
2500 
2502 {
2503  if((m_Status & 0x2) == 0) {
2505  m_Status |= 0x2;
2506  }
2507  return m_DBTime.days;
2508 }
2509 
2510 
2512 {
2513  if((m_Status & 0x2) == 0) {
2515  m_Status |= 0x2;
2516  }
2517  return m_DBTime.time;
2518 }
2519 
2520 
2522 {
2523  return eDB_DateTime;
2524 }
2525 
2527 {
2528  return IsNULL() ? new CDB_DateTime : new CDB_DateTime(Value());
2529 }
2530 
2532 {
2534  v.GetType() != eDB_DateTime,
2535  string("wrong type of CDB_Object: ") + GetTypeName(v.GetType(), false),
2536  2 );
2537  *this= (const CDB_DateTime&)v;
2538 }
2539 
2540 
2541 /////////////////////////////////////////////////////////////////////////////
2542 // CDB_BigDateTime::
2543 //
2544 
2545 
2547  TOffset offset)
2548  : m_Time(mode), m_SQLType(sql_type), m_Offset(offset)
2549 {
2551 }
2552 
2553 
2555  TOffset offset)
2556  : m_Time(t), m_SQLType(sql_type), m_Offset(offset)
2557 {
2558  SetNULL(t.IsEmpty());
2559 }
2560 
2561 
2563  TOffset offset)
2564 {
2565  m_Time = t;
2566  m_SQLType = sql_type;
2567  m_Offset = offset;
2568  SetNULL(t.IsEmpty());
2569  return *this;
2570 }
2571 
2573 {
2574  switch (syntax) {
2575  case eSyntax_Unknown:
2576  break;
2577  case eSyntax_Microsoft:
2578  switch (m_SQLType) {
2579  case eDate: return "DATE";
2580  case eTime: return "TIME";
2581  case eDateTime: return "DATETIME2";
2582  case eDateTimeOffset: return "DATETIMEOFFSET";
2583  }
2584  case eSyntax_Sybase:
2585  switch (m_SQLType) {
2586  case eDate: return "BIGDATE";
2587  case eTime: return "BIGTIME";
2588  case eDateTime: return "BIGDATETIME";
2589  case eDateTimeOffset: break;
2590  }
2591  }
2592  return kEmptyCStr;
2593 }
2594 
2596 {
2597  return eDB_BigDateTime;
2598 }
2599 
2601 {
2602  return IsNULL() ? new CDB_BigDateTime : new CDB_BigDateTime(*this);
2603 }
2604 
2606 {
2607  switch (v.GetType()) {
2608  case eDB_BigDateTime: *this = (const CDB_BigDateTime&) v; break;
2609  case eDB_DateTime : *this = ((const CDB_DateTime&)v).Value(); break;
2610  case eDB_VarChar :
2611  {
2612  const string& s = (const CDB_VarChar&) v;
2613  pair<ESyntax, ESQLType> id = Identify(s);
2614  Assign(CTime(s, GetTimeFormat(id.first, id.second)), id.second);
2615  break;
2616  }
2617  default:
2618  DATABASE_DRIVER_ERROR(string("wrong type of CDB_Object: ")
2619  + GetTypeName(v.GetType(), false), 2);
2620  }
2621 }
2622 
2624  TOffset offset)
2625 {
2626  const char* s = kEmptyCStr;
2627  switch (syntax) {
2628  case eSyntax_Unknown: // go with ISO
2629  switch (sql_type) {
2630  case eDate: s = "Y-M-D" ; break;
2631  case eTime: s = "h:m:G" ; break;
2632  case eDateTime: s = "Y-M-DTh:m:G" ; break;
2633  case eDateTimeOffset: s = "Y-M-DTh:m:Go"; break;
2634  }
2635  break;
2636  case eSyntax_Microsoft:
2637  switch (sql_type) {
2638  case eDate: s = "Y-M-D" ; break;
2639  case eTime: s = "h:m:G" ; break;
2640  case eDateTime: s = "Y-M-D h:m:G" ; break;
2641  case eDateTimeOffset: s = "Y-M-D h:m:Go"; break;
2642  }
2643  break;
2644  case eSyntax_Sybase: // cap time precision to avoid syntax errors(!)
2645  switch (sql_type) {
2646  case eDate: s = "b D Y" ; break;
2647  case eTime: s = "H:m:s.rP" ; break;
2648  case eDateTime: s = "b D Y H:m:s.rP" ; break;
2649  case eDateTimeOffset: s = "b D Y H:m:s.rPo"; break;
2650  }
2651  break;
2652  }
2653  if (sql_type == eDateTimeOffset && !offset.IsNull() ) {
2654  char offset_str[6];
2655  auto o = offset.GetValue();
2656  if (o < 0) {
2657  offset_str[0] = '-';
2658  o = -o;
2659  } else {
2660  offset_str[0] = '+';
2661  }
2662  offset_str[1] = '0' + o / 600;
2663  offset_str[2] = '0' + ((o / 60) % 10);
2664  offset_str[3] = ':';
2665  offset_str[4] = '0' + ((o / 10) % 10);
2666  offset_str[5] = '0' + (o % 10);
2667  string s2(s);
2668  _ASSERT(NStr::EndsWith(s2, "o"));
2669  s2.replace(s2.size() - 1, 1, offset_str, 6);
2670  return CTimeFormat(s2);
2671  }
2672  return CTimeFormat(s);
2673 }
2674 
2675 pair<CDB_BigDateTime::ESyntax, CDB_BigDateTime::ESQLType>
2677 {
2678  ESyntax syntax = eSyntax_Unknown;
2679  ESQLType sql_type = eDateTime;
2680 
2681  if (s.size() >= 8) {
2682  if (s[s.size() - 1] == 'M' || isalpha((unsigned char) s[0])) {
2683  syntax = eSyntax_Sybase;
2684  if (s.find(" ") == NPOS) {
2685  sql_type = (s[2] == ':') ? eTime : eDate;
2686  }
2687  } else {
2688  SIZE_TYPE pos = s.find_first_of(" T");
2689  if (pos == NPOS) {
2690  sql_type = (s[2] == ':') ? eTime : eDate;
2691  } else {
2692  if (s[pos] == ' ') {
2693  syntax = eSyntax_Microsoft;
2694  }
2695  char c = s[s.size() - 6];
2696  if (c == '+' || c == '-') {
2697  sql_type = eDateTimeOffset;
2698  }
2699  }
2700  }
2701  }
2702 
2703  return make_pair(syntax, sql_type);
2704 }
2705 
2706 /////////////////////////////////////////////////////////////////////////////
2707 // CDB_Bit::
2708 //
2709 
2710 
2712  CDB_Object(true),
2713  m_Val(0)
2714 {
2715  return;
2716 }
2717 
2719  CDB_Object(false)
2720 {
2721  m_Val = i ? 1 : 0;
2722 }
2723 
2725  CDB_Object(false)
2726 {
2727  m_Val = i ? 1 : 0;
2728 }
2729 
2731 {
2732 }
2733 
2735 {
2736  SetNULL(false);
2737  m_Val = i ? 1 : 0;
2738  return *this;
2739 }
2740 
2741 
2743 {
2744  SetNULL(false);
2745  m_Val = i ? 1 : 0;
2746  return *this;
2747 }
2748 
2749 
2751 {
2752  return eDB_Bit;
2753 }
2754 
2756 {
2757  return IsNULL() ? new CDB_Bit : new CDB_Bit(m_Val ? 1 : 0);
2758 }
2759 
2761 {
2763  v.GetType() != eDB_Bit,
2764  string("wrong type of CDB_Object: ") + GetTypeName(v.GetType(), false),
2765  2 );
2766  *this= (const CDB_Bit&)v;
2767 }
2768 
2769 
2770 /////////////////////////////////////////////////////////////////////////////
2771 //
2772 // CDB_Numeric::
2773 //
2774 
2775 
2777  CDB_Object(true),
2778  m_Precision(0),
2779  m_Scale(0)
2780 {
2781  memset(m_Body, 0, sizeof(m_Body));
2782 }
2783 
2784 
2785 CDB_Numeric::CDB_Numeric(unsigned int precision, unsigned int scale)
2786  : CDB_Object(false),
2787  m_Precision(precision),
2788  m_Scale(scale)
2789 {
2790  memset(m_Body, 0, sizeof(m_Body));
2791 }
2792 
2793 
2795  unsigned int scale,
2796  const unsigned char* arr) :
2797  CDB_Object(false),
2798  m_Precision(precision),
2799  m_Scale(scale)
2800 {
2801  memcpy(m_Body, arr, sizeof(m_Body));
2802 }
2803 
2804 
2806  unsigned int scale,
2807  bool is_negative,
2808  const unsigned char* arr) :
2809  CDB_Object(false),
2810  m_Precision(precision),
2811  m_Scale(scale)
2812 {
2813  m_Body[0]= is_negative? 1 : 0;
2814  memcpy(m_Body+1, arr, sizeof(m_Body)-1);
2815 }
2816 
2817 
2818 CDB_Numeric::CDB_Numeric(unsigned int precision, unsigned int scale, const char* val)
2819  : m_Precision(0),
2820  m_Scale(0)
2821 {
2822  x_MakeFromString(precision, scale, val);
2823 }
2824 
2825 
2826 CDB_Numeric::CDB_Numeric(unsigned int precision, unsigned int scale, const string& val)
2827  : m_Precision(0),
2828  m_Scale(0)
2829 {
2830  x_MakeFromString(precision, scale, val);
2831 }
2832 
2833 
2835 {
2836 }
2837 
2838 
2840  unsigned int scale,
2841  const unsigned char* arr)
2842 {
2844  m_Scale = scale;
2845  SetNULL(false);
2846  memcpy(m_Body, arr, sizeof(m_Body));
2847  return *this;
2848 }
2849 
2850 
2852  unsigned int scale,
2853  bool is_negative,
2854  const unsigned char* arr)
2855 {
2857  m_Scale = scale;
2858  SetNULL(false);
2859  m_Body[0] = is_negative? 1 : 0;
2860  memcpy(m_Body + 1, arr, sizeof(m_Body) - 1);
2861  return *this;
2862 }
2863 
2864 
2866 {
2868  return *this;
2869 }
2870 
2871 
2873 {
2875  return *this;
2876 }
2877 
2878 
2880 {
2881  return eDB_Numeric;
2882 }
2883 
2884 
2886 {
2887  return new CDB_Numeric((unsigned int) m_Precision,
2888  (unsigned int) m_Scale, m_Body);
2889 }
2890 
2891 
2893 {
2894  2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9,
2895  10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 14, 15, 15,
2896  16, 16, 16, 17, 17, 18, 18, 19, 19, 19, 20, 20, 21, 21, 21,
2897  22, 22, 23, 23, 24, 24, 24, 25, 25, 26, 26, 26
2898 };
2899 
2900 
2901 static const unsigned int kMaxPrecision = 50;
2902 
2903 
2904 static void s_DoCarry(unsigned char* product)
2905 {
2906  for (unsigned int j = 0; j < kMaxPrecision; j++) {
2907  if (product[j] > 9) {
2908  product[j + 1] += product[j] / 10;
2909  product[j] %= 10;
2910  }
2911  }
2912 }
2913 
2914 
2915 static void s_MultiplyByte(unsigned char* product, int num,
2916  const unsigned char* multiplier)
2917 {
2918  unsigned char number[3];
2919  number[0] = num % 10;
2920  number[1] = (num / 10) % 10;
2921  number[2] = (num / 100) % 10;
2922 
2923  int top;
2924  for (top = kMaxPrecision - 1; top >= 0 && !multiplier[top]; top--)
2925  continue;
2926 
2927  int start = 0;
2928  for (int i = 0; i <= top; i++) {
2929  for (int j =0; j < 3; j++) {
2930  product[j + start] += multiplier[i] * number[j];
2931  }
2932  s_DoCarry(product);
2933  start++;
2934  }
2935 }
2936 
2937 
2938 static char* s_ArrayToString(const unsigned char* array, int scale, char* s)
2939 {
2940  int top;
2941 
2942  for (top = kMaxPrecision - 1; top >= 0 && top > scale && !array[top];
2943  top--)
2944  continue;
2945 
2946  if (top == -1) {
2947  s[0] = '0';
2948  s[1] = '\0';
2949  return s;
2950  }
2951 
2952  int j = 0;
2953  for (int i = top; i >= 0; i--) {
2954  if (top + 1 - j == scale)
2955  s[j++] = '.';
2956  s[j++] = array[i] + '0';
2957  }
2958  s[j] = '\0';
2959 
2960  return s;
2961 }
2962 
2963 
2964 string CDB_Numeric::Value() const
2965 {
2966  unsigned char multiplier[kMaxPrecision];
2967  unsigned char temp[kMaxPrecision];
2968  unsigned char product[kMaxPrecision];
2969  char result[kMaxPrecision + 1];
2970  char* s = result;
2971  int num_bytes = 0;
2972 
2973  memset(multiplier, 0, kMaxPrecision);
2974  memset(product, 0, kMaxPrecision);
2975  multiplier[0] = 1;
2976  if (m_Precision != 0) {
2977  num_bytes = s_NumericBytesPerPrec[m_Precision-1];
2978  }
2979 
2980  if (m_Body[0] == 1) {
2981  *s++ = '-';
2982  }
2983 
2984  for (int pos = num_bytes - 1; pos > 0; pos--) {
2985  s_MultiplyByte(product, m_Body[pos], multiplier);
2986 
2987  memcpy(temp, multiplier, kMaxPrecision);
2988  memset(multiplier, 0, kMaxPrecision);
2989  s_MultiplyByte(multiplier, 256, temp);
2990  }
2991 
2992  s_ArrayToString(product, m_Scale, s);
2993  return result;
2994 }
2995 
2996 
2997 
2998 static int s_Div256(const char* value, char* product, int base)
2999 {
3000  int res = 0;
3001  char* const initial = product;
3002 
3003  while (*value < base) {
3004  res = res % 256 * base + (int)*value;
3005  ++value;
3006  while (product == initial && *value < base && res < 256) {
3007  res = res * base + (int)*value;
3008  ++value;
3009  }
3010  *product = (char) (res / 256);
3011  ++product;
3012  }
3013  *product = base;
3014  return res % 256;
3015 }
3016 
3017 
3018 void CDB_Numeric::x_MakeFromString(unsigned int precision, unsigned int scale,
3019  const CTempString& s)
3020 {
3021 
3022  if (m_Precision == 0 && precision == 0 && !s.empty()) {
3023  precision = (unsigned int) s.size();
3024  if (scale == 0) {
3025  SIZE_TYPE dot_pos = s.find('.');
3026  scale = (dot_pos == NPOS) ? 0 : precision - (unsigned int) dot_pos;
3027  if (scale > 1)
3028  --scale;
3029  }
3030  }
3031 
3034  "illegal precision " + NStr::NumericToString(precision),
3035  100 );
3037  scale > precision,
3038  "scale (" + NStr::NumericToString(scale)
3039  + ") cannot be more than precision ("
3041  101 );
3042 
3043  bool is_negative= false;
3045  if (val != s.end() && *val == '-') {
3046  is_negative= true;
3047  ++val;
3048  }
3049 
3050  while (val != s.end() && *val == '0') {
3051  ++val;
3052  }
3053 
3054  char buff1[kMaxPrecision + 1];
3055  unsigned int n = 0;
3056  while (val != s.end() && n < precision) {
3057  if (*val >= '0' && *val <= '9') {
3058  buff1[n++] = *val - '0';
3059  } else if (*val == '.') {
3060  break;
3061  } else {
3062  DATABASE_DRIVER_ERROR("string cannot be converted: " + string(s),
3063  102 );
3064  }
3065  ++val;
3066  }
3067 
3069  precision - n < scale,
3070  "string cannot be converted because of overflow: " + string(s),
3071  103 );
3072 
3073  unsigned int dec = 0;
3074  if (val != s.end() && *val == '.') {
3075  ++val;
3076  while (val != s.end() && dec < scale) {
3077  if (*val >= '0' && *val <= '9') {
3078  buff1[n++] = *val - '0';
3079  } else {
3081  ("string cannot be converted: " + string(s), 102);
3082  }
3083  ++dec;
3084  ++val;
3085  }
3086  }
3087 
3088  while (dec++ < scale) {
3089  buff1[n++] = 0;
3090  }
3091  if (n == 0) {
3092  buff1[n++] = 0;
3093  }
3094  buff1[n] = 10;
3095 
3096  char buff2[kMaxPrecision + 1];
3097  char* p[2];
3098  p[0] = buff1;
3099  p[1] = buff2;
3100 
3101  // Setup everything now
3102  memset(m_Body, 0, sizeof(m_Body));
3103  if (is_negative) {
3104  m_Body[0] = 1/*sign*/;
3105  }
3106  unsigned char* num = m_Body + s_NumericBytesPerPrec[precision - 1] - 1;
3107  for (int i = 0; *p[i] || p[i][1] != 10; i = 1 - i) {
3108  _ASSERT(num > m_Body);
3109  *num = s_Div256(p[i], p[1-i], 10);
3110  --num;
3111  }
3112 
3114  m_Scale = scale;
3115  SetNULL(false);
3116 }
3117 
3119 {
3121  v.GetType() != eDB_Numeric,
3122  string("wrong type of CDB_Object: ") + GetTypeName(v.GetType(), false),
3123  2 );
3124  *this = (const CDB_Numeric&)v;
3125 }
3126 
3128 
3129 
Convenience extension of basic_string, supporting implicit conversion to const TChar* in most situati...
Definition: types.hpp:99
size_t Tell() const
size_t Read(void *buff, size_t nof_bytes)
size_t GetDataSize() const
size_t Peek(void *buff, size_t nof_bytes) const
size_t Truncate(size_t nof_bytes=kMax_BlobSize)
long Seek(long offset, EWhence whence)
size_t PeekAt(void *buff, size_t start, size_t n) const
size_t Append(const void *buff, size_t nof_bytes)
CObjectFor –.
Definition: ncbiobj.hpp:2335
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
const value_slice::CValueConvert< value_slice::SRunTimeSqlCP, FROM > ConvertSQL(const FROM &value)
char TChar
Definition: interfaces.hpp:78
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
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 NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:581
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
#define DATABASE_DRIVER_ERROR(message, err_code)
Definition: exception.hpp:740
#define CHECK_DRIVER_ERROR(failed, message, err_code)
Definition: exception.hpp:765
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:2234
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:2421
CDB_BigDateTime(CTime::EInitMode mode=CTime::eEmpty, ESQLType sql_type=eDateTime, TOffset offset=null)
Definition: types.cpp:2546
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:1252
virtual ~CDB_Bit(void)
Definition: types.cpp:2730
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
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:2025
virtual EDB_Type GetType(void) const
Definition: types.cpp:2595
EDB_Type
Definition: types.hpp:52
Int4 m_Val
Definition: types.hpp:381
virtual EDB_Type GetType() const
Definition: types.cpp:2224
Uint2 GetMinutes(void) const
Definition: types.cpp:2401
virtual ~CDB_Int(void)
Definition: types.cpp:678
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:1533
size_t x_Append(const void *buff, size_t nof_bytes)
Definition: types.cpp:2055
const char * m_Char
Definition: types.hpp:277
~CWString(void)
Definition: types.cpp:184
virtual CDB_Object * Clone(void) const
Definition: types.cpp:2416
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:2531
virtual CDB_Object * Clone() const
Definition: types.cpp:1371
virtual void AssignNULL()
Definition: types.cpp:550
CDB_Float()
Definition: types.cpp:1832
virtual EDB_Type GetType() const
Definition: types.cpp:1366
TOffset m_Offset
Definition: types.hpp:1127
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:1539
void x_MakeUCS2LEString(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.cpp:378
const char * GetSQLTypeName(ESyntax syntax)
Definition: types.cpp:2572
virtual EDB_Type GetType() const
Definition: types.cpp:1234
CDB_Int()
Definition: types.cpp:664
CDB_VarBinaryMax(void)
Definition: types.cpp:2141
virtual EDB_Type GetType() const
Definition: types.cpp:1793
virtual CDB_Object * Clone() const
Definition: types.cpp:1615
size_t m_Size
Definition: types.hpp:703
CDB_Char & operator=(const CDB_Char &v)
Definition: types.cpp:1305
Uint1 m_Val
Definition: types.hpp:1153
virtual CDB_Object * Clone() const
Definition: types.cpp:688
CDB_VarCharMax & operator=(const string &s)
Definition: types.hpp:1005
size_t m_Size
Definition: types.hpp:808
void x_MakeFromString(unsigned int precision, unsigned int scale, const CTempString &s)
Definition: types.cpp:3018
CDB_DateTime & Assign(Int4 d, Int4 s300)
Definition: types.cpp:2481
CDB_VarBinary & operator=(const CDB_VarBinary &v)
Definition: types.cpp:1597
TDBTimeU m_DBTime
Definition: types.hpp:1040
CDB_LongChar(size_t s=8191)
Definition: types.cpp:1421
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:785
CDB_Numeric & operator=(const char *val)
Definition: types.cpp:2865
void SetValue(const char *str, size_t len, EEncoding enc=eEncoding_Unknown)
Definition: types.cpp:1502
size_t GetSymbolNum(void) const
Definition: types.cpp:390
void SetValue(const void *v, size_t v_size)
Definition: types.cpp:1759
EBulkEnc
Definition: types.hpp:85
TStringUCS2 m_UCS2LEString
Definition: types.hpp:286
virtual ~CDB_LongBinary()
Definition: types.cpp:1822
virtual EDB_Type GetType() const
Definition: types.cpp:775
virtual EDB_Type GetType() const
Definition: types.cpp:2164
TDBTimeI m_DBTime
Definition: types.hpp:1071
void x_MakeUTF8String(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.cpp:355
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:2174
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:1626
virtual size_t Append(const void *buff, size_t nof_bytes)
Definition: types.cpp:2002
virtual EDB_Type GetType() const
Definition: types.cpp:1609
Uint1 m_Precision
Definition: types.hpp:1203
CDB_BigInt()
Definition: types.cpp:800
void x_MakeWString(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.cpp:318
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:1620
virtual EDB_Type GetType() const
Definition: types.cpp:1695
virtual EDB_Type GetType() const
Definition: types.cpp:819
CSqlString m_String
Definition: types.hpp:281
const wchar_t * m_WChar
Definition: types.hpp:279
string GetLogString(void) const
Definition: types.cpp:624
ESQLType m_SQLType
Definition: types.hpp:1126
CDB_LongBinary & operator=(const CDB_LongBinary &v)
Definition: types.cpp:1778
virtual ~CDB_Text(void)
Definition: types.cpp:2193
virtual ~CDB_Double(void)
Definition: types.cpp:1901
CTime m_NCBITime
Definition: types.hpp:1070
virtual CDB_Object * Clone() const
Definition: types.cpp:734
CDB_Char(size_t s=1)
Definition: types.cpp:1268
const char * AsCString(void) const
Definition: types.hpp:532
CDB_VarCharMax(void)
Definition: types.cpp:2244
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:693
unsigned int m_Status
Definition: types.hpp:1042
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:1706
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:2131
virtual ~CDB_TinyInt(void)
Definition: types.cpp:770
CDB_Numeric & Assign(unsigned int precision, unsigned int scale, const unsigned char *arr)
Definition: types.cpp:2839
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:1712
void SetValue(const char *str, size_t len, EEncoding enc=eEncoding_Unknown)
Definition: types.cpp:1348
virtual EDB_Type GetType() const
Definition: types.cpp:2750
static CDB_Object * Create(EDB_Type type, size_t size=1)
Definition: types.cpp:556
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:1804
unsigned max_logged_param_length
Definition: types.hpp:1210
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:1869
virtual EDB_Type GetType() const =0
void x_MakeString(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.cpp:276
CDB_Object(bool is_null=true)
Definition: types.cpp:539
virtual size_t Append(const void *buff, size_t nof_bytes)
Definition: types.cpp:2202
const TStringUCS2 & AsUCS2_LE(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.hpp:205
virtual CDB_Object * Clone() const
Definition: types.cpp:780
virtual CDB_Object * Clone() const
Definition: types.cpp:824
virtual EDB_Type GetType() const
Definition: types.cpp:683
CWString(void)
Definition: types.cpp:80
CDB_SmallDateTime & operator=(const CTime &t)
Definition: types.cpp:2369
virtual CDB_Object * Clone(void) const
Definition: types.cpp:2526
void x_SetEncoding(EBulkEnc e)
Definition: types.cpp:2042
CDB_Stream & Assign(const CDB_Stream &v)
Definition: types.cpp:1961
CWString & operator=(const CWString &str)
Definition: types.cpp:189
CDB_Stream()
Definition: types.cpp:1941
const CTime & Value(void) const
Definition: types.cpp:2381
wstring m_WString
Definition: types.hpp:283
virtual CDB_Object * Clone() const
Definition: types.cpp:1240
virtual ~CDB_VarBinary(void)
Definition: types.cpp:1578
virtual size_t Peek(void *buff, size_t nof_bytes) const
Definition: types.cpp:1992
virtual CDB_Object * Clone() const
Definition: types.cpp:2308
void SetValue(const void *v, size_t v_size)
Definition: types.cpp:1663
void x_CalculateEncoding(EEncoding str_enc) const
Definition: types.cpp:231
Int4 Value() const
Definition: types.hpp:373
const wchar_t * AsUnicode(EEncoding enc) const
Definition: types.cpp:1011
unsigned int m_Status
Definition: types.hpp:1073
CDB_TinyInt()
Definition: types.cpp:756
CRef< TValue > m_Value
Definition: types.hpp:772
virtual ~CDB_Object()
Definition: types.cpp:545
void Clear(void)
Definition: types.cpp:419
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:739
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:1246
const wstring & AsUnicode(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.hpp:214
CDB_Image(void)
Definition: types.cpp:2103
CObjectFor< string > TValue
Definition: types.hpp:735
size_t m_Size
Definition: types.hpp:771
virtual ~CDB_Stream()
Definition: types.cpp:2034
virtual EDB_Type GetType() const
Definition: types.cpp:2879
virtual ~CDB_BigInt(void)
Definition: types.cpp:814
virtual void Truncate(size_t nof_bytes=kMax_Int)
Definition: types.cpp:2019
virtual bool MoveTo(size_t byte_number)
Definition: types.cpp:2008
Uint2 GetDays(void) const
Definition: types.cpp:2391
size_t Size(void) const
Definition: types.hpp:522
virtual EDB_Type GetType(void) const
Definition: types.cpp:2411
CDB_LongBinary(size_t s=8191)
Definition: types.cpp:1733
virtual ~CDB_Float(void)
Definition: types.cpp:1846
void x_StringToUTF8(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.cpp:256
virtual EDB_Type GetType() const
Definition: types.cpp:2303
CDB_Bit()
Definition: types.cpp:2711
CDB_LongChar & operator=(const CDB_LongChar &v)
Definition: types.cpp:1459
virtual EDB_Type GetType() const
Definition: types.cpp:1522
virtual size_t Append(const void *buff, size_t nof_bytes)
Definition: types.cpp:2282
string Value() const
Definition: types.cpp:2964
CObjectFor< string > TValue
Definition: types.hpp:806
CDB_String(void)
Definition: types.cpp:911
Int2 m_Val
Definition: types.hpp:408
CDB_Bit & operator=(const int &i)
Definition: types.cpp:2734
CDB_SmallDateTime(CTime::EInitMode mode=CTime::eEmpty)
Definition: types.cpp:2325
CDB_Double()
Definition: types.cpp:1887
CDB_VarChar(void)
Definition: types.cpp:1137
virtual EDB_Type GetType() const
Definition: types.cpp:1859
virtual CDB_Object * Clone() const
Definition: types.cpp:1528
void SetNULL(bool flag=true)
Definition: types.hpp:326
int m_AvailableValueType
Definition: types.hpp:275
EBulkEnc m_BulkInsertionEnc
Definition: types.hpp:562
virtual EDB_Type GetType() const
Definition: types.cpp:1912
CDB_DateTime & operator=(const CTime &t)
Definition: types.cpp:2470
static CTimeFormat GetTimeFormat(ESyntax syntax, ESQLType sql_type=eDateTime, TOffset offset=null)
Definition: types.cpp:2623
CDB_Text & operator=(const CDB_Text &text)
Definition: types.cpp:2218
Uint1 m_Val
Definition: types.hpp:435
virtual ~CDB_VarCharMax(void)
Definition: types.cpp:2273
CDB_BigDateTime & Assign(const CTime &t, ESQLType sql_type=eDateTime, TOffset offset=null)
Definition: types.cpp:2562
float m_Val
Definition: types.hpp:833
virtual EDB_Type GetType(void) const
Definition: types.cpp:2521
CDB_Image & operator=(const CDB_Image &image)
Definition: types.cpp:2116
CMemStore * m_Store
Definition: types.hpp:901
Int4 GetDays(void) const
Definition: types.cpp:2501
double m_Val
Definition: types.hpp:858
virtual size_t Read(void *buff, size_t nof_bytes)
Definition: types.cpp:1987
void SetEncoding(EBulkEnc e)
Definition: types.cpp:2277
EEncoding m_StringEncoding
Definition: types.hpp:276
virtual ~CDB_VarBinaryMax(void)
Definition: types.cpp:2155
virtual CDB_Object * Clone() const
Definition: types.cpp:1701
virtual CDB_Object * Clone() const
Definition: types.cpp:2755
CDB_Float & operator=(const float &i)
Definition: types.cpp:1851
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:2760
virtual ~CDB_Binary()
Definition: types.cpp:1724
virtual ~CDB_LongChar()
Definition: types.cpp:1551
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:1376
virtual ~CDB_DateTime(void)
Definition: types.cpp:2465
static const char * GetTypeName(EDB_Type db_type, bool throw_on_unknown=true)
Definition: types.cpp:586
Uint1 m_Scale
Definition: types.hpp:1204
void SetValue(const void *v, size_t l)
Definition: types.cpp:1582
virtual EDB_Type GetType() const
Definition: types.cpp:2121
virtual CDB_Object * Clone() const
Definition: types.cpp:1799
Int4 Get300Secs(void) const
Definition: types.cpp:2511
EBulkEnc m_Encoding
Definition: types.hpp:897
static pair< ESyntax, ESQLType > Identify(const CTempString &s)
Definition: types.cpp:2676
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:829
CRef< TValue > m_Value
Definition: types.hpp:736
CDB_VarBinaryMax & operator=(const CDB_VarBinaryMax &v)
Definition: types.cpp:2159
virtual void AssignNULL()
Definition: types.cpp:1981
virtual CDB_Object * Clone() const
Definition: types.cpp:2169
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:3118
const char * Data(void) const
Definition: types.hpp:527
CDB_SmallInt()
Definition: types.cpp:710
CDB_VarCharMax & SetValue(const string &s, EEncoding enc=eEncoding_Unknown)
Definition: types.hpp:992
virtual ~CDB_Char(void)
Definition: types.cpp:1392
const CTime & Value(void) const
Definition: types.cpp:2491
CDB_Binary & operator=(const CDB_Binary &v)
Definition: types.cpp:1682
void Assign(const CDB_String &other)
Definition: types.cpp:1018
CRef< TValue > m_Value
Definition: types.hpp:810
CDB_String & operator=(const CDB_String &other)
Definition: types.cpp:973
virtual ~CDB_Numeric(void)
Definition: types.cpp:2834
virtual size_t PeekAt(void *buff, size_t start, size_t nof_bytes) const
Definition: types.cpp:1997
virtual ~CDB_SmallInt(void)
Definition: types.cpp:724
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:2605
void GetBulkInsertionData(CTempString *ts, bool convert_raw_bytes=false) const
Definition: types.cpp:1084
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:1810
CDB_SmallDateTime & Assign(Uint2 days, Uint2 minutes)
Definition: types.cpp:2358
virtual ~CDB_Image(void)
Definition: types.cpp:2112
void Assign(const char *str, string::size_type size=string::npos, EEncoding enc=eEncoding_Unknown)
Definition: types.cpp:432
virtual CDB_Object * Clone() const
Definition: types.cpp:2229
CDB_Text(void)
Definition: types.cpp:2184
CStringUTF8 m_UTF8String
Definition: types.hpp:285
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:1381
CDB_Binary(size_t s=1)
Definition: types.cpp:1641
size_t m_Size
Definition: types.hpp:653
virtual CDB_Object * Clone() const
Definition: types.cpp:1917
Int8 m_Val
Definition: types.hpp:463
const string & x_GetWString() const
Definition: types.hpp:566
virtual CDB_Object * Clone() const
Definition: types.cpp:2126
virtual ~CDB_String(void)
Definition: types.cpp:968
CDB_VarChar & SetValue(const string &s, EEncoding enc=eEncoding_Unknown)
Definition: types.cpp:1189
virtual size_t Size() const
Definition: types.cpp:2014
virtual void AssignValue(const CDB_Object &v)
Definition: types.cpp:1922
virtual ~CDB_SmallDateTime(void)
Definition: types.cpp:2354
bool IsNULL() const
Definition: types.hpp:303
CRef< CWString > m_WString
Definition: types.hpp:561
virtual CDB_Object * ShallowClone() const
Definition: types.cpp:2313
void x_UTF8ToString(EEncoding str_enc=eEncoding_Unknown) const
Definition: types.cpp:240
CDB_DateTime(CTime::EInitMode mode=CTime::eEmpty)
Definition: types.cpp:2436
virtual CDB_Object * Clone(void) const
Definition: types.cpp:2600
CDB_Double & operator=(const double &i)
Definition: types.cpp:1905
virtual ~CDB_VarChar(void)
Definition: types.cpp:1184
virtual CDB_Object * Clone() const
Definition: types.cpp:2885
void SetEncoding(EBulkEnc e)
Definition: types.cpp:2197
virtual EDB_Type GetType() const
Definition: types.cpp:729
virtual CDB_Object * Clone() const
Definition: types.cpp:1864
unsigned char m_Body[33]
Definition: types.hpp:1205
@ 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
@ eChar
Definition: types.hpp:267
@ eString
Definition: types.hpp:269
@ eUCS2LEString
Definition: types.hpp:272
@ eWString
Definition: types.hpp:270
@ eWChar
Definition: types.hpp:268
@ eUTF8String
Definition: types.hpp:271
@ eDateTimeOffset
DATETIMEOFFSET (MS); no Sybase equivalent.
Definition: types.hpp:1086
@ eDateTime
DATETIME2 (MS), BIGDATETIME (Sybase)
Definition: types.hpp:1085
@ eTime
TIME (MS), (BIG)TIME (Sybase)
Definition: types.hpp:1084
@ eDate
DATE (MS, Sybase)
Definition: types.hpp:1083
#define NCBI_CURRENT_FUNCTION
Get current function name.
Definition: ncbidiag.hpp:142
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
#define NCBI_CATCH_ALL_X(err_subcode, message)
Definition: ncbiexpt.hpp:619
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
void AddReference(void) const
Add reference to object.
Definition: ncbiobj.hpp:489
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty – pointing to an object and has a non-null value.
Definition: ncbiobj.hpp:726
void RemoveReference(void) const
Remove reference to object.
Definition: ncbiobj.hpp:500
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
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
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
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
EEncoding
Definition: ncbistr.hpp:199
const_iterator end() const
Return an iterator to the string's ending position (one past the end of the represented sequence)
Definition: tempstr.hpp:306
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
Definition: ncbistr.cpp:3944
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:6974
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
Definition: ncbistr.hpp:5432
#define NPOS
Definition: ncbistr.hpp:133
static SIZE_TYPE GetSymbolCount(const CTempString &src)
Get the number of symbols (code points) in UTF8 string.
Definition: ncbistr.cpp:6669
CTempString & assign(const char *src_str, size_type len)
Assign new values to the content of the a string.
Definition: tempstr.hpp:733
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5086
const char * const_iterator
Definition: tempstr.hpp:71
const char * data(void) const
Return a pointer to the array represented.
Definition: tempstr.hpp:313
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
Definition: tempstr.hpp:334
Uint2 TCharUCS2
Type for character in UCS-2 encoding.
Definition: ncbistr.hpp:3849
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3891
basic_string< TCharUCS2 > TStringUCS2
Type for string in UCS-2 encoding.
Definition: ncbistr.hpp:3851
void clear(void)
Clears the string.
Definition: tempstr.hpp:351
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
size_type find(const CTempString match, size_type pos=0) const
Find the first instance of the entire matching string within the current string, beginning at an opti...
Definition: tempstr.hpp:655
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
Definition: ncbistr.cpp:68
size_type size(void) const
Return the length of the represented array.
Definition: tempstr.hpp:327
const_iterator begin() const
Return an iterator to the string's starting position.
Definition: tempstr.hpp:299
@ 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
@ fNonAscii_Quote
Octal for all non-ASCII characters.
Definition: ncbistr.hpp:2735
@ fNewLine_Quote
Display "\n" instead of actual linebreak.
Definition: ncbistr.hpp:2730
EInitMode
Which initial value to use for time.
Definition: ncbitime.hpp:299
Int4 days
days from 1/1/1900
Definition: ncbitime.hpp:115
CTime & SetTimeDBI(const TDBTimeI &t)
Set time using database format time, TDBTimeI.
Definition: ncbitime.cpp:1496
CTime & SetTimeDBU(const TDBTimeU &t)
Set time using database format time, TDBTimeU.
Definition: ncbitime.cpp:1481
TDBTimeI GetTimeDBI(void) const
Get time in database format time, TDBTimeI.
Definition: ncbitime.cpp:1467
TDBTimeU GetTimeDBU(void) const
Get time in database format time, TDBTimeU.
Definition: ncbitime.cpp:1454
Uint2 days
Days from 1/1/1900.
Definition: ncbitime.hpp:109
Uint2 time
Minutes from the beginning of current day.
Definition: ncbitime.hpp:110
Int4 time
x/300 seconds from the beginning of current day
Definition: ncbitime.hpp:116
@ 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
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
int i
yy_size_t n
int len
static void text(MDB_val *v)
Definition: mdb_dump.c:62
mdb_mode_t mode
Definition: lmdb++.h:38
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
EIPRangeType t
Definition: ncbi_localip.c:101
#define HAVE_WSTRING
Definition: ncbiconf_msvc.h:69
int isalpha(Uchar c)
Definition: ncbictype.hpp:61
Defines: CTimeFormat - storage class for time format.
T max(T x_, T y_)
T min(T x_, T y_)
static BOOL number
Definition: pcregrep.c:193
Definition: type.c:6
#define _TROUBLE
#define _ASSERT
else result
Definition: token2.c:20
size_t my_strnlen(const TChar *str, size_t maxlen)
Definition: types.cpp:845
NCBI_PARAM_DEF(unsigned int, dbapi, max_logged_param_length, 255)
CRef< CWString > MakeString(const string &s, string::size_type size, EEncoding enc=eEncoding_Unknown)
Definition: types.cpp:858
static int s_Div256(const char *value, char *product, int base)
Definition: types.cpp:2998
static void CheckStringTruncation(size_t cur_len, size_t max_len)
Definition: types.cpp:517
static const unsigned int kMaxPrecision
Definition: types.cpp:2901
static basic_string< TChar >::size_type get_string_size_varchar(const TChar *str, typename basic_string< TChar >::size_type len)
Definition: types.cpp:1119
static int s_NumericBytesPerPrec[]
Definition: types.cpp:2892
static void CheckBinaryTruncation(size_t cur_len, size_t max_len)
Definition: types.cpp:527
static char * s_ArrayToString(const unsigned char *array, int scale, char *s)
Definition: types.cpp:2938
void s_MakeLittleEndian(TStringUCS2 &s)
Definition: types.cpp:53
static string::size_type get_string_size_longchar(const char *str, string::size_type len)
Definition: types.cpp:1399
static void s_MultiplyByte(unsigned char *product, int num, const unsigned char *multiplier)
Definition: types.cpp:2915
static void s_DoCarry(unsigned char *product)
Definition: types.cpp:2904
Modified on Wed Jul 24 17:16:32 2024 by modify_doxy.py rev. 669887