DbtupRoutines.cpp 38.1 KB
Newer Older
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
/* 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 */


#define DBTUP_C
#include "Dbtup.hpp"
#include <RefConvert.hpp>
#include <ndb_limits.h>
#include <pc.hpp>
#include <AttributeDescriptor.hpp>
#include "AttributeOffset.hpp"
#include <AttributeHeader.hpp>

#define ljam() { jamLine(3000 + __LINE__); }
#define ljamEntry() { jamEntryLine(3000 + __LINE__); }

void
Dbtup::setUpQueryRoutines(Tablerec* const regTabPtr)
{
  Uint32 startDescriptor = regTabPtr->tabDescriptor;
  ndbrequire((startDescriptor + (regTabPtr->noOfAttr << ZAD_LOG_SIZE)) <= cnoOfTabDescrRec);
  for (Uint32 i = 0; i < regTabPtr->noOfAttr; i++) {
    Uint32 attrDescriptorStart = startDescriptor + (i << ZAD_LOG_SIZE);
    Uint32 attrDescriptor = tableDescriptor[attrDescriptorStart].tabDescr;
38
    Uint32 attrOffset = tableDescriptor[attrDescriptorStart + 1].tabDescr;
39 40 41 42
    if (!AttributeDescriptor::getDynamic(attrDescriptor)) {
      if ((AttributeDescriptor::getArrayType(attrDescriptor) == ZNON_ARRAY) ||
          (AttributeDescriptor::getArrayType(attrDescriptor) == ZFIXED_ARRAY)) {
        if (!AttributeDescriptor::getNullable(attrDescriptor)) {
43 44 45 46 47
	  if (AttributeDescriptor::getSize(attrDescriptor) == 0){
	    ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readBitsNotNULL;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateBitsNotNULL;
	  } else if (AttributeDescriptor::getSizeInWords(attrDescriptor) == 1){
48 49 50 51 52 53 54 55 56 57 58 59 60 61
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readFixedSizeTHOneWordNotNULL;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateFixedSizeTHOneWordNotNULL;
          } else if (AttributeDescriptor::getSizeInWords(attrDescriptor) == 2) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readFixedSizeTHTwoWordNotNULL;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateFixedSizeTHTwoWordNotNULL;
          } else if (AttributeDescriptor::getSizeInWords(attrDescriptor) > 2) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readFixedSizeTHManyWordNotNULL;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateFixedSizeTHManyWordNotNULL;
          } else {
            ndbrequire(false);
          }//if
62 63 64 65 66
          // replace read function of char attribute
          if (AttributeOffset::getCharsetFlag(attrOffset)) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readCharNotNULL;
          }
67
        } else {
68 69 70 71 72
	  if (AttributeDescriptor::getSize(attrDescriptor) == 0){
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readBitsNULLable;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateBitsNULLable;
	  } else if (AttributeDescriptor::getSizeInWords(attrDescriptor) == 1){
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readFixedSizeTHOneWordNULLable;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateFixedSizeTHManyWordNULLable;
          } else if (AttributeDescriptor::getSizeInWords(attrDescriptor) == 2) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readFixedSizeTHTwoWordNULLable;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateFixedSizeTHManyWordNULLable;
          } else if (AttributeDescriptor::getSizeInWords(attrDescriptor) > 2) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readFixedSizeTHManyWordNULLable;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateFixedSizeTHManyWordNULLable;
          } else {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readFixedSizeTHZeroWordNULLable;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateFixedSizeTHManyWordNULLable;
          }//if
89 90 91 92 93
          // replace read function of char attribute
          if (AttributeOffset::getCharsetFlag(attrOffset)) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readCharNULLable;
          }
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
        }//if
      } else if (AttributeDescriptor::getArrayType(attrDescriptor) == ZVAR_ARRAY) {
        if (!AttributeDescriptor::getNullable(attrDescriptor)) {
          if (AttributeDescriptor::getArraySize(attrDescriptor) == 0) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readVarSizeUnlimitedNotNULL;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateVarSizeUnlimitedNotNULL;
          } else if (AttributeDescriptor::getArraySize(attrDescriptor) > ZMAX_SMALL_VAR_ARRAY) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readBigVarSizeNotNULL;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateBigVarSizeNotNULL;
          } else {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readSmallVarSizeNotNULL;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateSmallVarSizeNotNULL;
          }//if
        } else {
          if (AttributeDescriptor::getArraySize(attrDescriptor) == 0) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readVarSizeUnlimitedNULLable;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateVarSizeUnlimitedNULLable;
          } else if (AttributeDescriptor::getArraySize(attrDescriptor) > ZMAX_SMALL_VAR_ARRAY) {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readBigVarSizeNULLable;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateBigVarSizeNULLable;
          } else {
            ljam();
            regTabPtr->readFunctionArray[i] = &Dbtup::readSmallVarSizeNULLable;
            regTabPtr->updateFunctionArray[i] = &Dbtup::updateSmallVarSizeNULLable;
          }//if
        }//if
      } else {
        ndbrequire(false);
      }//if
    } else {
      if ((AttributeDescriptor::getArrayType(attrDescriptor) == ZNON_ARRAY) ||
          (AttributeDescriptor::getArrayType(attrDescriptor) == ZFIXED_ARRAY)) {
        ljam();
        regTabPtr->readFunctionArray[i] = &Dbtup::readDynFixedSize;
        regTabPtr->updateFunctionArray[i] = &Dbtup::updateDynFixedSize;
      } else if (AttributeDescriptor::getType(attrDescriptor) == ZVAR_ARRAY) {
        if (AttributeDescriptor::getArraySize(attrDescriptor) == 0) {
          ljam();
          regTabPtr->readFunctionArray[i] = &Dbtup::readDynVarSizeUnlimited;
          regTabPtr->updateFunctionArray[i] = &Dbtup::updateDynVarSizeUnlimited;
        } else if (AttributeDescriptor::getArraySize(attrDescriptor) > ZMAX_SMALL_VAR_ARRAY) {
          ljam();
          regTabPtr->readFunctionArray[i] = &Dbtup::readDynBigVarSize;
          regTabPtr->updateFunctionArray[i] = &Dbtup::updateDynBigVarSize;
        } else {
          ljam();
          regTabPtr->readFunctionArray[i] = &Dbtup::readDynSmallVarSize;
          regTabPtr->updateFunctionArray[i] = &Dbtup::updateDynSmallVarSize;
        }//if
      } else {
        ndbrequire(false);
      }//if
    }//if
  }//for
}//Dbtup::setUpQueryRoutines()

/* ---------------------------------------------------------------- */
/*       THIS ROUTINE IS USED TO READ A NUMBER OF ATTRIBUTES IN THE */
/*       DATABASE AND PLACE THE RESULT IN ATTRINFO RECORDS.         */
//
// In addition to the parameters used in the call it also relies on the
// following variables set-up properly.
//
// operPtr.p      Operation record pointer
// fragptr.p      Fragment record pointer
// tabptr.p       Table record pointer
/* ---------------------------------------------------------------- */
int Dbtup::readAttributes(Page* const pagePtr,
167 168 169 170 171 172
			  Uint32  tupHeadOffset,
			  const Uint32* inBuffer,
			  Uint32  inBufLen,
			  Uint32* outBuffer,
			  Uint32  maxRead,
			  bool    xfrmFlag)
173 174 175 176 177 178 179 180 181 182 183 184
{
  Tablerec* const regTabPtr =  tabptr.p;
  Uint32 numAttributes = regTabPtr->noOfAttr;
  Uint32 attrDescriptorStart = regTabPtr->tabDescriptor;
  Uint32 inBufIndex = 0;

  ndbrequire(attrDescriptorStart + (numAttributes << ZAD_LOG_SIZE) <= cnoOfTabDescrRec);

  tOutBufIndex = 0;
  tCheckOffset = regTabPtr->tupheadsize;
  tMaxRead = maxRead;
  tTupleHeader = &pagePtr->pageWord[tupHeadOffset];
185
  tXfrmFlag = xfrmFlag;
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

  ndbrequire(tupHeadOffset + tCheckOffset <= ZWORDS_ON_PAGE);
  while (inBufIndex < inBufLen) {
    Uint32 tmpAttrBufIndex = tOutBufIndex;
    AttributeHeader ahIn(inBuffer[inBufIndex]);
    inBufIndex++;
    Uint32 attributeId = ahIn.getAttributeId();
    Uint32 attrDescriptorIndex = attrDescriptorStart + (attributeId << ZAD_LOG_SIZE);
    ljam();

    AttributeHeader::init(&outBuffer[tmpAttrBufIndex], attributeId, 0);
    AttributeHeader* ahOut = (AttributeHeader*)&outBuffer[tmpAttrBufIndex];
    tOutBufIndex = tmpAttrBufIndex + 1;
    if (attributeId < numAttributes) {
      Uint32 attributeDescriptor = tableDescriptor[attrDescriptorIndex].tabDescr;
      Uint32 attributeOffset = tableDescriptor[attrDescriptorIndex + 1].tabDescr;
      ReadFunction f = regTabPtr->readFunctionArray[attributeId];
      if ((this->*f)(outBuffer,
                     ahOut,
                     attributeDescriptor,
                     attributeOffset)) {
        continue;
      } else {
209
        return -1;
210
      }//if
joreland@mysql.com's avatar
joreland@mysql.com committed
211 212 213 214 215
    } else if(attributeId & AttributeHeader::PSUEDO){
      Uint32 sz = read_psuedo(attributeId, 
			      outBuffer+tmpAttrBufIndex+1);
      AttributeHeader::init(&outBuffer[tmpAttrBufIndex], attributeId, sz);
      tOutBufIndex = tmpAttrBufIndex + 1 + sz;
216 217
    } else {
      terrorCode = ZATTRIBUTE_ID_ERROR;
218
      return -1;
219 220 221 222 223
    }//if
  }//while
  return tOutBufIndex;
}//Dbtup::readAttributes()

224
#if 0
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
int Dbtup::readAttributesWithoutHeader(Page* const pagePtr,
                                       Uint32  tupHeadOffset,
                                       Uint32* inBuffer,
                                       Uint32  inBufLen,
                                       Uint32* outBuffer,
                                       Uint32* attrBuffer,
                                       Uint32  maxRead)
{
  Tablerec* const regTabPtr =  tabptr.p;
  Uint32 numAttributes = regTabPtr->noOfAttr;
  Uint32 attrDescriptorStart = regTabPtr->tabDescriptor;
  Uint32 inBufIndex = 0;
  Uint32 attrBufIndex = 0;

  ndbrequire(attrDescriptorStart + (numAttributes << ZAD_LOG_SIZE) <= cnoOfTabDescrRec);

  tOutBufIndex = 0;
  tCheckOffset = regTabPtr->tupheadsize;
  tMaxRead = maxRead;
  tTupleHeader = &pagePtr->pageWord[tupHeadOffset];

  ndbrequire(tupHeadOffset + tCheckOffset <= ZWORDS_ON_PAGE);
  while (inBufIndex < inBufLen) {
    AttributeHeader ahIn(inBuffer[inBufIndex]);
    inBufIndex++;
    Uint32 attributeId = ahIn.getAttributeId();
    Uint32 attrDescriptorIndex = attrDescriptorStart + (attributeId << ZAD_LOG_SIZE);
    ljam();

    AttributeHeader::init(&attrBuffer[attrBufIndex], attributeId, 0);
    AttributeHeader* ahOut = (AttributeHeader*)&attrBuffer[attrBufIndex];
    attrBufIndex++;
    if (attributeId < numAttributes) {
      Uint32 attributeDescriptor = tableDescriptor[attrDescriptorIndex].tabDescr;
      Uint32 attributeOffset = tableDescriptor[attrDescriptorIndex + 1].tabDescr;
      ReadFunction f = regTabPtr->readFunctionArray[attributeId];
      if ((this->*f)(outBuffer,
                     ahOut,
                     attributeDescriptor,
                     attributeOffset)) {
        continue;
      } else {
267
        return -1;
268 269 270
      }//if
    } else {
      terrorCode = ZATTRIBUTE_ID_ERROR;
271
      return -1;
272 273 274 275 276
    }//if
  }//while
  ndbrequire(attrBufIndex == inBufLen);
  return tOutBufIndex;
}//Dbtup::readAttributes()
277
#endif
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

bool
Dbtup::readFixedSizeTHOneWordNotNULL(Uint32* outBuffer,
                                     AttributeHeader* ahOut,
                                     Uint32  attrDescriptor,
                                     Uint32  attrDes2)
{
  Uint32 indexBuf = tOutBufIndex;
  Uint32 readOffset = AttributeOffset::getOffset(attrDes2);
  Uint32 const wordRead = tTupleHeader[readOffset];
  Uint32 newIndexBuf = indexBuf + 1;
  Uint32 maxRead = tMaxRead;

  ndbrequire(readOffset < tCheckOffset);
  if (newIndexBuf <= maxRead) {
    ljam();
    outBuffer[indexBuf] = wordRead;
    ahOut->setDataSize(1);
    tOutBufIndex = newIndexBuf;
    return true;
  } else {
    ljam();
    terrorCode = ZTRY_TO_READ_TOO_MUCH_ERROR;
    return false;
  }//if
}//Dbtup::readFixedSizeTHOneWordNotNULL()

bool
Dbtup::readFixedSizeTHTwoWordNotNULL(Uint32* outBuffer,
                                     AttributeHeader* ahOut,
                                     Uint32  attrDescriptor,
                                     Uint32  attrDes2)
{
  Uint32 indexBuf = tOutBufIndex;
  Uint32 readOffset = AttributeOffset::getOffset(attrDes2);
  Uint32 const wordReadFirst = tTupleHeader[readOffset];
  Uint32 const wordReadSecond = tTupleHeader[readOffset + 1];
  Uint32 newIndexBuf = indexBuf + 2;
  Uint32 maxRead = tMaxRead;

  ndbrequire(readOffset + 1 < tCheckOffset);
  if (newIndexBuf <= maxRead) {
    ljam();
    ahOut->setDataSize(2);
    outBuffer[indexBuf] = wordReadFirst;
    outBuffer[indexBuf + 1] = wordReadSecond;
    tOutBufIndex = newIndexBuf;
    return true;
  } else {
    ljam();
    terrorCode = ZTRY_TO_READ_TOO_MUCH_ERROR;
    return false;
  }//if
}//Dbtup::readFixedSizeTHTwoWordNotNULL()

bool
Dbtup::readFixedSizeTHManyWordNotNULL(Uint32* outBuffer,
                                      AttributeHeader* ahOut,
                                      Uint32  attrDescriptor,
                                      Uint32  attrDes2)
{
  Uint32 indexBuf = tOutBufIndex;
  Uint32 readOffset = AttributeOffset::getOffset(attrDes2);
  Uint32 attrNoOfWords = AttributeDescriptor::getSizeInWords(attrDescriptor);
  Uint32 newIndexBuf = indexBuf + attrNoOfWords;
  Uint32 maxRead = tMaxRead;

  ndbrequire((readOffset + attrNoOfWords - 1) < tCheckOffset);
  if (newIndexBuf <= maxRead) {
    ljam();
    ahOut->setDataSize(attrNoOfWords);
    MEMCOPY_NO_WORDS(&outBuffer[indexBuf],
                     &tTupleHeader[readOffset],
                     attrNoOfWords);
    tOutBufIndex = newIndexBuf;
    return true;
  } else {
    ljam();
    terrorCode = ZTRY_TO_READ_TOO_MUCH_ERROR;
    return false;
  }//if
}//Dbtup::readFixedSizeTHManyWordNotNULL()

bool
Dbtup::readFixedSizeTHOneWordNULLable(Uint32* outBuffer,
                                      AttributeHeader* ahOut,
                                      Uint32  attrDescriptor,
                                      Uint32  attrDes2)
{
  if (!nullFlagCheck(attrDes2)) {
    ljam();
    return readFixedSizeTHOneWordNotNULL(outBuffer,
                                         ahOut,
                                         attrDescriptor,
                                         attrDes2);
  } else {
    ljam();
    ahOut->setNULL();
    return true;
  }//if
}//Dbtup::readFixedSizeTHOneWordNULLable()

bool
Dbtup::readFixedSizeTHTwoWordNULLable(Uint32* outBuffer,
                                      AttributeHeader* ahOut,
                                      Uint32  attrDescriptor,
                                      Uint32  attrDes2)
{
  if (!nullFlagCheck(attrDes2)) {
    ljam();
    return readFixedSizeTHTwoWordNotNULL(outBuffer,
                                         ahOut,
                                         attrDescriptor,
                                         attrDes2);
  } else {
    ljam();
    ahOut->setNULL();
    return true;
  }//if
}//Dbtup::readFixedSizeTHTwoWordNULLable()

bool
Dbtup::readFixedSizeTHManyWordNULLable(Uint32* outBuffer,
                                       AttributeHeader* ahOut,
                                       Uint32  attrDescriptor,
                                       Uint32  attrDes2)
{
ljam();
  if (!nullFlagCheck(attrDes2)) {
    ljam();
    return readFixedSizeTHManyWordNotNULL(outBuffer,
                                          ahOut,
                                          attrDescriptor,
                                          attrDes2);
  } else {
    ljam();
    ahOut->setNULL();
    return true;
  }//if
}//Dbtup::readFixedSizeTHManyWordNULLable()

bool
Dbtup::readFixedSizeTHZeroWordNULLable(Uint32* outBuffer,
                                       AttributeHeader* ahOut,
                                       Uint32  attrDescriptor,
                                       Uint32  attrDes2)
{
  ljam();
  if (nullFlagCheck(attrDes2)) {
    ljam();
    ahOut->setNULL();
  }//if
  return true;
}//Dbtup::readFixedSizeTHZeroWordNULLable()

bool
Dbtup::nullFlagCheck(Uint32  attrDes2)
{
  Tablerec* const regTabPtr = tabptr.p;
  Uint32 nullFlagOffsetInTuple = AttributeOffset::getNullFlagOffset(attrDes2);
  ndbrequire(nullFlagOffsetInTuple < regTabPtr->tupNullWords);
  nullFlagOffsetInTuple += regTabPtr->tupNullIndex;
  ndbrequire(nullFlagOffsetInTuple < tCheckOffset);

  return (AttributeOffset::isNULL(tTupleHeader[nullFlagOffsetInTuple], attrDes2));
}//Dbtup::nullFlagCheck()

bool
Dbtup::readVariableSizedAttr(Uint32* outBuffer,
                             AttributeHeader* ahOut,
                             Uint32  attrDescriptor,
                             Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readVariableSizedAttr()

bool
Dbtup::readVarSizeUnlimitedNotNULL(Uint32* outBuffer,
                                   AttributeHeader* ahOut,
                                   Uint32  attrDescriptor,
                                   Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readVarSizeUnlimitedNotNULL()

bool
Dbtup::readVarSizeUnlimitedNULLable(Uint32* outBuffer,
                                    AttributeHeader* ahOut,
                                    Uint32  attrDescriptor,
                                    Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readVarSizeUnlimitedNULLable()

bool
Dbtup::readBigVarSizeNotNULL(Uint32* outBuffer,
                             AttributeHeader* ahOut,
                             Uint32  attrDescriptor,
                             Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readBigVarSizeNotNULL()

bool
Dbtup::readBigVarSizeNULLable(Uint32* outBuffer,
                             AttributeHeader* ahOut,
                             Uint32  attrDescriptor,
                             Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readBigVarSizeNULLable()

bool
Dbtup::readSmallVarSizeNotNULL(Uint32* outBuffer,
                               AttributeHeader* ahOut,
                               Uint32  attrDescriptor,
                               Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readSmallVarSizeNotNULL()

bool
Dbtup::readSmallVarSizeNULLable(Uint32* outBuffer,
                                AttributeHeader* ahOut,
                                Uint32  attrDescriptor,
                                Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readSmallVarSizeNULLable()

bool
Dbtup::readDynFixedSize(Uint32* outBuffer,
                        AttributeHeader* ahOut,
                        Uint32  attrDescriptor,
                        Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readDynFixedSize()

bool
Dbtup::readDynVarSizeUnlimited(Uint32* outBuffer,
                               AttributeHeader* ahOut,
                               Uint32  attrDescriptor,
                               Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readDynVarSizeUnlimited()

bool
Dbtup::readDynBigVarSize(Uint32* outBuffer,
                         AttributeHeader* ahOut,
                         Uint32  attrDescriptor,
                         Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readDynBigVarSize()

bool
Dbtup::readDynSmallVarSize(Uint32* outBuffer,
                           AttributeHeader* ahOut,
                           Uint32  attrDescriptor,
                           Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::readDynSmallVarSize()

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

bool
Dbtup::readCharNotNULL(Uint32* outBuffer,
                       AttributeHeader* ahOut,
                       Uint32  attrDescriptor,
                       Uint32  attrDes2)
{
  Uint32 indexBuf = tOutBufIndex;
  Uint32 readOffset = AttributeOffset::getOffset(attrDes2);
  Uint32 attrNoOfWords = AttributeDescriptor::getSizeInWords(attrDescriptor);
  Uint32 newIndexBuf = indexBuf + attrNoOfWords;
  Uint32 maxRead = tMaxRead;

  ndbrequire((readOffset + attrNoOfWords - 1) < tCheckOffset);
  if (newIndexBuf <= maxRead) {
    ljam();
    ahOut->setDataSize(attrNoOfWords);
    if (! tXfrmFlag) {
      MEMCOPY_NO_WORDS(&outBuffer[indexBuf],
                       &tTupleHeader[readOffset],
                       attrNoOfWords);
    } else {
      ljam();
      Tablerec* regTabPtr = tabptr.p;
      Uint32 i = AttributeOffset::getCharsetPos(attrDes2);
      ndbrequire(i < tabptr.p->noOfCharsets);
      // not const in MySQL
      CHARSET_INFO* cs = tabptr.p->charsetArray[i];
      // XXX should strip Uint32 null padding
      const unsigned nBytes = attrNoOfWords << 2;
      unsigned n =
      (*cs->coll->strnxfrm)(cs,
                            (uchar*)&outBuffer[indexBuf],
                            nBytes,
                            (const uchar*)&tTupleHeader[readOffset],
                            nBytes);
      // pad with ascii spaces
      while (n < nBytes)
        ((uchar*)&outBuffer[indexBuf])[n++] = 0x20;
    }
    tOutBufIndex = newIndexBuf;
    return true;
  } else {
    ljam();
    terrorCode = ZTRY_TO_READ_TOO_MUCH_ERROR;
    return false;
  }
}

bool
Dbtup::readCharNULLable(Uint32* outBuffer,
                       AttributeHeader* ahOut,
                       Uint32  attrDescriptor,
                       Uint32  attrDes2)
{
  if (!nullFlagCheck(attrDes2)) {
    ljam();
    return readCharNotNULL(outBuffer,
                           ahOut,
                           attrDescriptor,
                           attrDes2);
  } else {
    ljam();
    ahOut->setNULL();
    return true;
  }
}

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
/* ---------------------------------------------------------------------- */
/*       THIS ROUTINE IS USED TO UPDATE A NUMBER OF ATTRIBUTES. IT IS     */
/*       USED BY THE INSERT ROUTINE, THE UPDATE ROUTINE AND IT CAN BE     */
/*       CALLED SEVERAL TIMES FROM THE INTERPRETER.                       */
// In addition to the parameters used in the call it also relies on the
// following variables set-up properly.
//
// pagep.p        Page record pointer
// fragptr.p      Fragment record pointer
// operPtr.p      Operation record pointer
// tabptr.p       Table record pointer
/* ---------------------------------------------------------------------- */
int Dbtup::updateAttributes(Page* const pagePtr,
                            Uint32 tupHeadOffset,
                            Uint32* inBuffer,
                            Uint32 inBufLen)
{
  Tablerec* const regTabPtr =  tabptr.p;
  Operationrec* const regOperPtr = operPtr.p;
  Uint32 numAttributes = regTabPtr->noOfAttr;
  Uint32 attrDescriptorStart = regTabPtr->tabDescriptor;
  ndbrequire(attrDescriptorStart + (numAttributes << ZAD_LOG_SIZE) <= cnoOfTabDescrRec);

  tCheckOffset = regTabPtr->tupheadsize;
  tTupleHeader = &pagePtr->pageWord[tupHeadOffset];
  Uint32 inBufIndex = 0;
  tInBufIndex = 0;
  tInBufLen = inBufLen;

  ndbrequire(tupHeadOffset + tCheckOffset <= ZWORDS_ON_PAGE);
  while (inBufIndex < inBufLen) {
    AttributeHeader ahIn(inBuffer[inBufIndex]);
    Uint32 attributeId = ahIn.getAttributeId();
    Uint32 attrDescriptorIndex = attrDescriptorStart + (attributeId << ZAD_LOG_SIZE);
    if (attributeId < numAttributes) {
      Uint32 attrDescriptor = tableDescriptor[attrDescriptorIndex].tabDescr;
      Uint32 attributeOffset = tableDescriptor[attrDescriptorIndex + 1].tabDescr;
      if ((AttributeDescriptor::getPrimaryKey(attrDescriptor)) &&
          (regOperPtr->optype != ZINSERT)) {
        if (checkUpdateOfPrimaryKey(&inBuffer[inBufIndex], regTabPtr)) {
          ljam();
          terrorCode = ZTRY_UPDATE_PRIMARY_KEY;
          return -1;
        }//if
      }//if
      UpdateFunction f = regTabPtr->updateFunctionArray[attributeId];
      ljam();
      regOperPtr->changeMask.set(attributeId);
      if ((this->*f)(inBuffer,
                     attrDescriptor,
                     attributeOffset)) {
        inBufIndex = tInBufIndex;
        continue;
      } else {
        ljam();
689
        return -1;
690 691 692 693
      }//if
    } else {
      ljam();
      terrorCode = ZATTRIBUTE_ID_ERROR;
694
      return -1;
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
    }//if
  }//while
  return 0;
}//Dbtup::updateAttributes()

bool
Dbtup::checkUpdateOfPrimaryKey(Uint32* updateBuffer, Tablerec* const regTabPtr)
{
  Uint32 keyReadBuffer[MAX_KEY_SIZE_IN_WORDS];
  Uint32 attributeHeader;
  AttributeHeader* ahOut = (AttributeHeader*)&attributeHeader;
  AttributeHeader ahIn(*updateBuffer);
  Uint32 attributeId = ahIn.getAttributeId();
  Uint32 attrDescriptorIndex = regTabPtr->tabDescriptor + (attributeId << ZAD_LOG_SIZE);
  Uint32 attrDescriptor = tableDescriptor[attrDescriptorIndex].tabDescr;
  Uint32 attributeOffset = tableDescriptor[attrDescriptorIndex + 1].tabDescr;
  ReadFunction f = regTabPtr->readFunctionArray[attributeId];

  AttributeHeader::init(&attributeHeader, attributeId, 0);
  tOutBufIndex = 0;
  tMaxRead = MAX_KEY_SIZE_IN_WORDS;

joreland@mysql.com's avatar
joreland@mysql.com committed
717 718
  bool tmp = tXfrmFlag;
  tXfrmFlag = false;
719
  ndbrequire((this->*f)(&keyReadBuffer[0], ahOut, attrDescriptor, attributeOffset));
joreland@mysql.com's avatar
joreland@mysql.com committed
720
  tXfrmFlag = tmp;
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
  ndbrequire(tOutBufIndex == ahOut->getDataSize());
  if (ahIn.getDataSize() != ahOut->getDataSize()) {
    ljam();
    return true;
  }//if
  if (memcmp(&keyReadBuffer[0], &updateBuffer[1], tOutBufIndex << 2) != 0) {
    ljam();
    return true;
  }//if
  return false;
}//Dbtup::checkUpdateOfPrimaryKey()

#if 0
void Dbtup::checkPages(Fragrecord* const regFragPtr)
{
  Uint32 noPages = getNoOfPages(regFragPtr);
  for (Uint32 i = 0; i < noPages ; i++) {
    PagePtr pagePtr;
    pagePtr.i = getRealpid(regFragPtr, i);
    ptrCheckGuard(pagePtr, cnoOfPage, page);
    ndbrequire(pagePtr.p->pageWord[1] != (RNIL - 1));
  }
}
#endif

bool
Dbtup::updateFixedSizeTHOneWordNotNULL(Uint32* inBuffer,
                                       Uint32  attrDescriptor,
                                       Uint32  attrDes2)
{
  Uint32 indexBuf = tInBufIndex;
  Uint32 inBufLen = tInBufLen;
  Uint32 updateOffset = AttributeOffset::getOffset(attrDes2);
  AttributeHeader ahIn(inBuffer[indexBuf]);
  Uint32 nullIndicator = ahIn.isNULL();
  Uint32 newIndex = indexBuf + 2;
  ndbrequire(updateOffset < tCheckOffset);

  if (newIndex <= inBufLen) {
    Uint32 updateWord = inBuffer[indexBuf + 1];
    if (!nullIndicator) {
      ljam();
      tInBufIndex = newIndex;
      tTupleHeader[updateOffset] = updateWord;
      return true;
    } else {
      ljam();
      terrorCode = ZNOT_NULL_ATTR;
      return false;
    }//if
  } else {
    ljam();
    terrorCode = ZAI_INCONSISTENCY_ERROR;
    return false;
  }//if
  return true;
}//Dbtup::updateFixedSizeTHOneWordNotNULL()

bool
Dbtup::updateFixedSizeTHTwoWordNotNULL(Uint32* inBuffer,
                                       Uint32  attrDescriptor,
                                       Uint32  attrDes2)
{
  Uint32 indexBuf = tInBufIndex;
  Uint32 inBufLen = tInBufLen;
  Uint32 updateOffset = AttributeOffset::getOffset(attrDes2);
  AttributeHeader ahIn(inBuffer[indexBuf]);
  Uint32 nullIndicator = ahIn.isNULL();
  Uint32 newIndex = indexBuf + 3;
  ndbrequire((updateOffset + 1) < tCheckOffset);

  if (newIndex <= inBufLen) {
    Uint32 updateWord1 = inBuffer[indexBuf + 1];
    Uint32 updateWord2 = inBuffer[indexBuf + 2];
    if (!nullIndicator) {
      ljam();
      tInBufIndex = newIndex;
      tTupleHeader[updateOffset] = updateWord1;
      tTupleHeader[updateOffset + 1] = updateWord2;
      return true;
    } else {
      ljam();
      terrorCode = ZNOT_NULL_ATTR;
      return false;
    }//if
  } else {
    ljam();
    terrorCode = ZAI_INCONSISTENCY_ERROR;
    return false;
  }//if
}//Dbtup::updateFixedSizeTHTwoWordNotNULL()

bool
Dbtup::updateFixedSizeTHManyWordNotNULL(Uint32* inBuffer,
                                        Uint32  attrDescriptor,
                                        Uint32  attrDes2)
{
  Uint32 indexBuf = tInBufIndex;
  Uint32 inBufLen = tInBufLen;
  Uint32 updateOffset = AttributeOffset::getOffset(attrDes2);
  AttributeHeader ahIn(inBuffer[indexBuf]);
  Uint32 nullIndicator = ahIn.isNULL();
  Uint32 noOfWords = AttributeDescriptor::getSizeInWords(attrDescriptor);
  Uint32 newIndex = indexBuf + noOfWords + 1;
  ndbrequire((updateOffset + noOfWords - 1) < tCheckOffset);

  if (newIndex <= inBufLen) {
    if (!nullIndicator) {
      ljam();
      tInBufIndex = newIndex;
      MEMCOPY_NO_WORDS(&tTupleHeader[updateOffset],
                       &inBuffer[indexBuf + 1],
                       noOfWords);
      return true;
    } else {
      ljam();
      terrorCode = ZNOT_NULL_ATTR;
      return false;
    }//if
  } else {
    ljam();
    terrorCode = ZAI_INCONSISTENCY_ERROR;
    return false;
  }//if
}//Dbtup::updateFixedSizeTHManyWordNotNULL()

bool
Dbtup::updateFixedSizeTHManyWordNULLable(Uint32* inBuffer,
                                         Uint32  attrDescriptor,
                                         Uint32  attrDes2)
{
  Tablerec* const regTabPtr =  tabptr.p;
  AttributeHeader ahIn(inBuffer[tInBufIndex]);
  Uint32 nullIndicator = ahIn.isNULL();
  Uint32 nullFlagOffset = AttributeOffset::getNullFlagOffset(attrDes2);
  Uint32 nullFlagBitOffset = AttributeOffset::getNullFlagBitOffset(attrDes2);
  Uint32 nullWordOffset = nullFlagOffset + regTabPtr->tupNullIndex;
  ndbrequire((nullFlagOffset < regTabPtr->tupNullWords) &&
             (nullWordOffset < tCheckOffset));
  Uint32 nullBits = tTupleHeader[nullWordOffset];

  if (!nullIndicator) {
    nullBits &= (~(1 << nullFlagBitOffset));
    ljam();
    tTupleHeader[nullWordOffset] = nullBits;
    return updateFixedSizeTHManyWordNotNULL(inBuffer,
                                            attrDescriptor,
                                            attrDes2);
  } else {
    Uint32 newIndex = tInBufIndex + 1;
    if (newIndex <= tInBufLen) {
      nullBits |= (1 << nullFlagBitOffset);
      ljam();
      tTupleHeader[nullWordOffset] = nullBits;
      tInBufIndex = newIndex;
      return true;
    } else {
      ljam();
      terrorCode = ZAI_INCONSISTENCY_ERROR;
      return false;
    }//if
  }//if
}//Dbtup::updateFixedSizeTHManyWordNULLable()

bool
Dbtup::updateVariableSizedAttr(Uint32* inBuffer,
                               Uint32  attrDescriptor,
                               Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateVariableSizedAttr()

bool
Dbtup::updateVarSizeUnlimitedNotNULL(Uint32* inBuffer,
                                     Uint32  attrDescriptor,
                                     Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateVarSizeUnlimitedNotNULL()

bool
Dbtup::updateVarSizeUnlimitedNULLable(Uint32* inBuffer,
                                      Uint32  attrDescriptor,
                                      Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateVarSizeUnlimitedNULLable()

bool
Dbtup::updateBigVarSizeNotNULL(Uint32* inBuffer,
                               Uint32  attrDescriptor,
                               Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateBigVarSizeNotNULL()

bool
Dbtup::updateBigVarSizeNULLable(Uint32* inBuffer,
                                Uint32  attrDescriptor,
                                Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateBigVarSizeNULLable()

bool
Dbtup::updateSmallVarSizeNotNULL(Uint32* inBuffer,
                                 Uint32  attrDescriptor,
                                 Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateSmallVarSizeNotNULL()

bool
Dbtup::updateSmallVarSizeNULLable(Uint32* inBuffer,
                                  Uint32  attrDescriptor,
                                  Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateSmallVarSizeNULLable()

bool
Dbtup::updateDynFixedSize(Uint32* inBuffer,
                          Uint32  attrDescriptor,
                          Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateDynFixedSize()

bool
Dbtup::updateDynVarSizeUnlimited(Uint32* inBuffer,
                                 Uint32  attrDescriptor,
                                 Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateDynVarSizeUnlimited()

bool
Dbtup::updateDynBigVarSize(Uint32* inBuffer,
                           Uint32  attrDescriptor,
                           Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateDynBigVarSize()

bool
Dbtup::updateDynSmallVarSize(Uint32* inBuffer,
                             Uint32  attrDescriptor,
                             Uint32  attrDes2)
{
  ljam();
  terrorCode = ZVAR_SIZED_NOT_SUPPORTED;
  return false;
}//Dbtup::updateDynSmallVarSize()

joreland@mysql.com's avatar
joreland@mysql.com committed
995 996
Uint32 
Dbtup::read_psuedo(Uint32 attrId, Uint32* outBuffer){
997 998
  Uint32 tmp[sizeof(SignalHeader)+25];
  Signal * signal = (Signal*)&tmp;
joreland@mysql.com's avatar
joreland@mysql.com committed
999 1000
  switch(attrId){
  case AttributeHeader::FRAGMENT:
1001
    * outBuffer = operPtr.p->fragId >> 1; // remove "hash" bit
joreland@mysql.com's avatar
joreland@mysql.com committed
1002
    return 1;
1003 1004 1005
  case AttributeHeader::ROW_SIZE:
    * outBuffer = tabptr.p->tupheadsize << 2;
    return 1;
joreland@mysql.com's avatar
joreland@mysql.com committed
1006 1007 1008 1009
  case AttributeHeader::ROW_COUNT:
  case AttributeHeader::COMMIT_COUNT:
    signal->theData[0] = operPtr.p->userpointer;
    signal->theData[1] = attrId;
1010
    
joreland@mysql.com's avatar
joreland@mysql.com committed
1011 1012 1013 1014 1015 1016 1017
    EXECUTE_DIRECT(DBLQH, GSN_READ_PSUEDO_REQ, signal, 2);
    outBuffer[0] = signal->theData[0];
    outBuffer[1] = signal->theData[1];
    return 2;
  default:
    return 0;
  }
1018
}
1019 1020 1021 1022 1023 1024 1025 1026

bool
Dbtup::readBitsNotNULL(Uint32* outBuffer,
		       AttributeHeader* ahOut,
		       Uint32  attrDescriptor,
		       Uint32  attrDes2)
{
  Tablerec* const regTabPtr = tabptr.p;
1027
  Uint32 pos = AttributeOffset::getNullFlagPos(attrDes2);
1028 1029 1030 1031
  Uint32 bitCount = AttributeDescriptor::getArraySize(attrDescriptor);
  Uint32 indexBuf = tOutBufIndex;
  Uint32 newIndexBuf = indexBuf + ((bitCount + 31) >> 5);
  Uint32 maxRead = tMaxRead;
1032
  
1033 1034 1035 1036
  if (newIndexBuf <= maxRead) {
    ljam();
    ahOut->setDataSize((bitCount + 31) >> 5);
    tOutBufIndex = newIndexBuf;
1037 1038 1039 1040 1041 1042 1043
    
    BitmaskImpl::getField(regTabPtr->tupNullWords,
			  tTupleHeader+regTabPtr->tupNullIndex,
			  pos, 
			  bitCount,
			  outBuffer+indexBuf);
    
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
    return true;
  } else {
    ljam();
    terrorCode = ZTRY_TO_READ_TOO_MUCH_ERROR;
    return false;
  }//if
}

bool
Dbtup::readBitsNULLable(Uint32* outBuffer,
			AttributeHeader* ahOut,
			Uint32  attrDescriptor,
			Uint32  attrDes2)
{
  Tablerec* const regTabPtr = tabptr.p;
1059
  Uint32 pos = AttributeOffset::getNullFlagPos(attrDes2);
1060
  Uint32 bitCount = AttributeDescriptor::getArraySize(attrDescriptor);
1061
  
1062
  Uint32 indexBuf = tOutBufIndex;
1063
  Uint32 newIndexBuf = indexBuf + ((bitCount + 31) >> 5);
1064
  Uint32 maxRead = tMaxRead;
1065 1066 1067 1068
  
  if(BitmaskImpl::get(regTabPtr->tupNullWords,
		      tTupleHeader+regTabPtr->tupNullIndex,
		      pos))
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
  {
    ljam();
    ahOut->setNULL();
    return true;
  }


  if (newIndexBuf <= maxRead) {
    ljam();
    ahOut->setDataSize((bitCount + 31) >> 5);
    tOutBufIndex = newIndexBuf;
1080 1081 1082 1083 1084
    BitmaskImpl::getField(regTabPtr->tupNullWords,
			  tTupleHeader+regTabPtr->tupNullIndex,
			  pos+1, 
			  bitCount,
			  outBuffer+indexBuf);
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
    return true;
  } else {
    ljam();
    terrorCode = ZTRY_TO_READ_TOO_MUCH_ERROR;
    return false;
  }//if
}

bool
Dbtup::updateBitsNotNULL(Uint32* inBuffer,
			 Uint32  attrDescriptor,
			 Uint32  attrDes2)
{
  Tablerec* const regTabPtr =  tabptr.p;
  Uint32 indexBuf = tInBufIndex;
  Uint32 inBufLen = tInBufLen;
  AttributeHeader ahIn(inBuffer[indexBuf]);
  Uint32 nullIndicator = ahIn.isNULL();
1103
  Uint32 pos = AttributeOffset::getNullFlagPos(attrDes2);
1104 1105
  Uint32 bitCount = AttributeDescriptor::getArraySize(attrDescriptor);
  Uint32 newIndex = indexBuf + 1 + ((bitCount + 31) >> 5);
1106
  
1107 1108
  if (newIndex <= inBufLen) {
    if (!nullIndicator) {
1109 1110 1111 1112 1113
      BitmaskImpl::setField(regTabPtr->tupNullWords,
			    tTupleHeader+regTabPtr->tupNullIndex,
			    pos,
			    bitCount,
			    inBuffer+indexBuf+1);
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
      tInBufIndex = newIndex;
      return true;
    } else {
      ljam();
      terrorCode = ZNOT_NULL_ATTR;
      return false;
    }//if
  } else {
    ljam();
    terrorCode = ZAI_INCONSISTENCY_ERROR;
    return false;
  }//if
  return true;
}

bool
Dbtup::updateBitsNULLable(Uint32* inBuffer,
			  Uint32  attrDescriptor,
			  Uint32  attrDes2)
{
  Tablerec* const regTabPtr =  tabptr.p;
  AttributeHeader ahIn(inBuffer[tInBufIndex]);
  Uint32 indexBuf = tInBufIndex;
  Uint32 nullIndicator = ahIn.isNULL();
1138 1139 1140
  Uint32 pos = AttributeOffset::getNullFlagPos(attrDes2);
  Uint32 bitCount = AttributeDescriptor::getArraySize(attrDescriptor);
  
1141
  if (!nullIndicator) {
1142 1143 1144 1145 1146 1147 1148 1149
    BitmaskImpl::clear(regTabPtr->tupNullWords,
		       tTupleHeader+regTabPtr->tupNullIndex,
		       pos);
    BitmaskImpl::setField(regTabPtr->tupNullWords,
			  tTupleHeader+regTabPtr->tupNullIndex,
			  pos+1,
			  bitCount,
			  inBuffer+indexBuf+1);
1150
    
1151
    Uint32 newIndex = indexBuf + 1 + ((bitCount + 31) >> 5);
1152
    tInBufLen = newIndex;
1153
    return true;
1154 1155 1156 1157
  } else {
    Uint32 newIndex = tInBufIndex + 1;
    if (newIndex <= tInBufLen) {
      ljam();
1158 1159 1160 1161
      BitmaskImpl::set(regTabPtr->tupNullWords,
		       tTupleHeader+regTabPtr->tupNullIndex,
		       pos);
      
1162 1163 1164 1165 1166 1167 1168 1169 1170
      tInBufIndex = newIndex;
      return true;
    } else {
      ljam();
      terrorCode = ZAI_INCONSISTENCY_ERROR;
      return false;
    }//if
  }//if
}