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

Go to the SVN repository for this file.

1 /* $Id: bdb_types.cpp 77790 2017-05-08 13:31:07Z ivanov $
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: Anatoliy Kuznetsov
27  *
28  * File Description: BDB libarary types implementations.
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbi_bswap.hpp>
34 #include <db/bdb/bdb_types.hpp>
35 #include <db.h>
36 
38 
39 
40 static
41 const unsigned char* s_GetLString(const unsigned char* str,
42  bool check_legacy,
43  int* str_len)
44 {
45  _ASSERT(str);
46  _ASSERT(str_len);
47 
48  // string length reconstruction
49  *str_len = (str[0]) |
50  (str[1] << 8) |
51  (str[2] << 16) |
52  (str[3] << 24);
53 
54  if (check_legacy) {
55  if (*str_len < 0) { // true L-string
56  *str_len = -(*str_len);
57  str += 4;
58  } else {
59  *str_len = (int)::strlen((const char*)str);
60  }
61  } else { // no legacy strings
62  if (*str_len <= 0) { // true L-string
63  *str_len = -(*str_len);
64  str += 4;
65  } else {
66  _ASSERT(0); // positive length !
67  }
68  }
69 
70  return str;
71 
72 }
73 
74 static
75 const unsigned char* s_GetLString(const DBT* val,
76  bool check_legacy,
77  int* str_len)
78 {
79  const unsigned char* str = (const unsigned char*)val->data;
80 
81  if (val->size <= 4) { // looks like legacy C-string
82  _ASSERT(check_legacy);
83  *str_len = (int)::strlen((const char*)str);
84  return str;
85  }
86 
87  return s_GetLString(str, check_legacy, str_len);
88 }
89 
90 
91 
92 extern "C"
93 {
94 
95 /////////////////////////////////////////////////////////////////////////////
96 // BDB comparison functions
97 //
98 
99 int BDB_UintCompare(DB* db, const DBT* val1, const DBT* val2)
100 {
101  return BDB_Uint4Compare(db, val1, val2);
102 }
103 
104 int BDB_Uint4Compare(DB*, const DBT* val1, const DBT* val2)
105 {
106  Uint4 v1, v2;
107 #ifdef HAVE_UNALIGNED_READS
108  v1 = *((Uint4*) val1->data);
109  v2 = *((Uint4*) val2->data);
110 #else
111  ::memcpy(&v1, val1->data, sizeof(Uint4));
112  ::memcpy(&v2, val2->data, sizeof(Uint4));
113 #endif
114  return (v1 < v2) ? -1
115  : ((v2 < v1) ? 1 : 0);
116 }
117 
118 int BDB_Int8Compare(DB*, const DBT* val1, const DBT* val2)
119 {
120  Int8 v1, v2;
121 #ifdef HAVE_UNALIGNED_READS
122  v1 = *((Int8*) val1->data);
123  v2 = *((Int8*) val2->data);
124 #else
125  ::memcpy(&v1, val1->data, sizeof(Int8));
126  ::memcpy(&v2, val2->data, sizeof(Int8));
127 #endif
128  return (v1 < v2) ? -1
129  : ((v2 < v1) ? 1 : 0);
130 }
131 
132 int BDB_Uint8Compare(DB*, const DBT* val1, const DBT* val2)
133 {
134  Uint8 v1, v2;
135 #ifdef HAVE_UNALIGNED_READS
136  v1 = *((Uint8*) val1->data);
137  v2 = *((Uint8*) val2->data);
138 #else
139  ::memcpy(&v1, val1->data, sizeof(Uint8));
140  ::memcpy(&v2, val2->data, sizeof(Uint8));
141 #endif
142  return (v1 < v2) ? -1
143  : ((v2 < v1) ? 1 : 0);
144 }
145 
146 int BDB_IntCompare(DB* db, const DBT* val1, const DBT* val2)
147 {
148  return BDB_Int4Compare(db, val1, val2);
149 }
150 
151 int BDB_Int4Compare(DB*, const DBT* val1, const DBT* val2)
152 {
153  Int4 v1, v2;
154 #ifdef HAVE_UNALIGNED_READS
155  v1 = *((Int4*) val1->data);
156  v2 = *((Int4*) val2->data);
157 #else
158  ::memcpy(&v1, val1->data, sizeof(Int4));
159  ::memcpy(&v2, val2->data, sizeof(Int4));
160 #endif
161  return (v1 < v2) ? -1
162  : ((v2 < v1) ? 1 : 0);
163 }
164 
165 int BDB_Int2Compare(DB*, const DBT* val1, const DBT* val2)
166 {
167  Int2 v1, v2;
168 #ifdef HAVE_UNALIGNED_READS
169  v1 = *((Int2*) val1->data);
170  v2 = *((Int2*) val2->data);
171 #else
172  ::memcpy(&v1, val1->data, sizeof(Int2));
173  ::memcpy(&v2, val2->data, sizeof(Int2));
174 #endif
175  return (v1 < v2) ? -1
176  : ((v2 < v1) ? 1 : 0);
177 }
178 
179 int BDB_Uint2Compare(DB*, const DBT* val1, const DBT* val2)
180 {
181  Uint2 v1, v2;
182 #ifdef HAVE_UNALIGNED_READS
183  v1 = *((Uint2*) val1->data);
184  v2 = *((Uint2*) val2->data);
185 #else
186  ::memcpy(&v1, val1->data, sizeof(Uint2));
187  ::memcpy(&v2, val2->data, sizeof(Uint2));
188 #endif
189  return (v1 < v2) ? -1
190  : ((v2 < v1) ? 1 : 0);
191 }
192 
193 int BDB_CharCompare(DB*, const DBT* val1, const DBT* val2)
194 {
195  const char& v1=*static_cast<char*>(val1->data);
196  const char& v2=*static_cast<char*>(val2->data);
197 
198  return (v1 < v2) ? -1
199  : ((v2 < v1) ? 1 : 0);
200 }
201 
202 int BDB_UCharCompare(DB*, const DBT* val1, const DBT* val2)
203 {
204  const unsigned char& v1=*static_cast<unsigned char*>(val1->data);
205  const unsigned char& v2=*static_cast<unsigned char*>(val2->data);
206 
207  return (v1 < v2) ? -1
208  : ((v2 < v1) ? 1 : 0);
209 }
210 
211 int BDB_FloatCompare(DB*, const DBT* val1, const DBT* val2)
212 {
213  float v1, v2;
214 #ifdef HAVE_UNALIGNED_READS
215  v1 = *((float*) val1->data);
216  v2 = *((float*) val2->data);
217 #else
218  ::memcpy(&v1, val1->data, sizeof(v1));
219  ::memcpy(&v2, val2->data, sizeof(v2));
220 #endif
221  return (v1 < v2) ? -1
222  : ((v2 < v1) ? 1 : 0);
223 }
224 
225 int BDB_DoubleCompare(DB*, const DBT* val1, const DBT* val2)
226 {
227  double v1, v2;
228 #ifdef HAVE_UNALIGNED_READS
229  v1 = *((double*) val1->data);
230  v2 = *((double*) val2->data);
231 #else
232  ::memcpy(&v1, val1->data, sizeof(v1));
233  ::memcpy(&v2, val2->data, sizeof(v2));
234 #endif
235  return (v1 < v2) ? -1
236  : ((v2 < v1) ? 1 : 0);
237 }
238 
239 int BDB_StringCompare(DB*, const DBT* val1, const DBT* val2)
240 {
241  return ::strcmp((const char*)val1->data, (const char*)val2->data);
242 }
243 
244 int BDB_FixedByteStringCompare(DB* /*db*/, const DBT* val1, const DBT* val2)
245 {
246  _ASSERT(val1->size == val2->size);
247  int r = ::memcmp(val1->data, val2->data, val1->size);
248  return r;
249 }
250 
251 
252 
253 int BDB_LStringCompare(DB* db, const DBT* val1, const DBT* val2)
254 {
255  const CBDB_BufferManager* fbuf1 =
256  static_cast<CBDB_BufferManager*> (db->app_private);
257 
258  bool check_legacy = fbuf1->IsLegacyStrings();
259 
260  const unsigned char* str1;
261  const unsigned char* str2;
262  int str_len1;
263  int str_len2;
264 
265  str1 = s_GetLString(val1, check_legacy, &str_len1);
266  str2 = s_GetLString(val2, check_legacy, &str_len2);
267 
268  int cmp_len = min(str_len1, str_len2);
269  int r = ::memcmp(str1, str2, cmp_len);
270  if (r == 0) {
271  return (str_len1 < str_len2) ? -1
272  : ((str_len2 < str_len1) ? 1 : 0);
273  }
274  return r;
275 }
276 
277 
278 int BDB_StringCaseCompare(DB*, const DBT* val1, const DBT* val2)
279 {
280  return NStr::strcasecmp((const char*)val1->data, (const char*)val2->data);
281 }
282 
283 int BDB_Compare(DB* db, const DBT* val1, const DBT* val2)
284 {
285  const CBDB_BufferManager* fbuf1 =
286  static_cast<CBDB_BufferManager*> (db->app_private);
287 
288  bool byte_swapped = fbuf1->IsByteSwapped();
289 
290  _ASSERT(fbuf1);
291 
292  const char* p1 = static_cast<char*> (val1->data);
293  const char* p2 = static_cast<char*> (val2->data);
294 
295  unsigned int cmp_limit = fbuf1->GetFieldCompareLimit();
296  if (cmp_limit == 0) {
297  cmp_limit = fbuf1->FieldCount();
298  } else {
299  _ASSERT(cmp_limit <= fbuf1->FieldCount());
300  }
301 
302  for (unsigned int i = 0; i < cmp_limit; ++i) {
303  const CBDB_Field& fld1 = fbuf1->GetField(i);
304  int ret = fld1.Compare(p1, p2, byte_swapped);
305  if ( ret )
306  return ret;
307 
308  p1 += fld1.GetDataLength(p1);
309  p2 += fld1.GetDataLength(p2);
310  }
311 
312  return 0;
313 }
314 
315 /// String hash function taken from SStringHash (algo/text/text_util)
316 /// @internal
317 unsigned int
318 BDB_Hash(DB *, const void *bytes, unsigned length)
319 {
320  const unsigned char* buf = (const unsigned char*)bytes;
321  const unsigned char* buf_end = buf + length;
322  // Copied from include/algo/text/text_util.hpp:StrngHash17
323  // to cut dependency to algo
324  unsigned ha = 0;
325  for (; buf != buf_end; ++buf) {
326  ha = ((ha << 4) + ha) + *buf;
327  }
328  return ha;
329 }
330 
331 unsigned int
332 BDB_Uint4Hash(DB *db, const void *bytes, unsigned length)
333 {
334  if (length == 4) {
335  unsigned ha;
336  ::memcpy(&ha, bytes, 4);
337  return ha;
338  } else {
339  return BDB_Hash(db, bytes, length);
340  }
341 }
342 
343 
344 
345 int BDB_ByteSwap_UintCompare(DB* db, const DBT* val1, const DBT* val2)
346 {
347  return BDB_ByteSwap_Uint4Compare(db, val1, val2);
348 }
349 
350 int BDB_ByteSwap_Uint4Compare(DB*, const DBT* val1, const DBT* val2)
351 {
352  unsigned int v1, v2;
353  v1 = (unsigned int) CByteSwap::GetInt4((unsigned char*)val1->data);
354  v2 = (unsigned int) CByteSwap::GetInt4((unsigned char*)val2->data);
355  return (v1 < v2) ? -1
356  : ((v2 < v1) ? 1 : 0);
357 }
358 
359 int BDB_ByteSwap_Int8Compare(DB*, const DBT* val1, const DBT* val2)
360 {
361  Int8 v1, v2;
362  v1 = CByteSwap::GetInt8((unsigned char*)val1->data);
363  v2 = CByteSwap::GetInt8((unsigned char*)val2->data);
364  return (v1 < v2) ? -1
365  : ((v2 < v1) ? 1 : 0);
366 }
367 
368 int BDB_ByteSwap_Uint8Compare(DB*, const DBT* val1, const DBT* val2)
369 {
370  Uint8 v1, v2;
371  v1 = CByteSwap::GetInt8((unsigned char*)val1->data);
372  v2 = CByteSwap::GetInt8((unsigned char*)val2->data);
373  return (v1 < v2) ? -1
374  : ((v2 < v1) ? 1 : 0);
375 }
376 
377 int BDB_ByteSwap_IntCompare(DB* db, const DBT* val1, const DBT* val2)
378 {
379  return BDB_ByteSwap_Int4Compare(db, val1, val2);
380 }
381 
382 int BDB_ByteSwap_Int4Compare(DB*, const DBT* val1, const DBT* val2)
383 {
384  int v1, v2;
385  v1 = CByteSwap::GetInt4((unsigned char*)val1->data);
386  v2 = CByteSwap::GetInt4((unsigned char*)val2->data);
387  return (v1 < v2) ? -1
388  : ((v2 < v1) ? 1 : 0);
389 }
390 
391 int BDB_ByteSwap_Int2Compare(DB*, const DBT* val1, const DBT* val2)
392 {
393  Int2 v1, v2;
394  v1 = CByteSwap::GetInt2((unsigned char*)val1->data);
395  v2 = CByteSwap::GetInt2((unsigned char*)val2->data);
396  return (v1 < v2) ? -1
397  : ((v2 < v1) ? 1 : 0);
398 }
399 
400 int BDB_ByteSwap_Uint2Compare(DB*, const DBT* val1, const DBT* val2)
401 {
402  Uint2 v1, v2;
403  v1 = CByteSwap::GetInt2((unsigned char*)val1->data);
404  v2 = CByteSwap::GetInt2((unsigned char*)val2->data);
405  return (v1 < v2) ? -1
406  : ((v2 < v1) ? 1 : 0);
407 }
408 
409 
410 int BDB_ByteSwap_FloatCompare(DB*, const DBT* val1, const DBT* val2)
411 {
412  float v1, v2;
413  v1 = CByteSwap::GetFloat((unsigned char*)val1->data);
414  v2 = CByteSwap::GetFloat((unsigned char*)val2->data);
415  return (v1 < v2) ? -1
416  : ((v2 < v1) ? 1 : 0);
417 }
418 
419 
420 int BDB_ByteSwap_DoubleCompare(DB*, const DBT* val1, const DBT* val2)
421 {
422  double v1, v2;
423  v1 = CByteSwap::GetDouble((unsigned char*)val1->data);
424  v2 = CByteSwap::GetDouble((unsigned char*)val2->data);
425  return (v1 < v2) ? -1
426  : ((v2 < v1) ? 1 : 0);
427 
428 }
429 
430 
431 
432 
433 } // extern "C"
434 
435 /////////////////////////////////////////////////////////////////////////////
436 // IBDB_Field::
437 //
438 
440 {
441 }
442 
443 /////////////////////////////////////////////////////////////////////////////
444 // CBDB_Field::
445 //
446 
448 : m_BufferManager(0),
449  m_Buffer(0),
450  m_BufferSize(0),
451  m_BufferIdx(0)
452 {
453  m_Flags.VariableLength = (length_type == eFixedLength) ? 0 : 1;
454  m_Flags.Attached = 0;
455  m_Flags.Nullable = 0;
456 }
457 
459 CBDB_Field::GetCompareFunction(bool /*byte_swapped*/) const
460 {
461  return BDB_Compare;
462 }
463 
464 
466 {
467  return 0;
468 }
469 
470 
471 /////////////////////////////////////////////////////////////////////////////
472 // CBDB_BufferManager::
473 //
474 
475 
477  : m_Buffer(0),
478  m_BufferSize(0),
479  m_PackedSize(0),
480  m_DBT_Size(0),
481  m_Packable(false),
482  m_ByteSwapped(false),
483  m_Nullable(false),
484  m_NullSetSize(0),
485  m_CompareLimit(0),
486  m_LegacyString(false),
487  m_OwnFields(false),
488  m_PackOptComputed(false),
489  m_FirstVarFieldIdx(0),
490  m_FirstVarFieldIdxOffs(0)
491 {
492 }
493 
495 {
496  delete [] m_Buffer;
497 
498  if (m_OwnFields) {
499  for (size_t i = 0; i < m_Fields.size(); ++i) {
500  CBDB_Field* field = m_Fields[i];
501  delete field;
502  }
503  }
504 }
505 
507 {
508  m_Fields.push_back(field);
509  m_Ptrs.push_back(0);
510 
511  unsigned field_idx = (unsigned)(m_Fields.size() - 1);
512  field->SetBufferIdx(field_idx);
513 
514  if ( !m_Packable ) {
515  // If we bind any var length field, then record becomes packable
516  m_Packable = field->IsVariableLength();
517  }
518 
519  if (is_nullable == eNullable)
520  field->SetNullable();
521 }
522 
523 int CBDB_BufferManager::GetFieldIndex(const string& name) const
524 {
525  for (size_t i = 0; i < m_Fields.size(); ++i) {
526  const CBDB_Field& field = *m_Fields[i];
527  const string& fname = field.GetName();
528  if (NStr::CompareNocase(name, fname) == 0) {
529  return (int)i;
530  }
531  }
532  return -1;
533 }
534 
536 {
537  size_t buf_len = 0;
538  for (size_t i = 0; i < m_Fields.size(); ++i) {
539  const CBDB_Field& field = *m_Fields[i];
540  buf_len += field.GetBufferSize();
541  }
542  return buf_len;
543 }
544 
545 
547 {
548  if ( !IsNullable() )
549  return;
550 
551  for (size_t i = 0; i < m_Fields.size(); ++i) {
552  const CBDB_Field& fld = *m_Fields[i];
553  if (!fld.IsNullable() && TestNullBit((unsigned)i)) {
554  string message("NULL field in database operation.");
555  const string& field_name = fld.GetName();
556  if ( !field_name.empty() ) {
557  message.append("(Field:");
558  message.append(field_name);
559  message.append(")");
560  }
561  BDB_THROW(eNull, message);
562  }
563  }
564 }
565 
566 
568 {
569  _ASSERT(m_Fields.size());
570 
571  // Buffer construction: fields size calculation.
573 
574  if ( IsNullable() ) {
577  }
578 
579  delete [] m_Buffer; m_Buffer = 0;
580  m_Buffer = new char[m_BufferSize];
581  ::memset(m_Buffer, 0, m_BufferSize);
582 
583  // Record construction: set element offsets(pointers)
584  char* buf_ptr = (char*) m_Buffer;
585  buf_ptr += m_NullSetSize;
586 
587  for (size_t i = 0; i < m_Fields.size(); ++i) {
588  CBDB_Field& df = *m_Fields[i];
589  m_Ptrs[i] = buf_ptr;
590 
591  df.SetBufferManager(this);
592  df.SetBuffer(buf_ptr);
593 
594  buf_ptr += df.GetBufferSize();
595  }
596 
597  m_PackedSize = 0; // not packed
598 }
599 
600 
603 {
604  if (m_Fields.size() > 1)
605  return BDB_Compare;
606  bool byte_swapped = IsByteSwapped();
607  return m_Fields[0]->GetCompareFunction(byte_swapped);
608 }
609 
610 
613 {
614  return BDB_Hash;
615 }
616 
617 
619 {
620  _ASSERT(m_Fields.size());
621 
622  if ( !IsPackable() ) {
624  return;
625  }
626 
627  char* buf_ptr = m_Buffer;
628  buf_ptr += m_NullSetSize;
630 
631  for (size_t i = 0; i < m_Fields.size(); ++i) {
632  CBDB_Field& df = *m_Fields[i];
633  df.SetBuffer(buf_ptr);
634  size_t len = df.GetDataLength(buf_ptr);
635  buf_ptr += len;
636  m_PackedSize += len;
637  }
638 }
639 
640 
642 {
643  size_t offset = m_NullSetSize;
644 
645  for (TFieldVector::size_type i = 0; i < m_Fields.size(); ++i) {
646  CBDB_Field& df = *m_Fields[i];
647 
648  if (df.IsVariableLength()) {
649  m_FirstVarFieldIdx = (unsigned int)i;
650  break;
651  }
652  offset += df.GetLength();
653  }
654  m_FirstVarFieldIdxOffs = (unsigned int)offset;
655  m_PackOptComputed = true;
656 }
657 
658 
660 {
661  _ASSERT(m_Fields.size());
662  if (m_PackedSize != 0)
663  return (unsigned)m_PackedSize;
664  if ( !IsPackable() ) {
666  return (unsigned)m_PackedSize;
667  }
668 
669  if (!m_PackOptComputed) {
671  }
672 
673  char* new_ptr = m_Buffer;
674  new_ptr += m_FirstVarFieldIdxOffs;
676 
677  for (size_t i = m_FirstVarFieldIdx; i < m_Fields.size(); ++i) {
678  CBDB_Field& df = *m_Fields[i];
679  size_t actual_len = df.GetLength();
680  void* old_ptr = m_Ptrs[i];
681 
682  if (new_ptr != old_ptr) {
683  ::memmove(new_ptr, old_ptr, actual_len);
684  df.SetBuffer(new_ptr);
685  }
686 
687  if ( m_NullSetSize ) {
688  if (df.IsVariableLength() && TestNullBit((unsigned)i)) {
689  actual_len = 1;
690  *new_ptr = '\0'; // for string it will guarantee it is empty
691  }
692  }
693 
694  new_ptr += actual_len;
695  m_PackedSize += actual_len;
696  }
697 
698  return (unsigned)m_PackedSize;
699 }
700 
701 
703 {
704  _ASSERT(m_Fields.size());
705  if (m_PackedSize == 0)
706  return (unsigned)m_BufferSize;
707  if ( !IsPackable() ) {
708  m_PackedSize = 0;
709  return (unsigned)m_PackedSize;
710  }
711  if (!m_PackOptComputed) {
713  }
714 
715  _ASSERT(!m_Fields.empty());
716  for (size_t i = m_Fields.size() - 1; true; --i) {
717  CBDB_Field& df = *m_Fields[i];
718  size_t actual_len = df.GetLength();
719  void* new_ptr = m_Ptrs[i];
720  const void* old_ptr = df.GetBuffer();
721  if (new_ptr != old_ptr) {
722  ::memmove(new_ptr, old_ptr, actual_len);
723  df.SetBuffer(new_ptr);
724  }
725  m_PackedSize -= actual_len;
726 
727  if (i == m_FirstVarFieldIdx) {
729  break;
730  }
731  }
732 
733 
734  _ASSERT(m_PackedSize == 0);
735  return (unsigned)m_BufferSize;
736 }
737 
739 {
740  Pack();
741  dbt->data = m_Buffer;
742  dbt->size = (unsigned)m_PackedSize;
743  dbt->ulen = (unsigned)m_BufferSize;
744  dbt->flags = DB_DBT_USERMEM;
745 }
746 
748 {
749  dbt->data = m_Buffer;
750  dbt->size = (unsigned)m_PackedSize;
751  dbt->ulen = (unsigned)m_BufferSize;
752  dbt->flags = DB_DBT_USERMEM;
753 }
754 
755 int
757  unsigned int field_count) const
758 {
759  if ( !field_count ) {
760  field_count = FieldCount();
761  }
762  _ASSERT(field_count <= FieldCount());
763 
764  for (unsigned int i = 0; i < field_count; ++i) {
765  const CBDB_Field& df1 = GetField(i);
766  const CBDB_Field& df2 = buf_mgr.GetField(i);
767 
768  int ret = df1.CompareWith(df2);
769  if ( ret )
770  return ret;
771  }
772 
773  return 0;
774 }
775 
776 
778 {
779  _ASSERT(FieldCount() == 0);
780  for (unsigned int i = 0; i < buf_mgr.FieldCount(); ++i) {
781  const CBDB_Field& src_fld = buf_mgr.GetField(i);
782 
783  // "0" value selects the same buffer size as in src_fld
784  unique_ptr<CBDB_Field> dst_fld(src_fld.Construct(0));
785 
786  dst_fld->SetName(src_fld.GetName().c_str());
787  Bind(dst_fld.get());
788  dst_fld.release();
789  }
790  m_LegacyString = buf_mgr.IsLegacyStrings();
791 }
792 
793 
795 {
796  CopyFieldsFrom(buf_mgr);
797 }
798 
799 void CBDB_BufferManager::CopyPackedFrom(void* data, size_t data_size)
800 {
801  _ASSERT(data);
802  _ASSERT(data_size <= m_BufferSize);
803 
804  memcpy(m_Buffer, data, data_size);
805  SetDBT_Size(data_size);
807 }
808 
809 /////////////////////////////////////////////////////////////////////////////
810 // CBDB_FieldFixedByteString::
811 //
812 
814  : CBDB_Field(eFixedLength)
815 {
816  SetBufferSize(256 + 4);
817 }
818 
821 {
822  void* buf = GetBuffer();
823  if (this == &str)
824  return *this;
825 
826  size_t len = str.GetDataLength(buf);
827  if ( len > (GetBufferSize()) ) {
828  // TODO: allow partial string assignment?
829  BDB_THROW(eOverflow, "Fixed string field overflow.");
830  }
831  Unpack();
832  ::memcpy(buf, str.GetBuffer(), len);
833 
834  if ( str.IsNull() ) {
835  SetNull();
836  } else {
837  SetNotNull();
838  }
839 
840  return *this;
841 }
842 
843 
844 
845 
846 /////////////////////////////////////////////////////////////////////////////
847 // CBDB_FieldLString::
848 //
849 
852 {
853  SetBufferSize(256 + 4);
854 }
855 
857 {
859  fld->SetBufferSize(buf_size ? buf_size + 4 : GetBufferSize());
860  return fld;
861 }
862 
863 
864 const unsigned char*
865 CBDB_FieldLString::GetLString(const unsigned char* str,
866  bool check_legacy,
867  int* str_len) const
868 {
869  size_t DBT_size = m_BufferManager->GetDBT_Size();
870 
871  if (DBT_size > 0 && DBT_size <= 4) { // looks like legacy C-string
872  _ASSERT(check_legacy);
873  *str_len = (int)::strlen((const char*)str);
874  } else {
875  str = s_GetLString(str, check_legacy, str_len);
876  }
877  return str;
878 }
879 
880 
882 {
883  return 4;
884 }
885 
886 
887 /*
888 CBDB_FieldLString::operator const char* () const
889 {
890  const unsigned char* str = (const unsigned char*)GetBuffer();
891  bool check_legacy = m_BufferManager->IsLegacyStrings();
892 
893  int str_len;
894  size_t DBT_size = m_BufferManager->GetDBT_Size();
895 
896  if (DBT_size <= 4) { // looks like legacy C-string
897  _ASSERT(check_legacy);
898  str_len = ::strlen((const char*)str);
899  } else {
900  str = GetLString(str, check_legacy, &str_len);
901  }
902  return (const char*) str;
903 }
904 */
905 
908 {
909  void* buf = GetBuffer();
910  if (this == &str)
911  return *this;
912 
913  size_t len = str.GetDataLength(buf);
914  if ( len > (GetBufferSize() - 4) ) {
915  // TODO: allow partial string assignment?
916  BDB_THROW(eOverflow, "String field overflow.");
917  }
918  Unpack();
919  ::memcpy(buf, str.GetBuffer(), len);
920 
921  if ( str.IsNull() ) {
922  SetNull();
923  } else {
924  SetNotNull();
925  }
926 
927  return *this;
928 }
929 
930 void CBDB_FieldLString::Set(const char* str, size_t size,
931  EOverflowAction if_overflow)
932 {
933  if ( !size )
934  str = kEmptyCStr;
935 
936  size_t new_len = size;
937 
938  // check overflow
939  size_t eff_buffer_size = GetBufferSize() - 4;
940  if (new_len > eff_buffer_size) {
941  if (if_overflow == eTruncateOnOverflow) {
942  new_len = eff_buffer_size;
943  } else {
944  string message("String field overflow. Max length is ");
945  message += NStr::NumericToString(eff_buffer_size);
946  message += ", requested length is ";
947  message += NStr::NumericToString(new_len);
948  BDB_THROW(eOverflow, message);
949  }
950  }
951  Unpack();
952  unsigned char* str_buf = (unsigned char*) GetBuffer();
953 
954  int s_len = -(int)new_len; // always store it negative
955  str_buf[0] = (unsigned char) (s_len);
956  str_buf[1] = (unsigned char) (s_len >> 8);
957  str_buf[2] = (unsigned char) (s_len >> 16);
958  str_buf[3] = (unsigned char) (s_len >> 24);
959 
960  str_buf += 4;
961 
962  ::memcpy(str_buf, str, new_len);
963 
964  SetNotNull();
965 }
966 
967 
968 void CBDB_FieldLString::Set(const char* str, EOverflowAction if_overflow)
969 {
970  if ( !str )
971  str = kEmptyCStr;
972 
973  this->Set(str, ::strlen(str), if_overflow);
974 }
975 
977 {
978  operator=(str);
979 }
980 
981 
982 int CBDB_FieldLString::Compare(const void* p1,
983  const void* p2,
984  bool /*byte_swapped*/) const
985 {
986  _ASSERT(p1 && p2);
987 
988  bool check_legacy = m_BufferManager->IsLegacyStrings();
989 
990  const unsigned char* str1;
991  const unsigned char* str2;
992  int str_len1;
993  int str_len2;
994 
995  str1 = GetLString((const unsigned char*)p1, check_legacy, &str_len1);
996  str2 = GetLString((const unsigned char*)p2, check_legacy, &str_len2);
997 
998  int cmp_len = min(str_len1, str_len2);
999  int r = ::memcmp(str1, str2, cmp_len);
1000  if (r == 0) {
1001  return (str_len1 < str_len2) ? -1
1002  : ((str_len2 < str_len1) ? 1 : 0);
1003  }
1004  return r;
1005 }
1006 
1007 
1009 {
1010  Set("", eTruncateOnOverflow);
1011 }
1012 
1013 
1015 {
1016  void* buf = Unpack();
1017  size_t buf_size = GetBufferSize();
1018 
1019  ::memset(buf, 0x7F, buf_size); // 0xFF for international
1020  ((char*) buf)[buf_size - 1] = '\0';
1021 
1022  int s_len = -((int)buf_size - 4); // always store it negative
1023  unsigned char* str_buf = (unsigned char*) buf;
1024 
1025  str_buf[0] = (unsigned char) (s_len);
1026  str_buf[1] = (unsigned char) (s_len >> 8);
1027  str_buf[2] = (unsigned char) (s_len >> 16);
1028  str_buf[3] = (unsigned char) (s_len >> 24);
1029 
1030  SetNotNull();
1031 }
1032 
1033 
1035 {
1036  const unsigned char* str = (const unsigned char*) GetBuffer();
1037  bool check_legacy = m_BufferManager->IsLegacyStrings();
1038  int str_len;
1039 
1040  str = GetLString(str, check_legacy, &str_len);
1041 
1042  return (str_len == 0);
1043 }
1044 
1046 {
1047  const unsigned char* str = (const unsigned char*) GetBuffer();
1048  bool check_legacy = m_BufferManager->IsLegacyStrings();
1049  int str_len;
1050 
1051  str = GetLString(str, check_legacy, &str_len);
1052 
1053  for (int i = 0; i < str_len; ++i) {
1054  if (!isspace((unsigned char) str[i]))
1055  return false;
1056  }
1057 
1058  return true;
1059 }
1060 
1061 
1062 size_t CBDB_FieldLString::GetDataLength(const void* buf) const
1063 {
1064  const unsigned char* str = (const unsigned char*) buf;
1065  bool check_legacy = m_BufferManager->IsLegacyStrings();
1066  int str_len;
1067 
1068  str = GetLString(str, check_legacy, &str_len);
1069  if (str != (const unsigned char*) buf)
1070  str_len += 4;
1071  // We should NOT add 1 to the length here because it messes with
1072  // buffer packing/unpacking algorithm for the record containing
1073  // this field.
1074  return str_len;
1075 }
1076 
1078 {
1080  return *this;
1081 }
1082 
1084 {
1085  SetStdString(str);
1086  return *this;
1087 }
1088 
1089 
1091 {
1092  _ASSERT(!IsNull());
1093 
1094  const unsigned char* buf = (const unsigned char*) GetBuffer();
1095  bool check_legacy = m_BufferManager->IsLegacyStrings();
1096 
1097  const unsigned char* str;
1098  int str_len;
1099 
1100  str = GetLString(buf, check_legacy, &str_len);
1101  if (str_len == 0) {
1102  return kEmptyStr;
1103  }
1104  string ret((const char*) str, str_len);
1105  return ret;
1106 }
1107 
1108 void CBDB_FieldLString::ToString(string& ostr) const
1109 {
1110  const unsigned char* buf = (const unsigned char*) GetBuffer();
1111  bool check_legacy = m_BufferManager->IsLegacyStrings();
1112 
1113  const unsigned char* str;
1114  int str_len;
1115 
1116  ostr.resize(0);
1117 
1118  str = GetLString(buf, check_legacy, &str_len);
1119  if (str_len == 0) {
1120  return;
1121  }
1122  ostr.append((const char*) str, str_len);
1123 }
1124 
1126 {
1127  size_t str_len = str.length();
1128  if (str_len == 0) {
1129  Set("", eThrowOnOverflow);
1130  return;
1131  }
1132 
1133  size_t eff_buffer_size = GetBufferSize() - 4;
1134  // check overflow
1135  if (str_len > eff_buffer_size) {
1136  string message("String field overflow. Max length is ");
1137  message += NStr::NumericToString(eff_buffer_size);
1138  message += ", requested length is ";
1139  message += NStr::NumericToString(str_len);
1140  BDB_THROW(eOverflow, message);
1141  }
1142 
1143  const char* str_data = str.data();
1144 
1145  unsigned char* str_buf = (unsigned char*) Unpack();
1146 
1147  int s_len = -(int)str_len; // always store it negative
1148  str_buf[0] = (unsigned char) (s_len);
1149  str_buf[1] = (unsigned char) (s_len >> 8);
1150  str_buf[2] = (unsigned char) (s_len >> 16);
1151  str_buf[3] = (unsigned char) (s_len >> 24);
1152 
1153  str_buf += 4;
1154  ::memcpy(str_buf, str_data, str_len);
1155 
1156  SetNotNull();
1157 }
1158 
1159 /////////////////////////////////////////////////////////////////////////////
1160 // CBDB_FieldFactory::
1161 //
1162 
1164 {}
1165 
1167 {
1168  if (NStr::CompareNocase(type, "string")==0) {
1169  return eString;
1170  } else
1171  if (NStr::CompareNocase(type, "lstring")==0) {
1172  return eLString;
1173  } else
1174  if (NStr::CompareNocase(type, "int8")==0) {
1175  return eInt8;
1176  } else
1177  if (NStr::CompareNocase(type, "int4")==0) {
1178  return eInt4;
1179  } else
1180  if (NStr::CompareNocase(type, "uint4")==0) {
1181  return eUint4;
1182  } else
1183  if (NStr::CompareNocase(type, "int2")==0) {
1184  return eInt2;
1185  } else
1186  if (NStr::CompareNocase(type, "uint1")==0) {
1187  return eUint1;
1188  } else
1189  if (NStr::CompareNocase(type, "float")==0) {
1190  return eFloat;
1191  } else
1192  if (NStr::CompareNocase(type, "double")==0) {
1193  return eDouble;
1194  } else
1195  if (NStr::CompareNocase(type, "uchar")==0) {
1196  return eUChar;
1197  } else
1198  if (NStr::CompareNocase(type, "blob")==0) {
1199  return eBlob;
1200  } else
1201  if (NStr::CompareNocase(type, "lob")==0) {
1202  return eBlob;
1203  } else {
1204  return eUnknown;
1205  }
1206 }
1207 
1209 {
1210  switch (etype)
1211  {
1212  case eString:
1213  return new CBDB_FieldString();
1214  case eLString:
1215  return new CBDB_FieldLString();
1216  case eInt8:
1217  return new CBDB_FieldInt8();
1218  case eInt4:
1219  return new CBDB_FieldInt4();
1220  case eInt2:
1221  return new CBDB_FieldInt2();
1222  case eUint1:
1223  return new CBDB_FieldUint1();
1224  case eFloat:
1225  return new CBDB_FieldFloat();
1226  case eDouble:
1227  return new CBDB_FieldDouble();
1228  case eUChar:
1229  return new CBDB_FieldUChar();
1230  default:
1231  BDB_THROW(eInvalidType, "Type is not supported.");
1232  };
1233 
1234  return 0;
1235 }
1236 
1238 {
1239  EType et = GetType(type);
1240  try
1241  {
1242  return Create(et);
1243  }
1244  catch (CBDB_LibException& )
1245  {
1246  BDB_THROW(eInvalidType, type);
1247  }
1248 }
1249 
1250 
1252 
1253 
static const unsigned char * s_GetLString(const unsigned char *str, bool check_legacy, int *str_len)
Definition: bdb_types.cpp:41
unsigned int(* BDB_HashFunction)(DB *, const void *bytes, unsigned length)
Definition: bdb_types.hpp:59
int(* BDB_CompareFunction)(DB *, const DBT *, const DBT *)
Definition: bdb_types.hpp:57
struct __db DB
Definition: bdb_types.hpp:52
struct __db_dbt DBT
Definition: bdb_types.hpp:51
BDB Data Field Buffer manager class.
Definition: bdb_types.hpp:1768
Double precision floating point field type.
Definition: bdb_types.hpp:1436
Fixed length bytestring.
Definition: bdb_types.hpp:1519
Float field type.
Definition: bdb_types.hpp:1352
Int2 field type.
Definition: bdb_types.hpp:911
Int4 field type.
Definition: bdb_types.hpp:827
Int8 field type.
Definition: bdb_types.hpp:659
Length prefised string field type.
Definition: bdb_types.hpp:1709
String field type.
Definition: bdb_types.hpp:1572
String field type designed to work with C-strings (ASCIIZ)
Definition: bdb_types.hpp:1590
Char field type.
Definition: bdb_types.hpp:1078
Uint1 field type.
Definition: bdb_types.hpp:1232
Base class for constructing BDB fields.
Definition: bdb_types.hpp:297
BDB library exception.
Definition: bdb_expt.hpp:121
static Int8 GetInt8(const unsigned char *ptr)
Definition: ncbi_bswap.hpp:154
static double GetDouble(const unsigned char *ptr)
Definition: ncbi_bswap.hpp:222
static Int2 GetInt2(const unsigned char *ptr)
Definition: ncbi_bswap.hpp:96
static Int4 GetInt4(const unsigned char *ptr)
Definition: ncbi_bswap.hpp:121
static float GetFloat(const unsigned char *ptr)
Definition: ncbi_bswap.hpp:205
#define false
Definition: bool.h:36
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
ENullable
Whether a value is nullable.
Definition: ncbimisc.hpp:113
@ eNullable
Value can be null.
Definition: ncbimisc.hpp:114
virtual BDB_CompareFunction GetCompareFunction(bool byte_swapped) const
Return address to the type specific comparison function By default it's universal BDB_Compare.
Definition: bdb_types.cpp:459
void SetDBT_Size(size_t size)
Definition: bdb_types.hpp:1895
CBDB_FieldFixedByteString & operator=(const CBDB_FieldFixedByteString &str)
Definition: bdb_types.cpp:820
void CopyFrom(const CBDB_BufferManager &bman)
Copy all fields from another manager with the same(a must!) structure.
Definition: bdb_types.cpp:794
virtual CBDB_Field * Construct(size_t buf_size) const
Virtual constructor - class factory for BDB fields.
Definition: bdb_types.cpp:856
int BDB_LStringCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented length prefixed string keys.
Definition: bdb_types.cpp:253
unsigned int BDB_Hash(DB *, const void *bytes, unsigned length)
String hash function taken from SStringHash (algo/text/text_util)
Definition: bdb_types.cpp:318
bool m_LegacyString
Flag to check for legacy string compatibility.
Definition: bdb_types.hpp:1936
virtual void SetMaxVal()
Set maximum possible value for the field type.
Definition: bdb_types.cpp:1014
int BDB_CharCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "char" keys.
Definition: bdb_types.cpp:193
int BDB_FloatCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "float" keys.
Definition: bdb_types.cpp:211
bool IsNull() const
Return TRUE if field is NULL.
Definition: bdb_types.hpp:2171
int BDB_IntCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "int" keys.
Definition: bdb_types.cpp:146
TFieldVector m_Fields
Definition: bdb_types.hpp:1916
EType GetType(const string &type) const
Return type enumerator by string type (case insensitive)
Definition: bdb_types.cpp:1166
void SetNotNull()
Set "is NULL" flag to FALSE.
Definition: bdb_types.hpp:2158
virtual int Compare(const void *p1, const void *p2, bool byte_swapped) const =0
Comparison function.
int BDB_Uint2Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned short int" keys.
Definition: bdb_types.cpp:179
bool IsLegacyStrings() const
Return TRUE if buffer l-strings should check about legacy c-str compatibility.
Definition: bdb_types.hpp:1793
unsigned int m_FirstVarFieldIdx
Index of first variable length field.
Definition: bdb_types.hpp:1947
struct CBDB_Field::@104 m_Flags
unsigned int BDB_Uint4Hash(DB *db, const void *bytes, unsigned length)
Hash method for databases with a single (unique) UInt4 key.
Definition: bdb_types.cpp:332
bool IsBlank() const
Definition: bdb_types.cpp:1045
void CheckNullConstraint() const
Check if all NOT NULLABLE fields were assigned.
Definition: bdb_types.cpp:546
void Set(const char *str, EOverflowAction if_overflow=eThrowOnOverflow)
Definition: bdb_types.cpp:968
CBDB_Field(ELengthType length_type=eFixedLength)
Definition: bdb_types.cpp:447
void PrepareDBT_ForWrite(DBT *dbt)
Pack the buffer and initialize DBT structure for write operation.
Definition: bdb_types.cpp:738
void SetBufferSize(size_t size)
Set the buffer size.
Definition: bdb_types.hpp:2194
int BDB_ByteSwap_Int4Compare(DB *, const DBT *val1, const DBT *val2)
Definition: bdb_types.cpp:382
int BDB_UCharCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned char" keys.
Definition: bdb_types.cpp:202
int BDB_ByteSwap_Int2Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "short int" keys Used when the data...
Definition: bdb_types.cpp:391
BDB_HashFunction GetHashFunction() const
Return buffer hash function.
Definition: bdb_types.cpp:612
bool IsByteSwapped() const
Return TRUE if buffer is in a non-native byte order.
Definition: bdb_types.hpp:1781
unsigned int FieldCount() const
Return number of fields attached using function Bind.
Definition: bdb_types.hpp:2529
ELengthType
Length based classificator for fields (fixed-variable)
Definition: bdb_types.hpp:300
int BDB_Uint8Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "Uint8" keys.
Definition: bdb_types.cpp:132
void * Unpack()
Unpack the buffer which contains this field (using CBDB_BufferManager).
Definition: bdb_types.hpp:2177
int BDB_Uint4Compare(DB *, const DBT *val1, const DBT *val2)
Definition: bdb_types.cpp:104
bool IsNullable() const
Return TRUE if field can be NULL.
Definition: bdb_types.hpp:2146
void Construct()
Create internal data buffer, assign places in this buffer to the fields.
Definition: bdb_types.cpp:567
bool IsNullable() const
Return TRUE if buffer can carry NULL fields.
Definition: bdb_types.hpp:2541
bool TestNullBit(unsigned int idx) const
Definition: bdb_types.hpp:2563
CBDB_Field * Create(EType type) const
Definition: bdb_types.cpp:1208
int BDB_UintCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned int" keys.
Definition: bdb_types.cpp:99
int BDB_ByteSwap_Uint4Compare(DB *, const DBT *val1, const DBT *val2)
Definition: bdb_types.cpp:350
virtual size_t GetDataLength(const void *buf) const =0
Return current effective size of the buffer.
virtual int Compare(const void *p1, const void *p2, bool) const
Comparison function.
Definition: bdb_types.cpp:982
int BDB_ByteSwap_Uint2Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned short int" keys Used when...
Definition: bdb_types.cpp:400
virtual void ToString(string &str) const
Definition: bdb_types.cpp:1108
int BDB_ByteSwap_UintCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "unsigned int" keys.
Definition: bdb_types.cpp:345
int Compare(const CBDB_BufferManager &buf_mgr, unsigned int n_fields=0) const
Compare fields of this buffer with those of 'buf_mgr' using CBDB_Field::CompareWith().
Definition: bdb_types.cpp:756
void DuplicateStructureFrom(const CBDB_BufferManager &buf_mgr)
Duplicate (dynamic allocation is used) all fields from 'buf_mgr' and bind them to the this buffer man...
Definition: bdb_types.cpp:777
virtual void SetString(const char *)
Definition: bdb_types.cpp:976
const CBDB_Field & GetField(unsigned int idx) const
Definition: bdb_types.hpp:2517
bool m_OwnFields
Field ownership flag.
Definition: bdb_types.hpp:1939
virtual void SetStdString(const string &str)
Definition: bdb_types.cpp:1125
const string & GetName() const
Return symbolic name for the field.
Definition: bdb_types.hpp:2289
int BDB_Compare(DB *db, const DBT *val1, const DBT *val2)
General purpose DBD comparison function.
Definition: bdb_types.cpp:283
int BDB_ByteSwap_Uint8Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "Uint8" keys Used when the data fil...
Definition: bdb_types.cpp:368
vector< void * > m_Ptrs
Array of pointers to the fields' data.
Definition: bdb_types.hpp:1918
int BDB_ByteSwap_Int8Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "Int8" keys Used when the data file...
Definition: bdb_types.cpp:359
bool IsPackable() const
Return TRUE if any field bound to this buffer manager has variable length (i.e.
Definition: bdb_types.hpp:2535
virtual size_t GetExtraDataLength()
Hook for defining extra data length.
Definition: bdb_types.cpp:465
unsigned Unpack()
Definition: bdb_types.cpp:702
void SetNull()
Assign field value to NULL.
Definition: bdb_types.hpp:2164
bool m_PackOptComputed
Pack optimization flag (turns TRUE on first Pack call)
Definition: bdb_types.hpp:1945
unsigned int m_FirstVarFieldIdxOffs
Buffer offset of first variable length field.
Definition: bdb_types.hpp:1949
int BDB_StringCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "C string" keys.
Definition: bdb_types.cpp:239
int BDB_Int8Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "Int8" keys.
Definition: bdb_types.cpp:118
int CompareWith(const CBDB_Field &field) const
Field comparison function.
Definition: bdb_types.hpp:2238
string Get() const
Definition: bdb_types.cpp:1090
unsigned int GetFieldCompareLimit() const
Get number of fields in comparison.
Definition: bdb_types.hpp:2698
int BDB_StringCaseCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "case insensitive C string" keys.
Definition: bdb_types.cpp:278
int BDB_ByteSwap_IntCompare(DB *db, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "int" keys Used when the data file ...
Definition: bdb_types.cpp:377
void PrepareDBT_ForRead(DBT *dbt)
Initialize DBT structure for read operation.
Definition: bdb_types.cpp:747
virtual size_t GetDataLength(const void *buf) const
Return current effective size of the buffer.
Definition: bdb_types.cpp:1062
void Bind(CBDB_Field *field, ENullable is_nullable=eNotNullable)
Attach 'field' to the buffer.
Definition: bdb_types.cpp:506
size_t GetDBT_Size() const
Get DBT.size of the parent file (key or data area) (Set by CBDB_File after read)
Definition: bdb_types.hpp:1797
CBDB_BufferManager * m_BufferManager
Definition: bdb_types.hpp:401
bool IsEmpty() const
Definition: bdb_types.cpp:1034
bool IsVariableLength() const
Return TRUE if it is a variable length variable (like string)
Definition: bdb_types.hpp:2128
size_t ComputeNullSetSize() const
Definition: bdb_types.hpp:2554
BDB_CompareFunction GetCompareFunction() const
Return buffer compare function.
Definition: bdb_types.cpp:602
void CopyPackedFrom(void *data, size_t data_size)
Copy packed data (buffer) from an external source.
Definition: bdb_types.cpp:799
size_t m_NullSetSize
size of the 'is NULL' bitset in bytes
Definition: bdb_types.hpp:1930
size_t GetBufferSize() const
Return maximum possible buffer length.
Definition: bdb_types.hpp:2134
int BDB_Int2Compare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "short int" keys.
Definition: bdb_types.cpp:165
const unsigned char * GetLString(const unsigned char *str, bool check_legacy, int *str_len) const
Definition: bdb_types.cpp:865
virtual void SetMinVal()
Set minimal possible value for the field type.
Definition: bdb_types.cpp:1008
int BDB_FixedByteStringCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented fixed length string keys.
Definition: bdb_types.cpp:244
int BDB_ByteSwap_FloatCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "float" keys Used when the data fil...
Definition: bdb_types.cpp:410
int BDB_Int4Compare(DB *, const DBT *val1, const DBT *val2)
Definition: bdb_types.cpp:151
void ArrangePtrsPacked()
Definition: bdb_types.cpp:618
virtual ~IBDB_Field()
Definition: bdb_types.cpp:439
const void * GetBuffer() const
Get pointer to the data. NULL if not yet attached.
Definition: bdb_types.hpp:2213
int GetFieldIndex(const string &name) const
Find the field with the specified name.
Definition: bdb_types.cpp:523
void SetNullable()
Mark field as "NULL" capable.
Definition: bdb_types.hpp:2152
void SetBufferIdx(unsigned int idx)
Set field position in the buffer manager.
Definition: bdb_types.hpp:2207
int BDB_DoubleCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "double" keys.
Definition: bdb_types.cpp:225
size_t ComputeBufferSize() const
Calculate buffer size.
Definition: bdb_types.cpp:535
CBDB_FieldLString & operator=(const CBDB_FieldLString &str)
Definition: bdb_types.cpp:907
void CopyFieldsFrom(const CBDB_BufferManager &buf_mgr)
Copy all field values from the 'buf_mgr'.
Definition: bdb_types.hpp:2657
virtual CBDB_Field * Construct(size_t buf_size=0) const =0
Virtual constructor - class factory for BDB fields.
virtual size_t GetExtraDataLength()
Hook for defining extra data length.
Definition: bdb_types.cpp:881
int BDB_ByteSwap_DoubleCompare(DB *, const DBT *val1, const DBT *val2)
Simple and fast comparison function for tables with non-segmented "double" keys Used when the data fi...
Definition: bdb_types.cpp:420
@ eFixedLength
fixed-length (like int)
Definition: bdb_types.hpp:301
#define BDB_THROW(errcode, message)
Definition: bdb_expt.hpp:178
const CVect2< U > & v2
Definition: globals.hpp:440
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
#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 kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static int strcasecmp(const char *s1, const char *s2)
Case-insensitive comparison of two zero-terminated strings.
Definition: ncbistr.hpp:5220
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
const char *const kEmptyCStr
Empty "C" string (points to a '\0').
Definition: ncbistr.cpp:68
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
char * buf
int i
if(yy_accept[yy_current_state])
int len
const struct ncbi::grid::netcache::search::fields::SIZE size
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
int isspace(Uchar c)
Definition: ncbictype.hpp:69
T min(T x_, T y_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
double df(double x_, const double &y_)
Definition: njn_root.hpp:189
#define memmove(a, b, c)
Definition: type.c:6
#define _ASSERT
Modified on Fri Apr 12 17:15:29 2024 by modify_doxy.py rev. 669887