MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbRecAttr.hpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef NdbRecAttr_H
19 #define NdbRecAttr_H
20 
21 #include "NdbDictionary.hpp"
22 #include "Ndb.hpp"
23 
24 class NdbOperation;
25 
75 {
76 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
77  friend class NdbOperation;
78  friend class NdbScanOperation;
79  friend class NdbIndexScanOperation;
80  friend class NdbEventOperationImpl;
81  friend class NdbReceiver;
82  friend class Ndb;
83  friend class NdbQueryOperationImpl;
84  friend class NdbOut& operator<<(class NdbOut&, const class AttributeS&);
85 #endif
86 
87 public:
92  const NdbDictionary::Column * getColumn() const;
93 
99 
104  Uint32 get_size_in_bytes() const { return m_size_in_bytes; }
105 
120  int isNULL() const;
121 
127  Int64 int64_value() const;
128 
134  Int32 int32_value() const;
135 
141  Int32 medium_value() const;
142 
148  short short_value() const;
149 
155  char char_value() const;
156 
162  Int8 int8_value() const;
163 
169  Uint64 u_64_value() const;
170 
176  Uint32 u_32_value() const;
177 
183  Uint32 u_medium_value() const;
184 
190  Uint16 u_short_value() const;
191 
197  Uint8 u_char_value() const;
198 
204  Uint8 u_8_value() const;
205 
211  float float_value() const;
212 
218  double double_value() const;
219 
243  char* aRef() const;
244 
252  NdbRecAttr * clone() const;
253 
260  ~NdbRecAttr();
261 
262 public:
263 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
264  const NdbRecAttr* next() const;
265 #endif
266 private:
267 
268  Uint32 attrId() const; /* Get attribute id */
269  bool setNULL(); /* Set NULL indicator */
270  void setUNDEFINED(); //
271 
272  bool receive_data(const Uint32*, Uint32);
273 
274  void release(); /* Release memory if allocated */
275  void init(); /* Initialise object when allocated */
276 
277  NdbRecAttr(Ndb*);
278  void next(NdbRecAttr* aRecAttr);
279  NdbRecAttr* next();
280 
281  int setup(const class NdbDictionary::Column* col, char* aValue);
282  int setup(const class NdbColumnImpl* anAttrInfo, char* aValue);
283  int setup(Uint32 byteSize, char* aValue);
284  /* Set up attributes and buffers */
285  bool copyoutRequired() const; /* Need to copy data to application */
286  void copyout(); /* Copy from storage to application */
287 
288  Uint64 theStorage[4]; /* The data storage here if <= 32 bytes */
289  Uint64* theStorageX; /* The data storage here if > 32 bytes */
290  char* theValue; /* The data storage in the application */
291  void* theRef; /* Pointer to one of above */
292 
293  NdbRecAttr* theNext; /* Next pointer */
294  Uint32 theAttrId; /* The attribute id */
295 
296  Int32 m_size_in_bytes;
297  const NdbDictionary::Column* m_column;
298 
299  // not-NULL means skip length bytes and store their value here
300  Uint16* m_getVarValue;
301 
302  friend struct Ndb_free_list_t<NdbRecAttr>;
303 
304  NdbRecAttr(const NdbRecAttr&); // Not impl.
305  NdbRecAttr&operator=(const NdbRecAttr&);
306 };
307 
308 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
309 
310 inline
313  return m_column->getType();
314 }
315 
316 inline
317 const NdbDictionary::Column *
318 NdbRecAttr::getColumn() const {
319  return m_column;
320 }
321 
322 inline
323 Int32
325 {
326  return *(Int32*)theRef;
327 }
328 
329 inline
330 short
332 {
333  return *(short*)theRef;
334 }
335 
336 inline
337 char
339 {
340  return *(char*)theRef;
341 }
342 
343 inline
344 Int8
346 {
347  return *(Int8*)theRef;
348 }
349 
350 inline
351 Uint32
353 {
354  return *(Uint32*)theRef;
355 }
356 
357 inline
358 Uint16
360 {
361  return *(Uint16*)theRef;
362 }
363 
364 inline
365 Uint8
367 {
368  return *(Uint8*)theRef;
369 }
370 
371 inline
372 Uint8
374 {
375  return *(Uint8*)theRef;
376 }
377 
378 inline
379 void
380 NdbRecAttr::release()
381 {
382  if (theStorageX != 0) {
383  delete [] theStorageX;
384  theStorageX = 0;
385  }
386 }
387 
388 inline
389 void
390 NdbRecAttr::init()
391 {
392  theStorageX = 0;
393  theValue = 0;
394  theRef = 0;
395  theNext = 0;
396  theAttrId = 0xFFFF;
397  m_getVarValue = 0;
398 }
399 
400 inline
401 void
402 NdbRecAttr::next(NdbRecAttr* aRecAttr)
403 {
404  theNext = aRecAttr;
405 }
406 
407 inline
408 NdbRecAttr*
409 NdbRecAttr::next()
410 {
411  return theNext;
412 }
413 
414 inline
415 const NdbRecAttr*
416 NdbRecAttr::next() const
417 {
418  return theNext;
419 }
420 
421 inline
422 char*
424 {
425  return (char*)theRef;
426 }
427 
428 inline
429 bool
430 NdbRecAttr::copyoutRequired() const
431 {
432  return theRef != theValue && theValue != 0;
433 }
434 
435 inline
436 Uint32
437 NdbRecAttr::attrId() const
438 {
439  return theAttrId;
440 }
441 
442 inline
443 bool
444 NdbRecAttr::setNULL()
445 {
446  m_size_in_bytes= 0;
447  return true;
448 }
449 
450 inline
451 int
453 {
454  return m_size_in_bytes == 0 ? 1 : (m_size_in_bytes > 0 ? 0 : -1);
455 }
456 
457 inline
458 void
459 NdbRecAttr::setUNDEFINED()
460 {
461  m_size_in_bytes= -1;
462 }
463 
464 class NdbOut& operator <<(class NdbOut&, const NdbRecAttr &);
465 
467 {
468 public:
469  NdbRecordPrintFormat() : NdbDataPrintFormat() {};
470  virtual ~NdbRecordPrintFormat() {};
471 };
472 
473 /* See also NdbDictionary::printFormattedValue() */
474 
475 NdbOut&
476 ndbrecattr_print_formatted(NdbOut& out, const NdbRecAttr &r,
477  const NdbRecordPrintFormat &f);
478 
479 #endif // ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
480 
481 #endif
482