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

Go to the SVN repository for this file.

1 #ifndef DBAPI_DRIVER___DBAPI_DRIVER_CONVERT__HPP
2 #define DBAPI_DRIVER___DBAPI_DRIVER_CONVERT__HPP
3 
4 /* $Id: dbapi_driver_convert.hpp 92224 2020-12-23 19:08:29Z grichenk $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NTOICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Sergey Sikorskiy
30  *
31  * File Description:
32  *
33  */
34 
35 #include <dbapi/driver/public.hpp>
37 // Future development ...
38 // #include <dbapi/driver/dbapi_driver_value_slice.hpp>
39 
40 #include <vector>
41 #include <set>
42 #include <stack>
43 
45 
46 namespace value_slice
47 {
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 template <>
52 {
53 public:
54  typedef const CDB_Result obj_type;
55  typedef SSafeCP CP;
56 
58  : m_Value(&value)
59  {
60  }
61 
62 public:
63  operator bool(void) const
64  {
65  CDB_Bit db_obj;
66  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
67  if (db_obj.IsNULL()) {
69  }
70  return db_obj.Value() != 0;
71  }
72  operator Uint1(void) const
73  {
74  return ConvertFrom<Uint1, CDB_TinyInt>();
75  }
76  operator Int2(void) const
77  {
78  return ConvertFrom<Int2, CDB_SmallInt>();
79  }
80  operator Int4(void) const
81  {
82  return ConvertFrom<Int4, CDB_Int>();
83  }
84  operator Int8(void) const
85  {
86  return ConvertFrom<Int8, CDB_BigInt>();
87  }
88  operator float(void) const
89  {
90  return ConvertFrom<float, CDB_Float>();
91  }
92  operator double(void) const
93  {
94  return ConvertFrom<double, CDB_Double>();
95  }
96  operator string(void) const
97  {
98  CDB_VarChar db_obj;
99  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
100  if (db_obj.IsNULL()) {
101  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("NULL to string");
102  }
103  return string(db_obj.Data(), db_obj.Size());
104  }
105  operator CTime(void) const
106  {
107  return ConvertFrom<const CTime&, CDB_DateTime>();
108  }
109 
110 private:
111  template <typename TO, typename FROM>
112  TO ConvertFrom(void) const
113  {
114  FROM db_obj;
115  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
116  if (db_obj.IsNULL()) {
118  }
119  return MakeCP<CP>(db_obj.Value());
120  }
121 
122 private:
124 };
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 template <>
129 {
130 public:
131  typedef const CDB_Result obj_type;
132  typedef SSafeSqlCP CP;
133 
135  : m_Value(value.m_Value)
136  {
137  }
139  : m_Value(&value)
140  {
141  }
142 
143 public:
144  operator bool(void) const
145  {
146  const int item_num = m_Value->CurrentItemNo();
147  const EDB_Type db_type = m_Value->ItemDataType(item_num);
148 
149  // *null* is reported as eDB_Int by the ctlib driver.
150  // That means that *null* can be checked using Int4 type only.
151  if (db_type == eDB_Int) {
152  CDB_Int db_obj_int;
153 
154  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj_int);
155  if (db_obj_int.IsNULL()) {
156  return bool();
157  }
158 
159  NCBI_REPORT_CONVERSION_ERROR("non-NULL CDB_Int ("
160  << db_obj_int.Value()
161  << ") to bool");
162  }
163 
164  CDB_Bit db_obj;
165  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
166 
167  if (db_obj.IsNULL()) {
168  return bool();
169  }
170 
171  return db_obj.Value() != 0;
172  }
173  operator Uint1(void) const
174  {
175  return ConvertFrom<Uint1, CDB_TinyInt>();
176  }
177  operator Int2(void) const
178  {
179  return ConvertFrom<Int2, CDB_SmallInt>();
180  }
181  operator Int4(void) const
182  {
183  CDB_Int db_obj;
184  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
185 
186  if (db_obj.IsNULL()) {
187  return Int4();
188  }
189 
190  // We are using SSafeCP intentionally here ...
191  return MakeCP<SSafeCP>(db_obj.Value());
192  }
193  operator Int8(void) const
194  {
195  return ConvertFrom<Int8, CDB_BigInt>();
196  }
197  operator float(void) const
198  {
199  return ConvertFrom<float, CDB_Float>();
200  }
201  operator double(void) const
202  {
203  return ConvertFrom<double, CDB_Double>();
204  }
205  operator string(void) const
206  {
207  const int item_num = m_Value->CurrentItemNo();
208  const EDB_Type db_type = m_Value->ItemDataType(item_num);
209 
210  // *null* is reported as eDB_Int by the ctlib driver.
211  // That means that *null* can be checked using Int4 type only.
212  CDB_Int db_obj_int;
213  if (db_type == eDB_Int) {
214 
215  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj_int);
216  if (db_obj_int.IsNULL()) {
217  return string();
218  }
219 
220  NCBI_REPORT_CONVERSION_ERROR("non-NULL CDB_Int("
221  << db_obj_int.Value()
222  << ") to string");
223  }
224 
225  CDB_VarChar db_obj;
226  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
227  if (db_obj.IsNULL()) {
228  return string();
229  }
230  return string(db_obj.Data(), db_obj.Size());
231  }
232  operator CTime(void) const
233  {
234  return ConvertFrom<CTime, CDB_DateTime>();
235  }
236 
237 private:
238  template <typename TO, typename FROM>
239  TO ConvertFrom(void) const
240  {
241  const int item_num = m_Value->CurrentItemNo();
242  const EDB_Type db_type = m_Value->ItemDataType(item_num);
243 
244  // *null* is reported as eDB_Int by the ctlib driver.
245  // That means that *null* can be checked using Int4 type only.
246  if (db_type == eDB_Int) {
247  CDB_Int db_obj_int;
248 
249  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj_int);
250  if (db_obj_int.IsNULL()) {
251  return TO();
252  }
253 
254  NCBI_REPORT_CONVERSION_ERROR("non-NULL CDB_Int("
255  << db_obj_int.Value()
256  << ')');
257  }
258 
259  FROM db_obj;
260  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
261 
262  if (db_obj.IsNULL()) {
263  return TO();
264  }
265 
266  // We are using SSafeCP intentionally here ...
267  return MakeCP<SSafeCP>(db_obj.Value());
268  }
269 
270 private:
272 };
273 
274 ////////////////////////////////////////////////////////////////////////////////
275 template <>
277 {
278 public:
279  typedef const CDB_Result obj_type;
280 
282 
283 public:
284  operator bool(void) const;
285  operator Int1(void) const;
286  operator Uint1(void) const;
287  operator Int2(void) const;
288  operator Uint2(void) const;
289  operator Int4(void) const;
290  operator Uint4(void) const;
291  operator Int8(void) const;
292  operator Uint8(void) const;
293  operator float(void) const;
294  operator double(void) const;
295  operator string(void) const;
296  operator CTime(void) const;
297 
298 private:
299  /* future development ...
300  template <typename TO, typename FROM>
301  TO ConvertFrom(void) const
302  {
303  FROM db_obj;
304  wrapper<FROM> obj_wrapper(db_obj);
305 
306  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
307  if (obj_wrapper.is_null()) {
308  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("NULL");
309  }
310 
311  // return MakeCP<SRunTimeCP>(obj_wrapper.get_value());
312  return Convert(obj_wrapper.get_value());
313  }
314  */
315 
316  template <typename TO, typename FROM>
317  TO ConvertFrom(void) const
318  {
319  FROM db_obj;
320 
321  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
322  if (db_obj.IsNULL()) {
324  }
325 
326  return NCBI_CONVERT_TO(Convert(db_obj.Value()), TO);
327  }
328 
329  template <typename TO, typename FROM>
330  TO ConvertFromStr(void) const
331  {
332  FROM db_obj;
333 
334  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
335  if (db_obj.IsNULL()) {
337  }
338 
339  return Convert(string(static_cast<const char*>(db_obj.Data()),
340  db_obj.Size()));
341  }
342 
343  template <typename TO, typename FROM>
344  TO ConvertFromChar(const int item_num) const
345  {
346  FROM db_obj(m_Value->ItemMaxSize(item_num));
347 
348  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
349  if (db_obj.IsNULL()) {
350  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("NULL fixed-length string");
351  }
352 
353  return Convert(string(static_cast<const char*>(db_obj.Data()),
354  db_obj.Size()));
355  }
356 
357  template <typename TO, typename FROM>
358  TO ConvertFromLOB(void) const
359  {
360  FROM db_obj;
361  string result;
362 
363  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
364  if (db_obj.IsNULL()) {
366  }
367 
368  result.resize(db_obj.Size());
369  db_obj.Read(const_cast<void*>(static_cast<const void*>(result.data())),
370  db_obj.Size()
371  );
372 
373  return Convert(result);
374  }
375 
376  template <typename TO, typename FROM>
377  TO Convert2CTime(void) const
378  {
379  FROM db_obj;
380 
381  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
382  if (db_obj.IsNULL()) {
384  }
385 
386  return CTime(time_t(Convert(db_obj.Value())));
387  }
388 
389  template <typename TO>
390  void ReadCDBObject(TO& value) const
391  {
392  const int item_num = m_Value->CurrentItemNo();
393  const EDB_Type db_type = m_Value->ItemDataType(item_num);
394 
395  switch (db_type) {
396  case eDB_Int:
397  value = ConvertFrom<TO, CDB_Int>();
398  break;
399  case eDB_SmallInt:
400  value = ConvertFrom<TO, CDB_SmallInt>();
401  break;
402  case eDB_TinyInt:
403  value = ConvertFrom<TO, CDB_TinyInt>();
404  break;
405  case eDB_BigInt:
406  value = ConvertFrom<TO, CDB_BigInt>();
407  break;
408  case eDB_VarChar:
409  value = ConvertFromStr<TO, CDB_VarChar>();
410  break;
411  case eDB_Char:
412  value = ConvertFromChar<TO, CDB_Char>(item_num);
413  break;
414  case eDB_VarBinary:
415  value = ConvertFromStr<TO, CDB_VarBinary>();
416  break;
417  case eDB_Binary:
418  value = ConvertFromChar<TO, CDB_Binary>(item_num);
419  break;
420  case eDB_Float:
421  value = ConvertFrom<TO, CDB_Float>();
422  break;
423  case eDB_Double:
424  value = ConvertFrom<TO, CDB_Double>();
425  break;
426  // case eDB_DateTime:
427  // value = ConvertFrom<TO, CDB_DateTime>();
428  // case eDB_SmallDateTime:
429  // value = ConvertFrom<TO, CDB_SmallDateTime>();
430  case eDB_Text:
431  value = ConvertFromLOB<TO, CDB_Text>();
432  break;
433  case eDB_Image:
434  value = ConvertFromLOB<TO, CDB_Image>();
435  break;
436  case eDB_VarCharMax:
437  value = ConvertFromLOB<TO, CDB_VarCharMax>();
438  break;
439  case eDB_VarBinaryMax:
440  value = ConvertFromLOB<TO, CDB_VarBinaryMax>();
441  break;
442  case eDB_Bit:
443  value = ConvertFrom<TO, CDB_Bit>();
444  break;
445  case eDB_Numeric:
446  value = ConvertFrom<TO, CDB_Numeric>();
447  break;
448  case eDB_LongChar:
449  value = ConvertFromChar<TO, CDB_LongChar>(item_num);
450  break;
451  case eDB_LongBinary:
452  {
453  CDB_LongBinary db_obj(m_Value->ItemMaxSize(item_num));
454 
455  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
456  if (db_obj.IsNULL()) {
458  ("NULL long binary");
459  }
460 
461  value = Convert(string(static_cast<const char*>(db_obj.Value()), db_obj.DataSize()));
462  }
463  break;
464  default:
465  NCBI_REPORT_CONVERSION_ERROR("CDB_Object of unsupported type "
466  << db_type);
467  }
468  }
469 
470 private:
472 };
473 
474 ////////////////////////////////////////////////////////////////////////////////
475 template <>
477 {
478 public:
479  typedef const CDB_Result obj_type;
480 
482 
483 public:
484  operator bool(void) const;
485  operator Int1(void) const;
486  operator Uint1(void) const;
487  operator Int2(void) const;
488  operator Uint2(void) const;
489  operator Int4(void) const;
490  operator Uint4(void) const;
491  operator Int8(void) const;
492  operator Uint8(void) const;
493  operator float(void) const;
494  operator double(void) const;
495  operator string(void) const;
496  operator CTime(void) const;
497 
498 private:
499  template <typename TO, typename FROM>
500  TO ConvertFrom(void) const
501  {
502  FROM db_obj;
503 
504  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
505  if (db_obj.IsNULL()) {
506  return TO();
507  }
508 
509  return NCBI_CONVERT_TO(Convert(db_obj.Value()), TO);
510  }
511 
512  template <typename TO, typename FROM>
513  TO ConvertFromStr(void) const
514  {
515  FROM db_obj;
516 
517  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
518  if (db_obj.IsNULL()) {
519  return TO();
520  }
521 
522  return Convert(string(static_cast<const char*>(db_obj.Data()),
523  db_obj.Size()));
524  }
525 
526  template <typename TO, typename FROM>
527  TO ConvertFromChar(const int item_num) const
528  {
529  FROM db_obj(m_Value->ItemMaxSize(item_num));
530 
531  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
532  if (db_obj.IsNULL()) {
533  return TO();
534  }
535 
536  return Convert(string(static_cast<const char*>(db_obj.Data()),
537  db_obj.Size()));
538  }
539 
540  template <typename TO, typename FROM>
541  TO ConvertFromLOB(void) const
542  {
543  FROM db_obj;
544  string result;
545 
546  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
547  if (db_obj.IsNULL()) {
548  return TO();
549  }
550 
551  result.resize(db_obj.Size());
552  db_obj.Read(const_cast<void*>(static_cast<const void*>(result.data())),
553  db_obj.Size()
554  );
555 
556  return Convert(result);
557  }
558 
559  template <typename TO, typename FROM>
560  TO Convert2CTime(void) const
561  {
562  FROM db_obj;
563 
564  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
565  if (db_obj.IsNULL()) {
566  return TO();
567  }
568 
569  return CTime(time_t(Convert(db_obj.Value())));
570  }
571 
572  template <typename TO>
573  void ReadCDBObject(TO& value) const
574  {
575  const int item_num = m_Value->CurrentItemNo();
576  const EDB_Type db_type = m_Value->ItemDataType(item_num);
577 
578  switch (db_type) {
579  case eDB_Int:
580  value = ConvertFrom<TO, CDB_Int>();
581  break;
582  case eDB_SmallInt:
583  value = ConvertFrom<TO, CDB_SmallInt>();
584  break;
585  case eDB_TinyInt:
586  value = ConvertFrom<TO, CDB_TinyInt>();
587  break;
588  case eDB_BigInt:
589  value = ConvertFrom<TO, CDB_BigInt>();
590  break;
591  case eDB_VarChar:
592  value = ConvertFromStr<TO, CDB_VarChar>();
593  break;
594  case eDB_Char:
595  value = ConvertFromChar<TO, CDB_Char>(item_num);
596  break;
597  case eDB_VarBinary:
598  value = ConvertFromStr<TO, CDB_VarBinary>();
599  break;
600  case eDB_Binary:
601  value = ConvertFromChar<TO, CDB_Binary>(item_num);
602  break;
603  case eDB_Float:
604  value = ConvertFrom<TO, CDB_Float>();
605  break;
606  case eDB_Double:
607  value = ConvertFrom<TO, CDB_Double>();
608  break;
609  // case eDB_DateTime:
610  // value = ConvertFrom<TO, CDB_DateTime>();
611  // case eDB_SmallDateTime:
612  // value = ConvertFrom<TO, CDB_SmallDateTime>();
613  case eDB_Text:
614  value = ConvertFromLOB<TO, CDB_Text>();
615  break;
616  case eDB_Image:
617  value = ConvertFromLOB<TO, CDB_Image>();
618  break;
619  case eDB_Bit:
620  value = ConvertFrom<TO, CDB_Bit>();
621  break;
622  case eDB_Numeric:
623  value = ConvertFrom<TO, CDB_Numeric>();
624  break;
625  case eDB_LongChar:
626  value = ConvertFromChar<TO, CDB_LongChar>(item_num);
627  break;
628  case eDB_LongBinary:
629  {
630  CDB_LongBinary db_obj(m_Value->ItemMaxSize(item_num));
631 
632  const_cast<CDB_Result*>(m_Value)->GetItem(&db_obj);
633  if (db_obj.IsNULL()) {
634  value = TO();
635  }
636 
637  value = Convert(string(static_cast<const char*>(db_obj.Value()), db_obj.DataSize()));
638  }
639  break;
640  default:
641  NCBI_REPORT_CONVERSION_ERROR("CDB_Object of unsupported type "
642  << db_type);
643  }
644  }
645 
646 private:
648 };
649 
650 ///////////////////////////////////////////////////////////////////////////////
651 template <typename CP, typename R, typename S>
653 {
654 public:
655  static R Make(S& source)
656  {
657  return R();
658  }
659 };
660 
661 template <typename CP, typename R>
663 {
664 public:
666  {
667  typedef CValueConvert<CP, CDB_Result> TResult;
668 
669  return TResult(source);
670  }
671 };
672 
673 template <typename T1, typename T2>
674 class CMakeObject<SRunTimeCP, pair<T1, T2>, CDB_Result>
675 {
676 public:
677  typedef pair<T1, T2> TValue;
678  typedef SRunTimeCP CP;
679 
681  {
682  typedef CValueConvert<CP, CDB_Result> TResult;
683 
684  TResult result(source);
685 
686  // We may get an error at run-time ...
689 
690  return TValue(v1, v2);
691  }
692 };
693 
694 template <typename T1, typename T2>
695 class CMakeObject<SSafeCP, pair<T1, T2>, CDB_Result>
696 {
697 public:
698  typedef pair<T1, T2> TValue;
699  typedef SSafeCP CP;
700 
702  {
703  typedef CValueConvert<CP, CDB_Result> TResult;
704 
705  TResult result(source);
706 
707  /* Not all data types have default constructor. */
708  const unsigned int n = source.NofItems();
709 
710  T1 v1 = T1();
711  T2 v2 = T2();
712 
713  if (static_cast<unsigned int>(source.CurrentItemNo()) < n) {
715  }
716 
717  if (static_cast<unsigned int>(source.CurrentItemNo()) < n) {
719  }
720 
721  return TValue(v1, v2);
722  }
723 };
724 
725 template <typename CP, typename T>
726 class CMakeObject<CP, vector<T>, CDB_Result>
727 {
728 public:
729  typedef vector<T> TValue;
730 
732  {
733  typedef CValueConvert<CP, CDB_Result> TResult;
734 
735  TResult result(source);
736  const unsigned int n = source.NofItems();
737  TValue res_val;
738 
739  for (unsigned int i = source.CurrentItemNo(); i < n; i = source.CurrentItemNo()) {
740  res_val.push_back(CMakeObject<CP, T, CDB_Result>::Make(source));
741  }
742 
743  return res_val;
744  }
745 };
746 
747 template <typename CP, typename T>
748 class CMakeObject<CP, stack<T>, CDB_Result>
749 {
750 public:
751  typedef stack<T> TValue;
752 
754  {
755  typedef CValueConvert<CP, CDB_Result> TResult;
756 
757  TResult result(source);
758  const unsigned int n = source.NofItems();
759  TValue res_val;
760 
761  for (unsigned int i = source.CurrentItemNo(); i < n; i = source.CurrentItemNo()) {
763  }
764 
765  return res_val;
766  }
767 };
768 
769 template <typename CP, typename T>
770 class CMakeObject<CP, deque<T>, CDB_Result>
771 {
772 public:
773  typedef deque<T> TValue;
774 
776  {
777  typedef CValueConvert<CP, CDB_Result> TResult;
778 
779  TResult result(source);
780  const unsigned int n = source.NofItems();
781  TValue res_val;
782 
783  for (unsigned int i = source.CurrentItemNo(); i < n; i = source.CurrentItemNo()) {
784  res_val.push_back(CMakeObject<CP, T, CDB_Result>::Make(source));
785  }
786 
787  return res_val;
788  }
789 };
790 
791 template <typename CP, typename T>
793 {
794 public:
795  typedef set<T> TValue;
796 
798  {
799  typedef CValueConvert<CP, CDB_Result> TResult;
800 
801  TResult result(source);
802  const unsigned int n = source.NofItems();
803  TValue res_val;
804 
805  for (unsigned int i = source.CurrentItemNo(); i < n; i = source.CurrentItemNo()) {
807  }
808 
809  return res_val;
810  }
811 };
812 
813 template <typename K, typename V>
815 {
816 public:
817  typedef map<K, V> TValue;
818  typedef SRunTimeCP CP;
819 
821  {
822  typedef CValueConvert<CP, CDB_Result> TResult;
823 
824  TResult result(source);
825  const unsigned int n = source.NofItems();
826  TValue res_val;
827 
828  for (unsigned int i = source.CurrentItemNo(); i < n; i = source.CurrentItemNo()) {
829  // We may get an error at run-time ...
832 
833  res_val.insert(pair<K, V>(k, v));
834  }
835 
836  return res_val;
837  }
838 };
839 
840 template <typename K, typename V>
842 {
843 public:
844  typedef map<K, V> TValue;
845  typedef SSafeCP CP;
846 
848  {
849  typedef CValueConvert<CP, CDB_Result> TResult;
850 
851  TResult result(source);
852  const unsigned int n = source.NofItems();
853  TValue res_val;
854 
855  for (unsigned int i = source.CurrentItemNo(); i < n; i = source.CurrentItemNo()) {
856  /* Not all data types have default constructor ... */
858  V v = V();
859 
860  if (static_cast<unsigned int>(source.CurrentItemNo()) < n) {
862  }
863 
864  res_val.insert(pair<K, V>(k, v));
865  }
866 
867  return res_val;
868  }
869 };
870 
871 ////////////////////////////////////////////////////////////////////////////////
872 template <typename CP, typename TO>
874 {
875 public:
876  typedef TO TValue;
877 
878  static void Convert(const shared_ptr<CDB_Result>& rs, TValue& value)
879  {
880  if (rs->Fetch()) {
882  } else {
883  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("valueless result");
884  }
885  }
886 };
887 
888 template <typename CP, typename T>
889 class CConvertTO<CP, vector<T> >
890 {
891 public:
892  typedef vector<T> TValue;
893 
894  static void Convert(const shared_ptr<CDB_Result>& rs, TValue& value)
895  {
896  while (rs->Fetch()) {
898  }
899  }
900 };
901 
902 template <typename CP, typename T>
903 class CConvertTO<CP, deque<T> >
904 {
905 public:
906  typedef deque<T> TValue;
907 
908  static void Convert(const shared_ptr<CDB_Result>& rs, TValue& value)
909  {
910  while (rs->Fetch()) {
912  }
913  }
914 };
915 
916 template <typename CP, typename T>
917 class CConvertTO<CP, set<T> >
918 {
919 public:
920  typedef set<T> TValue;
921 
922  static void Convert(const shared_ptr<CDB_Result>& rs, TValue& value)
923  {
924  while (rs->Fetch()) {
926  }
927  }
928 };
929 
930 template <typename CP, typename T>
931 class CConvertTO<CP, stack<T> >
932 {
933 public:
934  typedef stack<T> TValue;
935 
936  static void Convert(const shared_ptr<CDB_Result>& rs, TValue& value)
937  {
938  while (rs->Fetch()) {
940  }
941  }
942 };
943 
944 template <typename CP, typename K, typename V>
945 class CConvertTO<CP, map<K, V> >
946 {
947 public:
948  typedef map<K, V> TValue;
949 
950  static void Convert(const shared_ptr<CDB_Result>& rs, TValue& value)
951  {
952  while (rs->Fetch()) {
955 
956  value.insert(pair<K, V>(k, v));
957  }
958  }
959 };
960 
961 ////////////////////////////////////////////////////////////////////////////////
962 template <typename CP>
964 {
965 public:
966  typedef CDB_LangCmd TObj;
967 
969  : m_Stmt(other.m_Stmt)
970  {
971  }
973  : m_Stmt(&value)
974  {
975  if (!m_Stmt->Send()) {
976  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("unsendable CDB_LangCmd");
977  }
978  }
980  {
981  try {
982  m_Stmt->DumpResults();
983  }
984  // NCBI_CATCH_ALL_X( 6, NCBI_CURRENT_FUNCTION )
985  catch (...)
986  {
987  ;
988  }
989  }
990 
991 public:
992  template <typename TO>
993  operator TO(void) const
994  {
995  TO result;
996 
997  while (m_Stmt->HasMoreResults()) {
998  shared_ptr<CDB_Result> rs(m_Stmt->Result());
999 
1000  if (rs.get() == NULL) {
1001  continue;
1002  }
1003 
1005 
1006  return result;
1007  }
1008 
1009  // return TO();
1010  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("failed CDB_LangCmd");
1011  }
1012 
1013 private:
1015 };
1016 
1017 template <typename CP>
1019 {
1020 public:
1022 
1024  : m_Stmt(other.m_Stmt)
1025  {
1026  }
1028  : m_Stmt(value)
1029  {
1030  if (!m_Stmt->Send()) {
1031  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("unsendable CDB_LangCmd");
1032  }
1033  }
1035  {
1036  try {
1037  m_Stmt->DumpResults();
1038  }
1039  // NCBI_CATCH_ALL_X( 6, NCBI_CURRENT_FUNCTION )
1040  catch (...)
1041  {
1042  ;
1043  }
1044  }
1045 
1046 public:
1047  template <typename TO>
1048  operator TO(void) const
1049  {
1050  TO result;
1051 
1052  while (m_Stmt->HasMoreResults()) {
1053  shared_ptr<CDB_Result> rs(m_Stmt->Result());
1054 
1055  if (rs.get() == NULL) {
1056  continue;
1057  }
1058 
1060 
1061  return result;
1062  }
1063 
1064  // return TO();
1065  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("failed CDB_LangCmd");
1066  }
1067 
1068 private:
1069  mutable shared_ptr<TObj> m_Stmt;
1070 };
1071 
1072 ////////////////////////////////////////////////////////////////////////////////
1073 template <typename CP>
1075 {
1076 public:
1077  typedef CDB_RPCCmd TObj;
1078 
1080  : m_Stmt(other.m_Stmt)
1081  {
1082  }
1084  : m_Stmt(&value)
1085  {
1086  if (!m_Stmt->Send()) {
1087  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("unsendable CDB_RPCCmd");
1088  }
1089  }
1091  {
1092  try {
1093  m_Stmt->DumpResults();
1094  }
1095  // NCBI_CATCH_ALL_X( 6, NCBI_CURRENT_FUNCTION )
1096  catch (...)
1097  {
1098  ;
1099  }
1100  }
1101 
1102 public:
1103  template <typename TO>
1104  operator TO(void) const
1105  {
1106  TO result;
1107 
1108  while (m_Stmt->HasMoreResults()) {
1109  shared_ptr<CDB_Result> rs(m_Stmt->Result());
1110 
1111  if (rs.get() == NULL) {
1112  continue;
1113  }
1114 
1116 
1117  return result;
1118  }
1119 
1120  // return TO();
1121  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("failed CDB_RPCCmd");
1122  }
1123 
1124 private:
1126 };
1127 
1128 template <typename CP>
1130 {
1131 public:
1132  typedef CDB_RPCCmd TObj;
1133 
1135  : m_Stmt(other.m_Stmt)
1136  {
1137  }
1139  : m_Stmt(value)
1140  {
1141  if (!m_Stmt->Send()) {
1142  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("unsendable CDB_RPCCmd");
1143  }
1144  }
1146  {
1147  try {
1148  m_Stmt->DumpResults();
1149  }
1150  // NCBI_CATCH_ALL_X( 6, NCBI_CURRENT_FUNCTION )
1151  catch (...)
1152  {
1153  ;
1154  }
1155  }
1156 
1157 public:
1158  template <typename TO>
1159  operator TO(void) const
1160  {
1161  TO result;
1162 
1163  while (m_Stmt->HasMoreResults()) {
1164  shared_ptr<CDB_Result> rs(m_Stmt->Result());
1165 
1166  if (rs.get() == NULL) {
1167  continue;
1168  }
1169 
1171 
1172  return result;
1173  }
1174 
1175  // return TO();
1176  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("failed CDB_RPCCmd");
1177  }
1178 
1179 private:
1180  mutable shared_ptr<TObj> m_Stmt;
1181 };
1182 
1183 ////////////////////////////////////////////////////////////////////////////////
1184 template <typename CP>
1186 {
1187 public:
1189 
1191  : m_Stmt(other.m_Stmt)
1192  , m_RS(other.m_RS)
1193  {
1194  }
1196  : m_Stmt(&value)
1197  , m_RS(value.Open())
1198  {
1199  if (!m_RS.get()) {
1200  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("failed CDB_CursorCmd");
1201  }
1202  }
1204  {
1205  }
1206 
1207 public:
1208  template <typename TO>
1209  operator TO(void) const
1210  {
1211  TO result;
1212 
1214 
1215  return result;
1216  }
1217 
1218 private:
1220  mutable shared_ptr<CDB_Result> m_RS;
1221 };
1222 
1223 template <typename CP>
1225 {
1226 public:
1228 
1230  : m_Stmt(other.m_Stmt)
1231  , m_RS(other.m_RS)
1232  {
1233  }
1235  : m_Stmt(value)
1236  , m_RS(value->Open())
1237  {
1238  if (!m_RS.get()) {
1239  NCBI_REPORT_CONSTANT_CONVERSION_ERROR("failed CDB_CursorCmd");
1240  }
1241  }
1243  {
1244  }
1245 
1246 public:
1247  template <typename TO>
1248  operator TO(void) const
1249  {
1250  TO result;
1251 
1253 
1254  return result;
1255  }
1256 
1257 private:
1258  mutable shared_ptr<TObj> m_Stmt;
1259  mutable shared_ptr<CDB_Result> m_RS;
1260 };
1261 
1262 } // namespace value_slice
1263 
1265 
1266 
1267 #endif // DBAPI_DRIVER___DBAPI_DRIVER_CONVERT__HPP
1268 
CTime –.
Definition: ncbitime.hpp:296
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
Definition: map.hpp:338
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
static void Convert(const shared_ptr< CDB_Result > &rs, TValue &value)
static void Convert(const shared_ptr< CDB_Result > &rs, TValue &value)
static void Convert(const shared_ptr< CDB_Result > &rs, TValue &value)
static void Convert(const shared_ptr< CDB_Result > &rs, TValue &value)
static void Convert(const shared_ptr< CDB_Result > &rs, TValue &value)
static void Convert(const shared_ptr< CDB_Result > &rs, TValue &value)
CValueConvert(const CValueConvert< CP, TObj > &other)
CValueConvert(const CValueConvert< CP, TObj * > &other)
CValueConvert(const CValueConvert< CP, TObj > &other)
CValueConvert(const CValueConvert< CP, TObj * > &other)
CValueConvert(const CValueConvert< CP, TObj > &other)
CValueConvert(const CValueConvert< CP, TObj * > &other)
CValueConvert(const CValueConvert< CP, CDB_Result > &value)
#define T(s)
Definition: common.h:230
#define bool
Definition: bool.h:34
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
EDB_Type
Definition: types.hpp:52
size_t DataSize() const
Definition: types.hpp:797
Int4 Value() const
Definition: types.hpp:373
size_t Size(void) const
Definition: types.hpp:522
int Value() const
Definition: types.hpp:1145
const char * Data(void) const
Definition: types.hpp:527
bool IsNULL() const
Definition: types.hpp:303
const void * Value() const
Definition: types.hpp:792
@ eDB_Bit
Definition: types.hpp:68
@ eDB_Char
Definition: types.hpp:58
@ 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_Binary
Definition: types.hpp:60
@ eDB_Text
Definition: types.hpp:66
@ eDB_SmallInt
Definition: types.hpp:54
@ eDB_LongBinary
Definition: types.hpp:71
@ eDB_VarBinary
Definition: types.hpp:59
@ eDB_VarBinaryMax
Definition: types.hpp:73
const CVect2< U > & v2
Definition: globals.hpp:440
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
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
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
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
int8_t Int1
1-byte (8-bit) signed integer
Definition: ncbitype.h:98
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_DBAPIDRIVER_EXPORT
Definition: ncbi_export.h:392
int i
yy_size_t n
#define S(x, n)
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const CharType(& source)[N]
Definition: pointer.h:1149
#define K
#define R(t)
#define CP
Definition: streambuf.cpp:49
else result
Definition: token2.c:20
const value_slice::CValueConvert< value_slice::SRunTimeCP, FROM > Convert(const FROM &value)
#define NCBI_CONVERT_TO(x, y)
#define NCBI_REPORT_CONVERSION_ERROR(x)
#define NCBI_REPORT_CONSTANT_CONVERSION_ERROR(x)
Modified on Tue Apr 23 07:39:27 2024 by modify_doxy.py rev. 669887