1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/************************************************************************************************
Name: NdbRecAttr.C
Include:
Link:
Author: UABRONM Mikael Ronström UAB/B/SD
Date: 971206
Version: 0.1
Description: Interface between TIS and NDB
Documentation:
Adjust: 971206 UABRONM First version
************************************************************************************************/
#include "NdbRecAttr.hpp"
#include <stdlib.h>
#include "NdbDictionaryImpl.hpp"
NdbRecAttr::NdbRecAttr() :
theStorageX(NULL),
theValue(NULL),
theRef(NULL),
theNext(NULL),
theAttrId(0xFFFF),
theNULLind(-1)
{
}
NdbRecAttr::~NdbRecAttr()
{
release();
}
int
NdbRecAttr::setup(const NdbColumnImpl* anAttrInfo, char* aValue)
{
Uint32 tAttrSize = anAttrInfo->m_attrSize;
Uint32 tArraySize = anAttrInfo->m_arraySize;
Uint32 tAttrByteSize = tAttrSize * tArraySize;
m_column = anAttrInfo;
theAttrId = anAttrInfo->m_attrId;
theAttrSize = tAttrSize;
theArraySize = tArraySize;
theValue = aValue;
// check alignment to signal data
// a future version could check alignment per data type as well
if (aValue != NULL && (UintPtr(aValue)&3) == 0 && (tAttrByteSize&3) == 0) {
theStorageX = NULL;
theRef = aValue;
return 0;
}
if (tAttrByteSize <= 32) {
theStorageX = NULL;
theStorage[0] = 0;
theStorage[1] = 0;
theStorage[2] = 0;
theStorage[3] = 0;
theRef = theStorage;
return 0;
}
Uint32 tSize = (tAttrByteSize + 7) >> 3;
Uint64* tRef = new Uint64[tSize];
if (tRef != NULL) {
for (Uint32 i = 0; i < tSize; i++) {
tRef[i] = 0;
}
theStorageX = tRef;
theRef = tRef;
return 0;
}
return -1;
}
void
NdbRecAttr::copyout()
{
char* tRef = (char*)theRef;
char* tValue = theValue;
if (tRef != tValue && tRef != NULL && tValue != NULL) {
Uint32 n = theAttrSize * theArraySize;
while (n-- > 0) {
*tValue++ = *tRef++;
}
}
}
NdbRecAttr *
NdbRecAttr::clone() const {
NdbRecAttr * ret = new NdbRecAttr();
ret->theAttrId = theAttrId;
ret->theNULLind = theNULLind;
ret->theAttrSize = theAttrSize;
ret->theArraySize = theArraySize;
ret->m_column = m_column;
Uint32 n = theAttrSize * theArraySize;
if(n <= 32){
ret->theRef = (char*)&ret->theStorage[0];
ret->theStorageX = 0;
ret->theValue = 0;
} else {
ret->theStorageX = new Uint64[((n + 7) >> 3)];
ret->theRef = (char*)ret->theStorageX;
ret->theValue = 0;
}
memcpy(ret->theRef, theRef, n);
return ret;
}
|