forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdbOperationDefine.cpp
More file actions
1413 lines (1288 loc) · 40.1 KB
/
NdbOperationDefine.cpp
File metadata and controls
1413 lines (1288 loc) · 40.1 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
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; version 2 of the License.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "API.hpp"
#include "NdbOut.hpp"
#include <NdbBlob.hpp>
#include <Interpreter.hpp>
#include <NdbInterpretedCode.hpp>
#include <AttributeHeader.hpp>
#include <signaldata/TcKeyReq.hpp>
/*****************************************************************************
* int insertTuple();
*****************************************************************************/
int
NdbOperation::insertTuple()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
theOperationType = InsertRequest;
tNdbCon->theSimpleState = 0;
theErrorLine = tErrorLine++;
theLockMode = LM_Exclusive;
m_abortOption = AbortOnError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::insertTuple()
/******************************************************************************
* int updateTuple();
*****************************************************************************/
int
NdbOperation::updateTuple()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
tNdbCon->theSimpleState = 0;
theOperationType = UpdateRequest;
theErrorLine = tErrorLine++;
theLockMode = LM_Exclusive;
m_abortOption = AbortOnError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::updateTuple()
/*****************************************************************************
* int writeTuple();
*****************************************************************************/
int
NdbOperation::writeTuple()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
tNdbCon->theSimpleState = 0;
theOperationType = WriteRequest;
theErrorLine = tErrorLine++;
theLockMode = LM_Exclusive;
m_abortOption = AbortOnError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::writeTuple()
/*****************************************************************************
* int deleteTuple();
*****************************************************************************/
int
NdbOperation::deleteTuple()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
tNdbCon->theSimpleState = 0;
theOperationType = DeleteRequest;
theErrorLine = tErrorLine++;
theLockMode = LM_Exclusive;
m_abortOption = AbortOnError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::deleteTuple()
/******************************************************************************
* int readTuple();
*****************************************************************************/
int
NdbOperation::readTuple(NdbOperation::LockMode lm)
{
switch(lm) {
case LM_Read:
return readTuple();
break;
case LM_Exclusive:
return readTupleExclusive();
break;
case LM_CommittedRead:
return committedRead();
break;
case LM_SimpleRead:
return simpleRead();
default:
return -1;
};
}
/******************************************************************************
* int readTuple();
*****************************************************************************/
int
NdbOperation::readTuple()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
tNdbCon->theSimpleState = 0;
theOperationType = ReadRequest;
theErrorLine = tErrorLine++;
theLockMode = LM_Read;
m_abortOption = AO_IgnoreError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::readTuple()
/******************************************************************************
* int readTupleExclusive();
*****************************************************************************/
int
NdbOperation::readTupleExclusive()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
tNdbCon->theSimpleState = 0;
theOperationType = ReadExclusive;
theErrorLine = tErrorLine++;
theLockMode = LM_Exclusive;
m_abortOption = AO_IgnoreError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::readTupleExclusive()
/*****************************************************************************
* int simpleRead();
*****************************************************************************/
int
NdbOperation::simpleRead()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
theOperationType = ReadRequest;
theSimpleIndicator = 1;
theDirtyIndicator = 0;
theErrorLine = tErrorLine++;
theLockMode = LM_SimpleRead;
m_abortOption = AO_IgnoreError;
tNdbCon->theSimpleState = 0;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::simpleRead()
/*****************************************************************************
* int dirtyRead();
*****************************************************************************/
int
NdbOperation::dirtyRead()
{
return committedRead();
}//NdbOperation::dirtyRead()
/*****************************************************************************
* int committedRead();
*****************************************************************************/
int
NdbOperation::committedRead()
{
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
theOperationType = ReadRequest;
theSimpleIndicator = 1;
theDirtyIndicator = 1;
theErrorLine = tErrorLine++;
theLockMode = LM_CommittedRead;
m_abortOption = AO_IgnoreError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::committedRead()
/*****************************************************************************
* int dirtyUpdate();
****************************************************************************/
int
NdbOperation::dirtyUpdate()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
theOperationType = UpdateRequest;
tNdbCon->theSimpleState = 0;
theSimpleIndicator = 1;
theDirtyIndicator = 1;
theErrorLine = tErrorLine++;
theLockMode = LM_CommittedRead;
m_abortOption = AbortOnError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::dirtyUpdate()
/******************************************************************************
* int dirtyWrite();
*****************************************************************************/
int
NdbOperation::dirtyWrite()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
theOperationType = WriteRequest;
tNdbCon->theSimpleState = 0;
theSimpleIndicator = 1;
theDirtyIndicator = 1;
theErrorLine = tErrorLine++;
theLockMode = LM_CommittedRead;
m_abortOption = AbortOnError;
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::dirtyWrite()
/******************************************************************************
* int interpretedUpdateTuple();
****************************************************************************/
int
NdbOperation::interpretedUpdateTuple()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
tNdbCon->theSimpleState = 0;
theOperationType = UpdateRequest;
theAI_LenInCurrAI = 25;
theLockMode = LM_Exclusive;
theErrorLine = tErrorLine++;
m_abortOption = AbortOnError;
initInterpreter();
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::interpretedUpdateTuple()
/*****************************************************************************
* int interpretedDeleteTuple();
*****************************************************************************/
int
NdbOperation::interpretedDeleteTuple()
{
NdbTransaction* tNdbCon = theNdbCon;
int tErrorLine = theErrorLine;
if (theStatus == Init) {
theStatus = OperationDefined;
tNdbCon->theSimpleState = 0;
theOperationType = DeleteRequest;
theErrorLine = tErrorLine++;
theAI_LenInCurrAI = 25;
theLockMode = LM_Exclusive;
m_abortOption = AbortOnError;
initInterpreter();
return 0;
} else {
setErrorCode(4200);
return -1;
}//if
}//NdbOperation::interpretedDeleteTuple()
void
NdbOperation::setReadLockMode(LockMode lockMode)
{
/* We only support changing lock mode for read operations at this time. */
assert(theOperationType == ReadRequest || theOperationType == ReadExclusive);
switch (lockMode) {
case LM_CommittedRead: /* TODO, check theNdbCon->theSimpleState */
theOperationType= ReadRequest;
theSimpleIndicator= 1;
theDirtyIndicator= 1;
break;
case LM_SimpleRead: /* TODO, check theNdbCon->theSimpleState */
theOperationType= ReadRequest;
theSimpleIndicator= 1;
theDirtyIndicator= 0;
break;
case LM_Read:
theNdbCon->theSimpleState= 0;
theOperationType= ReadRequest;
theSimpleIndicator= 0;
theDirtyIndicator= 0;
break;
case LM_Exclusive:
theNdbCon->theSimpleState= 0;
theOperationType= ReadExclusive;
theSimpleIndicator= 0;
theDirtyIndicator= 0;
break;
default:
/* Not supported / invalid. */
assert(false);
}
theLockMode= lockMode;
}
/******************************************************************************
* int getValue(AttrInfo* tAttrInfo, char* aRef )
*
* Return Value Return 0 : GetValue was successful.
* Return -1: In all other case.
* Parameters: tAttrInfo : Attribute object of the retrieved attribute
* value.
* Remark: Define an attribute to retrieve in query.
*****************************************************************************/
NdbRecAttr*
NdbOperation::getValue_impl(const NdbColumnImpl* tAttrInfo, char* aValue)
{
NdbRecAttr* tRecAttr;
if ((tAttrInfo != NULL) &&
(theStatus != Init)){
if (tAttrInfo->m_storageType == NDB_STORAGETYPE_DISK)
{
m_flags &= ~Uint8(OF_NO_DISK);
}
if (theStatus != GetValue) {
if (theStatus == UseNdbRecord)
/* This path for extra GetValues for NdbRecord */
return getValue_NdbRecord(tAttrInfo, aValue);
if (theInterpretIndicator == 1) {
if (theStatus == FinalGetValue) {
; // Simply continue with getValue
} else if (theStatus == ExecInterpretedValue) {
if (insertATTRINFO(Interpreter::EXIT_OK) == -1)
return NULL;
theInterpretedSize = theTotalCurrAI_Len -
(theInitialReadSize + 5);
} else if (theStatus == SetValueInterpreted) {
theFinalUpdateSize = theTotalCurrAI_Len -
(theInitialReadSize + theInterpretedSize + 5);
} else {
setErrorCodeAbort(4230);
return NULL;
}//if
/* Final read, after running interpreted instructions. */
theStatus = FinalGetValue;
} else {
setErrorCodeAbort(4230);
return NULL;
}//if
}//if
AttributeHeader ah(tAttrInfo->m_attrId, 0);
if (insertATTRINFO(ah.m_value) != -1) {
// Insert Attribute Id into ATTRINFO part.
/************************************************************************
* Get a Receive Attribute object and link it into the operation object.
***********************************************************************/
if((tRecAttr = theReceiver.getValue(tAttrInfo, aValue)) != 0){
theErrorLine++;
return tRecAttr;
} else {
setErrorCodeAbort(4000);
return NULL;
}
} else {
return NULL;
}//if insertATTRINFO failure
} else {
if (tAttrInfo == NULL) {
setErrorCodeAbort(4004);
return NULL;
}//if
}//if
setErrorCodeAbort(4200);
return NULL;
}
NdbRecAttr*
NdbOperation::getValue_NdbRecord(const NdbColumnImpl* tAttrInfo, char* aValue)
{
NdbRecAttr* tRecAttr;
if (tAttrInfo->m_storageType == NDB_STORAGETYPE_DISK)
{
m_flags &= ~Uint8(OF_NO_DISK);
}
/*
For getValue with NdbRecord operations, we just allocate the NdbRecAttr,
the signal data will be constructed later.
*/
if((tRecAttr = theReceiver.getValue(tAttrInfo, aValue)) != 0) {
theErrorLine++;
return tRecAttr;
} else {
setErrorCodeAbort(4000);
return NULL;
}
}
/*****************************************************************************
* int setValue(AttrInfo* tAttrInfo, char* aValue, Uint32 len)
*
* Return Value: Return 0 : SetValue was succesful.
* Return -1: In all other case.
* Parameters: tAttrInfo : Attribute object where the attribute
* info exists.
* aValue : Reference to the variable with the new value.
* len : Length of the value
* Remark: Define a attribute to set in a query.
******************************************************************************/
int
NdbOperation::setValue( const NdbColumnImpl* tAttrInfo,
const char* aValuePassed)
{
DBUG_ENTER("NdbOperation::setValue");
DBUG_PRINT("enter", ("col: %s op:%d val: 0x%lx",
tAttrInfo ? tAttrInfo->m_name.c_str() : "NULL",
theOperationType, (long) aValuePassed));
int tReturnCode;
Uint32 tAttrId;
Uint32 tData;
Uint32 tempData[ NDB_MAX_TUPLE_SIZE_IN_WORDS ];
OperationType tOpType = theOperationType;
OperationStatus tStatus = theStatus;
if ((tOpType == UpdateRequest) ||
(tOpType == WriteRequest)) {
if (theInterpretIndicator == 0) {
if (tStatus == SetValue) {
;
} else {
setErrorCodeAbort(4234);
DBUG_RETURN(-1);
}//if
} else {
if (tStatus == GetValue) {
theInitialReadSize = theTotalCurrAI_Len - 5;
} else if (tStatus == ExecInterpretedValue) {
//--------------------------------------------------------------------
// We insert an exit from interpretation since we are now starting
// to set values in the tuple by setValue.
//--------------------------------------------------------------------
if (insertATTRINFO(Interpreter::EXIT_OK) == -1){
DBUG_RETURN(-1);
}
theInterpretedSize = theTotalCurrAI_Len -
(theInitialReadSize + 5);
} else if (tStatus == SetValueInterpreted) {
; // Simply continue adding new setValue
} else {
//--------------------------------------------------------------------
// setValue used in the wrong context. Application coding error.
//-------------------------------------------------------------------
setErrorCodeAbort(4234); //Wrong error code
DBUG_RETURN(-1);
}//if
theStatus = SetValueInterpreted;
}//if
} else if (tOpType == InsertRequest) {
if ((theStatus != SetValue) && (theStatus != OperationDefined)) {
setErrorCodeAbort(4234);
DBUG_RETURN(-1);
}//if
} else if (tOpType == ReadRequest || tOpType == ReadExclusive) {
setErrorCodeAbort(4504);
DBUG_RETURN(-1);
} else if (tOpType == DeleteRequest) {
setErrorCodeAbort(4504);
DBUG_RETURN(-1);
} else if (tOpType == OpenScanRequest || tOpType == OpenRangeScanRequest) {
setErrorCodeAbort(4228);
DBUG_RETURN(-1);
} else {
//---------------------------------------------------------------------
// setValue with undefined operation type.
// Probably application coding error.
//---------------------------------------------------------------------
setErrorCodeAbort(4108);
DBUG_RETURN(-1);
}//if
if (tAttrInfo == NULL) {
setErrorCodeAbort(4004);
DBUG_RETURN(-1);
}//if
if (tAttrInfo->m_pk) {
if (theOperationType == InsertRequest) {
DBUG_RETURN(equal_impl(tAttrInfo, aValuePassed));
} else {
setErrorCodeAbort(4202);
DBUG_RETURN(-1);
}//if
}//if
// Insert Attribute Id into ATTRINFO part.
tAttrId = tAttrInfo->m_attrId;
if (tAttrInfo->m_storageType == NDB_STORAGETYPE_DISK)
{
m_flags &= ~Uint8(OF_NO_DISK);
}
const char *aValue = aValuePassed;
if (aValue == NULL) {
if (tAttrInfo->m_nullable) {
AttributeHeader ah(tAttrId, 0);
ah.setNULL();
insertATTRINFO(ah.m_value);
// Insert Attribute Id with the value
// NULL into ATTRINFO part.
DBUG_RETURN(0);
} else {
/***********************************************************************
* Setting a NULL value on a NOT NULL attribute is not allowed.
**********************************************************************/
setErrorCodeAbort(4203);
DBUG_RETURN(-1);
}//if
}//if
Uint32 len;
if (! tAttrInfo->get_var_length(aValue, len)) {
setErrorCodeAbort(4209);
DBUG_RETURN(-1);
}
const Uint32 sizeInBytes = len;
const Uint32 bitsInLastWord = 8 * (sizeInBytes & 3) ;
const int attributeSize = sizeInBytes;
const int slack = sizeInBytes & 3;
if (((UintPtr)aValue & 3) != 0 || (slack != 0)){
memcpy(&tempData[0], aValue, attributeSize);
aValue = (char*)&tempData[0];
if(slack != 0) {
char * tmp = (char*)&tempData[0];
memset(&tmp[attributeSize], 0, (4 - slack));
}//if
}//if
// Excluding bits in last word
const Uint32 sizeInWords = sizeInBytes / 4;
AttributeHeader ah(tAttrId, sizeInBytes);
insertATTRINFO( ah.m_value );
/***********************************************************************
* Check if the pointer of the value passed is aligned on a 4 byte boundary.
* If so only assign the pointer to the internal variable aValue.
* If it is not aligned then we start by copying the value to tempData and
* use this as aValue instead.
*************************************************************************/
tReturnCode = insertATTRINFOloop((Uint32*)aValue, sizeInWords);
if (tReturnCode == -1) {
DBUG_RETURN(tReturnCode);
}//if
if (bitsInLastWord != 0) {
tData = *(Uint32*)(aValue + sizeInWords*4);
tData = convertEndian(tData);
tData = tData & ((1 << bitsInLastWord) - 1);
tData = convertEndian(tData);
tReturnCode = insertATTRINFO(tData);
if (tReturnCode == -1) {
DBUG_RETURN(tReturnCode);
}//if
}//if
theErrorLine++;
DBUG_RETURN(0);
}//NdbOperation::setValue()
int
NdbOperation::setAnyValue(Uint32 any_value)
{
OperationType tOpType = theOperationType;
if (theStatus == UseNdbRecord)
{
/* Method not allowed for NdbRecord, use OperationOptions or
ScanOptions structure instead */
setErrorCodeAbort(4515);
return -1;
}
const NdbColumnImpl* impl =
&NdbColumnImpl::getImpl(* NdbDictionary::Column::ANY_VALUE);
switch(tOpType){
case DeleteRequest:{
Uint32 ah;
AttributeHeader::init(&ah, AttributeHeader::ANY_VALUE, 4);
if (insertATTRINFO(ah) != -1 && insertATTRINFO(any_value) != -1 )
{
return 0;
}
}
default:
return setValue(impl, (const char *)&any_value);
}
setErrorCodeAbort(4000);
return -1;
}
int
NdbOperation::setOptimize(Uint32 options)
{
return setValue(&NdbColumnImpl::getImpl(*NdbDictionary::Column::OPTIMIZE),
(const char*)&options);
}
/* Non-const variant of getBlobHandle - can return existing blob
* handles, or create new ones for non-NdbRecord operations
*/
NdbBlob*
NdbOperation::getBlobHandle(NdbTransaction* aCon, const NdbColumnImpl* tAttrInfo)
{
NdbBlob* tBlob = theBlobList;
NdbBlob* tLastBlob = NULL;
while (tBlob != NULL) {
if (tBlob->theColumn == tAttrInfo)
return tBlob;
tLastBlob = tBlob;
tBlob = tBlob->theNext;
}
/*
* For NdbRecord PK, unique index and scan operations, we only fetch existing
* blob handles here, creation must be done by requesting the blob in the
* NdbRecord and mask when creating the operation.
* For NdbRecAttr PK, IK and scan operations, we allow Blob handles
* to be created here. Note that NdbRecAttr PK and unique index ops are handled
* differently to NdbRecAttr scan operations.
*/
if (m_attribute_record)
{
setErrorCodeAbort(4288);
return NULL;
}
/* Check key fully defined for key operations */
switch (theStatus)
{
case TupleKeyDefined:
case GetValue:
case SetValue:
case FinalGetValue:
case ExecInterpretedValue:
case SetValueInterpreted:
/* All ok states to create a Blob Handle in */
break;
default:
{
/* Unexpected state to be obtaining Blob handle */
/* Invalid usage of blob attribute */
setErrorCodeAbort(4264);
return NULL;
}
}
tBlob = theNdb->getNdbBlob();
if (tBlob == NULL)
return NULL;
if (tBlob->atPrepare(aCon, this, tAttrInfo) == -1) {
theNdb->releaseNdbBlob(tBlob);
return NULL;
}
if (tLastBlob == NULL)
theBlobList = tBlob;
else
tLastBlob->theNext = tBlob;
tBlob->theNext = NULL;
theNdbCon->theBlobFlag = true;
return tBlob;
}
/* const variant of getBlobHandle - only returns existing blob handles */
NdbBlob*
NdbOperation::getBlobHandle(NdbTransaction* aCon, const NdbColumnImpl* tAttrInfo) const
{
NdbBlob* tBlob = theBlobList;
while (tBlob != NULL) {
if (tBlob->theColumn == tAttrInfo)
return tBlob;
tBlob = tBlob->theNext;
}
/*
Const method - cannot create a new BLOB handle, NdbRecord
or NdbRecAttr
*/
setErrorCodeAbort(4288);
return NULL;
}
/*
This is used to set up a blob handle for an NdbRecord operation.
It allocates the NdbBlob object, initialises it, and links it into the
operation.
There are two cases for how to set up the primary key info:
1. Normal primary key or hash index key operations. The keyinfo argument
is passed as NULL, and the key value is read from the NdbRecord and
row passed from the application.
2. Take-over scan operation. The keyinfo argument points to a buffer
containing KEYINFO20 data.
For a scan operation, there is no key info to set up at prepare time.
*/
NdbBlob *
NdbOperation::linkInBlobHandle(NdbTransaction *aCon,
const NdbColumnImpl *column,
NdbBlob * & lastPtr)
{
int res;
NdbBlob *bh= theNdb->getNdbBlob();
if (bh == NULL)
return NULL;
if (theOperationType == OpenScanRequest ||
theOperationType == OpenRangeScanRequest)
{
res= bh->atPrepareNdbRecordScan(aCon, this, column);
}
else if (m_key_record == NULL)
{
/* This means that we have a scan take-over operation, and we should
obtain the key from KEYINFO20 data.
*/
res= bh->atPrepareNdbRecordTakeover(aCon, this, column,
m_key_row, m_keyinfo_length*4);
}
else
{
res= bh->atPrepareNdbRecord(aCon, this, column, m_key_record, m_key_row);
}
if (res == -1)
{
theNdb->releaseNdbBlob(bh);
return NULL;
}
if (lastPtr)
lastPtr->theNext= bh;
else
theBlobList= bh;
lastPtr= bh;
bh->theNext= NULL;
theNdbCon->theBlobFlag= true;
return bh;
}
/*
* Setup blob handles for an NdbRecord operation.
*
* Create blob handles for all requested blob columns.
*
* For read request, store the pointers to blob handles in the row.
*/
int
NdbOperation::getBlobHandlesNdbRecord(NdbTransaction* aCon,
const Uint32 * m_read_mask)
{
NdbBlob *lastBlob= NULL;
for (Uint32 i= 0; i<m_attribute_record->noOfColumns; i++)
{
const NdbRecord::Attr *col= &m_attribute_record->columns[i];
if (!(col->flags & NdbRecord::IsBlob))
continue;
Uint32 attrId= col->attrId;
if (!BitmaskImpl::get((NDB_MAX_ATTRIBUTES_IN_TABLE+31)>>5,
m_read_mask, attrId))
continue;
const NdbColumnImpl *tableColumn= m_currentTable->getColumn(attrId);
assert(tableColumn != NULL);
NdbBlob *bh= linkInBlobHandle(aCon, tableColumn, lastBlob);
if (bh == NULL)
return -1;
if (theOperationType == ReadRequest || theOperationType == ReadExclusive)
{
/*
* For read request, it is safe to cast away const-ness for the
* m_attribute_row.
*/
memcpy((char *)&m_attribute_row[col->offset], &bh, sizeof(bh));
}
}
return 0;
}
/*
For a delete, we need to create blob handles for all table blob columns,
so that we can be sure to delete all blob parts for the row.
If checkReadset is true, we also check that the caller is not asking to
read any blobs as part of the delete.
*/
int
NdbOperation::getBlobHandlesNdbRecordDelete(NdbTransaction* aCon,
bool checkReadSet,
const Uint32 * m_read_mask)
{
NdbBlob *lastBlob= NULL;
assert(theOperationType == DeleteRequest);
for (Uint32 i= 0; i < m_currentTable->m_columns.size(); i++)
{
const NdbColumnImpl* c= m_currentTable->m_columns[i];
assert(c != 0);
if (!c->getBlobType())
continue;
if (checkReadSet &&
(BitmaskImpl::get((NDB_MAX_ATTRIBUTES_IN_TABLE+31)>>5,
m_read_mask, c->m_attrId)))
{
/* Blobs are not allowed in NdbRecord delete result record */
setErrorCodeAbort(4511);
return -1;
}
NdbBlob *bh= linkInBlobHandle(aCon, c, lastBlob);
if (bh == NULL)
return -1;
}
return 0;
}
NdbRecAttr*
NdbOperation::getVarValue(const NdbColumnImpl* tAttrInfo,
char* aBareValue, Uint16* aLenLoc)
{
NdbRecAttr* ra = getValue(tAttrInfo, aBareValue);
if (ra != NULL) {
assert(aLenLoc != NULL);
ra->m_getVarValue = aLenLoc;
}
return ra;
}
int
NdbOperation::setVarValue(const NdbColumnImpl* tAttrInfo,
const char* aBareValue, const Uint16& aLen)
{
DBUG_ENTER("NdbOperation::setVarValue");
DBUG_PRINT("info", ("aLen=%u", (Uint32)aLen));
// wl3717_todo not optimal..
const Uint32 MaxTupleSizeInLongWords= (NDB_MAX_TUPLE_SIZE + 7)/ 8;
Uint64 buf[ MaxTupleSizeInLongWords ];
assert( aLen < (NDB_MAX_TUPLE_SIZE - 2) );
unsigned char* p = (unsigned char*)buf;
p[0] = (aLen & 0xff);
p[1] = (aLen >> 8);
memcpy(&p[2], aBareValue, aLen);
if (setValue(tAttrInfo, (char*)buf) == -1)
DBUG_RETURN(-1);
DBUG_RETURN(0);
}
/****************************************************************************
* int insertATTRINFO( Uint32 aData );
*
* Return Value: Return 0 : insertATTRINFO was succesful.
* Return -1: In all other case.
* Parameters: aData: the data to insert into ATTRINFO.
* Remark: Puts the the data into either TCKEYREQ signal or
* ATTRINFO signal.
*****************************************************************************/
int
NdbOperation::insertATTRINFO( Uint32 aData )
{
NdbApiSignal* tSignal;
register Uint32 tAI_LenInCurrAI = theAI_LenInCurrAI;
register Uint32* tAttrPtr = theATTRINFOptr;
register Uint32 tTotCurrAILen = theTotalCurrAI_Len;
if (tAI_LenInCurrAI >= 25) {
Ndb* tNdb = theNdb;
NdbApiSignal* tFirstAttrinfo = theFirstATTRINFO;
tAI_LenInCurrAI = 3;
tSignal = tNdb->getSignal();
if (tSignal != NULL) {
tSignal->setSignal(m_attrInfoGSN, refToBlock(theNdbCon->m_tcRef));
tAttrPtr = &tSignal->getDataPtrSend()[3];
if (tFirstAttrinfo == NULL) {
tSignal->next(NULL);
theFirstATTRINFO = tSignal;
theCurrentATTRINFO = tSignal;
} else {
NdbApiSignal* tCurrentAttrinfoBeforeUpdate = theCurrentATTRINFO;
tSignal->next(NULL);
theCurrentATTRINFO = tSignal;
tCurrentAttrinfoBeforeUpdate->next(tSignal);
}//if
} else {
goto insertATTRINFO_error1;
}//if
}//if
*tAttrPtr = aData;
tAttrPtr++;
tTotCurrAILen++;
tAI_LenInCurrAI++;
theTotalCurrAI_Len = tTotCurrAILen;
theAI_LenInCurrAI = tAI_LenInCurrAI;
theATTRINFOptr = tAttrPtr;
return 0;
insertATTRINFO_error1:
setErrorCodeAbort(4000);
return -1;
}//NdbOperation::insertATTRINFO()
/*****************************************************************************
* int insertATTRINFOloop(Uint32* aDataPtr, Uint32 aLength );
*
* Return Value: Return 0 : insertATTRINFO was succesful.
* Return -1: In all other case.
* Parameters: aDataPtr: Pointer to the data to insert into ATTRINFO.
* aLength: Length of data to be copied
* Remark: Puts the the data into either TCKEYREQ signal or
* ATTRINFO signal.
*****************************************************************************/
int
NdbOperation::insertATTRINFOloop(register const Uint32* aDataPtr,
register Uint32 aLength)
{
NdbApiSignal* tSignal;
register Uint32 tAI_LenInCurrAI = theAI_LenInCurrAI;