21 #include <ndb_global.h>
23 #include <kernel/AttributeHeader.hpp>
24 #include <NdbSqlUtil.hpp>
74 TypeOutOfRange = -102,
75 TypeNotSupported = -103,
77 TypeFixSizeInvalid = -105,
78 TypeNullableNotBool = -106,
79 CharsetNotSpecified = -107,
80 CharsetNotFound = -108,
81 CharsetNotAllowed = -109,
82 SpecBufOverflow = -201,
83 DataCntOverflow = -301,
84 DataBufOverflow = -302,
85 DataValueOverflow = -303,
86 DataNotNullable = -304,
87 InvalidAttrInfo = -305,
88 BoundEmptySide = -401,
89 BoundNonemptySide = -402,
91 ValidationError = -902,
96 int get_error_code()
const;
97 int get_error_line()
const;
108 void set_error(
int code,
int line)
const;
109 void set_error(
const Error& e2)
const;
110 mutable int m_error_code;
111 mutable int m_error_line;
124 static Value get_endian();
125 static void convert(
void* ptr, Uint32 len);
134 Type(
int typeId, Uint32 byteSize,
bool nullable, Uint32 csNumber);
142 void set(Uint32 typeId, Uint32 byteSize,
bool nullable, Uint32 csNumber);
144 Uint32 get_type_id()
const;
145 Uint32 get_byte_size()
const;
146 bool get_nullable()
const;
147 Uint32 get_cs_number()
const;
148 Uint32 get_array_type()
const;
150 friend NdbOut& operator<<(NdbOut&,
const Type&);
151 void print(NdbOut& out)
const;
152 const char* print(
char*
buf, Uint32 bufsz)
const;
153 int validate()
const;
179 void set_buf(
Type*
buf, Uint32 bufMaxCnt);
181 void set_buf(
Type* buf);
186 int add(
Type type, Uint32 cnt);
188 void copy(
const Spec& s2);
190 const Type& get_type(Uint32
i)
const;
191 Uint32 get_cnt()
const;
192 Uint32 get_nullable_cnt(
bool allNullable)
const;
193 Uint32 get_nullmask_len(
bool allNullable)
const;
195 Uint32 get_max_data_len(
bool allNullable)
const;
197 Uint32 get_min_var_bytes(
bool allNullable)
const;
199 friend NdbOut& operator<<(NdbOut&,
const Spec&);
200 void print(NdbOut& out)
const;
201 const char* print(
char* buf, Uint32 bufsz)
const;
202 int validate()
const;
215 Uint16 m_nullableCnt;
217 Uint32 m_maxByteSize;
240 int desc(
const Uint8* item);
243 int cmp(
const Iter& r2,
const Uint8* buf1,
const Uint8* buf2)
const;
246 const bool m_allNullable;
264 DataC(
const Spec& spec,
bool allNullable);
266 void set_buf(
const void*
buf, Uint32 bufMaxLen, Uint32 cnt);
268 int desc(
Iter& r)
const;
270 int cmp(
const DataC& d2, Uint32 cnt, Uint32& num_eq)
const;
272 const Spec& get_spec()
const;
273 bool get_all_nullable()
const;
274 const void* get_data_buf()
const;
275 Uint32 get_cnt()
const;
276 bool is_empty()
const;
277 bool is_full()
const;
279 friend NdbOut& operator<<(NdbOut&,
const DataC&);
280 void print(NdbOut& out)
const;
281 const char* print(
char* buf, Uint32 bufsz,
bool convert_flag =
false)
const;
282 int validate()
const {
return 0; }
292 const bool m_allNullable;
310 Data(
const Spec& spec,
bool allNullable, Uint32 varBytes);
312 void set_buf(
void*
buf, Uint32 bufMaxLen);
316 int add(
const void* data, Uint32* len_out);
317 int add(
const void* data, Uint32 cnt, Uint32* len_out);
319 int add_null(Uint32* len_out);
320 int add_null(Uint32 cnt, Uint32* len_out);
322 int add_poai(
const Uint32* poai, Uint32* len_out);
323 int add_poai(
const Uint32* poai, Uint32 cnt, Uint32* len_out);
327 int copy(
const DataC& d2);
329 int convert(Endian::Value to_endian);
331 int desc_all(Uint32 cnt, Endian::Value from_endian);
333 Uint32 get_max_len()
const;
334 Uint32 get_max_len4()
const;
335 Uint32 get_var_bytes()
const;
336 const void* get_full_buf()
const;
337 Uint32 get_full_len()
const;
338 Uint32 get_data_len()
const;
339 Uint32 get_null_cnt()
const;
340 Endian::Value get_endian()
const;
342 friend NdbOut& operator<<(NdbOut&,
const Data&);
343 void print(NdbOut& out)
const;
344 const char* print(
char* buf, Uint32 bufsz)
const;
345 int validate()
const;
354 int convert_impl(Endian::Value to_endian);
355 const Uint32 m_varBytes;
358 Endian::Value m_endian;
372 int finalize(
int side);
374 int cmp(
const DataC& d2, Uint32 cnt, Uint32& num_eq)
const;
376 int cmp(
const BoundC& b2, Uint32 cnt, Uint32& num_eq)
const;
378 DataC& get_data()
const;
379 int get_side()
const;
381 friend NdbOut& operator<<(NdbOut&,
const BoundC&);
382 void print(NdbOut& out)
const;
383 const char* print(
char*
buf, Uint32 bufsz)
const;
384 int validate()
const;
407 int finalize(
int side);
409 Data& get_data()
const;
411 friend NdbOut& operator<<(NdbOut&,
const Bound&);
412 void print(NdbOut& out)
const;
413 const char* print(
char*
buf, Uint32 bufsz)
const;
414 int validate()
const;
437 void print(
const char* frm, ...);
447 NdbPack::getSqlType(Uint32 typeId)
449 return NdbSqlUtil::m_typeList[typeId];
455 NdbPack::Error::Error()
463 inline NdbPack::Endian::Value
464 NdbPack::Endian::get_endian()
466 #ifndef WORDS_BIGENDIAN
476 NdbPack::Type::Type()
478 m_typeId = NDB_TYPE_UNDEFINED;
487 NdbPack::Type::Type(
int typeId, Uint32 byteSize,
bool nullable, Uint32 csNumber)
489 set(typeId, byteSize, nullable, csNumber);
493 NdbPack::Type::set(Uint32 typeId, Uint32 byteSize,
bool nullable, Uint32 csNumber)
496 m_byteSize = byteSize;
497 m_nullable = nullable;
498 m_csNumber = csNumber;
502 NdbPack::Type::get_type_id()
const
508 NdbPack::Type::get_byte_size()
const
514 NdbPack::Type::get_nullable()
const
516 return (
bool)m_nullable;
520 NdbPack::Type::get_cs_number()
const
526 NdbPack::Type::get_array_type()
const
534 NdbPack::Spec::Spec()
542 NdbPack::Spec::set_buf(Type*
buf, Uint32 bufMaxCnt)
546 m_bufMaxCnt = bufMaxCnt;
550 NdbPack::Spec::set_buf(Type*
buf)
556 NdbPack::Spec::reset()
565 NdbPack::Spec::get_type(Uint32
i)
const
572 NdbPack::Spec::get_cnt()
const
578 NdbPack::Spec::get_nullable_cnt(
bool allNullable)
const
581 return m_nullableCnt;
587 NdbPack::Spec::get_nullmask_len(
bool allNullable)
const
589 return (get_nullable_cnt(allNullable) + 7) / 8;
593 NdbPack::Spec::get_max_data_len(
bool allNullable)
const
595 return get_nullmask_len(allNullable) + m_maxByteSize;
599 NdbPack::Spec::get_min_var_bytes(
bool allNullable)
const
601 const Uint32 len = get_max_data_len(allNullable);
602 return (len < 256 ? 1 : 2);
608 NdbPack::Iter::Iter(
const DataC& data) :
610 m_allNullable(data.m_allNullable)
616 NdbPack::Iter::reset()
618 m_itemPos = m_spec.get_nullmask_len(m_allNullable);
629 NdbPack::DataC::DataC(
const Spec& spec,
bool allNullable) :
631 m_allNullable(allNullable)
639 NdbPack::DataC::set_buf(
const void*
buf, Uint32 bufMaxLen, Uint32 cnt)
641 m_buf =
static_cast<const Uint8*
>(
buf);
642 m_bufMaxLen = bufMaxLen;
647 NdbPack::DataC::get_spec()
const
653 NdbPack::DataC::get_all_nullable()
const
655 return &m_allNullable;
659 NdbPack::DataC::get_data_buf()
const
665 NdbPack::DataC::get_cnt()
const
671 NdbPack::DataC::is_empty()
const
677 NdbPack::DataC::is_full()
const
679 return m_cnt == m_spec.m_cnt;
685 NdbPack::Data::Data(
const Spec& spec,
bool allNullable, Uint32 varBytes) :
686 DataC(spec, allNullable),
687 m_varBytes(varBytes),
692 m_endian = Endian::get_endian();
696 NdbPack::Data::set_buf(
void*
buf, Uint32 bufMaxLen)
698 m_buf =
static_cast<Uint8*
>(
buf);
699 m_bufMaxLen = bufMaxLen;
701 assert(bufMaxLen >= m_varBytes);
702 DataC::set_buf(&m_buf[m_varBytes], m_bufMaxLen - m_varBytes, 0);
706 NdbPack::Data::reset()
709 const Uint32 bytes = m_varBytes + m_spec.get_nullmask_len(m_allNullable);
710 memset(m_buf, 0, bytes);
711 m_endian = Endian::get_endian();
716 NdbPack::Data::finalize()
718 if (m_varBytes == 0 ||
719 finalize_impl() == 0)
725 NdbPack::Data::convert(Endian::Value to_endian)
727 if (to_endian == Endian::Native)
728 to_endian = Endian::get_endian();
729 if (m_endian == to_endian)
731 if (convert_impl(to_endian) == 0)
733 m_endian = to_endian;
740 NdbPack::Data::get_max_len()
const
742 return m_varBytes + m_spec.get_max_data_len(m_allNullable);
746 NdbPack::Data::get_max_len4()
const
748 Uint32 len4 = get_max_len();
756 NdbPack::Data::get_var_bytes()
const
762 NdbPack::Data::get_full_buf()
const
768 NdbPack::Data::get_full_len()
const
770 return m_varBytes + m_iter.m_itemPos + m_iter.m_itemLen;
774 NdbPack::Data::get_data_len()
const
776 return m_iter.m_itemPos + m_iter.m_itemLen;
780 NdbPack::Data::get_null_cnt()
const
782 return m_iter.m_nullCnt;
785 inline NdbPack::Endian::Value
786 NdbPack::Data::get_endian()
const
794 NdbPack::BoundC::BoundC(DataC& data) :
801 NdbPack::BoundC::cmp(
const DataC& d2, Uint32 cnt, Uint32& num_eq)
const
803 const BoundC& b1 = *
this;
804 const DataC& d1 = b1.m_data;
805 int res = d1.cmp(d2, cnt, num_eq);
806 if (res == 0 && d1.m_cnt <= d2.m_cnt)
812 NdbPack::BoundC::get_data()
const
818 NdbPack::BoundC::get_side()
const
826 NdbPack::Bound::Bound(
Data& data) :
833 NdbPack::Bound::reset()
840 NdbPack::Bound::finalize(
int side)
842 if (m_data.finalize() == -1)
847 if (BoundC::finalize(side) == -1)
853 NdbPack::Bound::get_data()
const
858 #endif // NDB_PACK_HPP