void Attributes::displayContents(Space * space, Int32 operandNum,
				 char * constsArea, Attributes * spAttr)
{
#ifndef __EID
  char buf[250];
  char r[15];

  if (operandNum == 0)
    str_cpy(r, " (result)",str_len(" (result)")+1,'\0');
  else
    r[0] = 0;
  
  str_sprintf(buf, "    Operand #%d%s:", operandNum, r);
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  str_sprintf(buf, "      Datatype = %s(%d), Length = %d, Null Flag = %d",
	  getDatatypeAsString(getDatatype()), getDatatype(), getLength(), getNullFlag());
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  if ((getDatatype() == REC_BLOB) ||
      (getDatatype() == REC_CLOB))
    {
      Int16 precision = getPrecision();
      UInt16 scale = getScaleAsUI();
      
      Lng32 lobLen = (precision << 16);
      lobLen += scale;
      
      Int64 ll = (Int64)lobLen;
      //      Int64 ll = (Int64)getPrecision() * 1000 + (Int64)getScale();
      str_sprintf(buf, "      LobLength = %Ld Mb", ll);
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }

  str_sprintf(buf, "      Precision = %d, Scale = %d, Collation = %d, flags_ = %b",
              getPrecision(), getScale(), getCollation(), flags_);

  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  str_cpy(buf, "      Tuple Data Format = ", 
          str_len("      Tuple Data Format = ")+1,'\0');

  switch (getTupleFormat())
    {
    case ExpTupleDesc::UNINITIALIZED_FORMAT: 
      str_cat(buf, "UNINITIALIZED_FORMAT", buf);
      break;

    case ExpTupleDesc::PACKED_FORMAT: 
      str_cat(buf, "PACKED_FORMAT", buf);
      break;

    case ExpTupleDesc::SQLMX_KEY_FORMAT: 
      str_cat(buf, "SQLMX_KEY_FORMAT", buf);
      break;

    case ExpTupleDesc::SQLARK_EXPLODED_FORMAT: 
      str_cat(buf, "SQLARK_EXPLODED_FORMAT", buf);
      break;

    case ExpTupleDesc::SQLMX_FORMAT: 
      str_cat(buf, "SQLMX_FORMAT", buf);
      break;

    case ExpTupleDesc::SQLMX_ALIGNED_FORMAT: 
      str_cat(buf, "SQLMX_ALIGNED_FORMAT", buf);
      break;

    default:
      str_cat(buf, "Unrecognized format", buf);
      break;

    } // switch tuple format

  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  if (isSpecialField())
    {
      str_sprintf(buf, "      DefaultFieldNum = %d",getDefaultFieldNum());
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }
    
  char constOrTemp[150];
  if ((getAtp()) == 0 && (getAtpIndex() == 0))
    {
      str_cpy(constOrTemp, " (Constant)",
              str_len(" (Constant)")+1,'\0');
    }
  else if ((getAtp() == 0) && (getAtpIndex() == 1))
    str_cpy(constOrTemp, " (Temporary)",
            str_len(" (Temporary)")+1,'\0');
  else if ((getAtp() == 1) && (getAtpIndex() == 1))
    str_cpy(constOrTemp, " (Persistent)",
            str_len(" (Persistent)")+1,'\0');
  else if (getAtpIndex() == 0)
    str_cpy(constOrTemp, " !!!ERROR!!! - Invalid (Atp,AtpIndex)",
            str_len(" !!!ERROR!!! - Invalid (Atp,AtpIndex)")+1,'\0');
  else
    str_cpy(constOrTemp, " ", str_len(" ")+1,'\0');

  str_sprintf(buf, "      Atp = %d, AtpIndex = %d%s",
	  getAtp(), getAtpIndex(), constOrTemp);
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  str_sprintf(buf, "      Offset = %d, NullIndOffset = %d, VClenIndOffset = %d",
	  (getOffset() == ExpOffsetMax ? -1 : (Lng32)getOffset()),
	  (getNullIndOffset() == ExpOffsetMax ?  -1 : getNullIndOffset()),
	  (getVCLenIndOffset() == ExpOffsetMax ? -1 : getVCLenIndOffset()));
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  if ((getTupleFormat() == ExpTupleDesc::SQLMX_FORMAT) ||
      (getTupleFormat() == ExpTupleDesc::SQLMX_ALIGNED_FORMAT))
    {
      str_sprintf(buf, "      RelOffset = %d, VoaOffset = %d, NullBitIdx = %d",
                  getRelOffset(),
                  (getVoaOffset() == ExpOffsetMax ? -1 : getVoaOffset()),
                  getNullBitIndex());
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }

  str_sprintf(buf, "      NullIndLength = %d, VClenIndLength = %d",
	      getNullIndicatorLength(), getVCIndicatorLength());
  space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));

  if ((getRowsetSize() > 0) ||
      (getRowsetInfo()))
    {
      str_sprintf(buf, "      rowsetSize_ = %d, rowsetInfo_ = %b",
		  getRowsetSize(), getRowsetInfo());
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }
  
  if (spAttr)
    {
      str_sprintf(buf, "      ValueId = %d",
	      ((ShowplanAttributes *)spAttr)->valueId());
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
      str_sprintf(buf, "      Text = %s",
	      (((ShowplanAttributes *)spAttr)->text() ? 
	       ((ShowplanAttributes *)spAttr)->text() : ""));
      space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short));
    }
#endif   // __EID
}
Exemple #2
0
/* This version creates records stored in uniocde internally.   */
void
read_database()
{
	FILE *fp;
    const char procname[]="read_database" ;
	register int i;

	char mbsbuf[BUFSIZ] ;	/* 1024 characters per
							   line on Mac Os X */
	/* Det ser mere ut som om det er en db-entry som er på 1024 tegn!i den må
	   bli litt større 256 tegn per linje er passe stort nok! 64 tegn per felt
	   skulle også holde, også! */
    
    /* If a file didn't exist from the commandline, an index file has been
    created if we come here. there is more, if we then choose not to make
    a single entry before we quit, then the file will be deleted in the
    finish() handler. */
    
    fp = open_db() ;
	/* Allocate some entries in array.  16 is  arbitrary nr.    */
	dbsize = MAXDBLINES;
	dbentries = 0;

	if ((db = (dbrecord *)calloc((size_t) dbsize ,sizeof(dbrecord))) == NULL) {
            yerror(YMALLOC_ERR,procname,"db",YX_EXTERNAL_CAUSE ) ;
    }
	/* Until we hit end of file...                              */
	while (!feof(fp)) {
		/* If we need to, allocate more entries.                */
		if (dbentries >= dbsize) {
			dbsize *= 2;
			db = yrealloc(db, dbsize * sizeof(dbrecord),procname,"db");

		}
		/* Read in one entry at a time.                         */
		for (i = 0; i < idx.idx_nlines; i++) {	/* GLOBAL */
			/* If we hit end of file before getting complete    */
			/* entry, then toss this one.                       */
            /* TODO: BUFSIZ skiftes ut */
			if (fgets(mbsbuf, (int)BUFSIZ, fp) ==
			    NULL)
				goto out;
			register size_t mbuflen = (strlen(mbsbuf) - 1);

			/* Save length of line                              */
			mbsbuf[mbuflen] = '\0';	/* remove newline           */

			/* hva gjør vi med tomme linjer?? */
			if (mbuflen > 0) {
				int32_t reslen = 0;
                /* TODO: we also need to improve errors in uniocFromUTF8_alloc
                   that would be the simplest so we never check for null upon 
                   return from it.(can be too many causes for errors to analyze
                   hindsightly. */
				db[dbentries].db_lines[i] =
				    unicodeFromUTF8_alloc(&reslen, mbsbuf,
							  (size_t) mbuflen);
				if (db[dbentries].db_lines[i] == NULL)
                    yerror(YMALLOC_ERR,procname,"db[dbentries].dblines[i]",YX_EXTERNAL_CAUSE ) ;

				db[dbentries].db_lens[i] = reslen;
			} else {
				db[dbentries].db_lines[i] = NULL;
				db[dbentries].db_lens[i] = 0;
			}

		}
		/* Mark entry as valid, increase number of entries.     */
		db[dbentries].db_flag = DB_VALID;
		dbentries++;
	}
 out:
	fclose(fp);
	UErrorCode status = U_ZERO_ERROR;

	compareCollator = ucol_open(getCollation(), &status);
	if (U_SUCCESS(status)) {
        if (!reverse_data) { 
		qsort(db, (size_t) dbentries, sizeof(dbrecord),
		      (compFunc) dbsort);
        } else {
		    qsort(db, (size_t) dbentries, sizeof(dbrecord),
		      (compFunc) reverse_dbsort);
            
        }
	} else {
        y_icuerror( YICU_CRECOLL_ERR, procname, "compareCollator", status ) ;
	}
	ucol_close(compareCollator);

	return;
}
Exemple #3
0
/* save the database to disk.                                   */
void save_db(void)
{
    const char procname[] = "save_db" ;
	FILE *fp;

	struct stat st;

	register int i, j;

	char *realfile=NULL, *bakfile=NULL;
    /* vi oppretter bakfile første gangen vi kaller rutinen
    hvis bakfile ikke er opprettet? 
    */
	char buf[BUFSIZ];

	/* If it doesn't need saving, never mind.                   */
	if (!dbmodified)
		return;

	/* Create name of file and a backup file.                   */
    realfile = getFullDbName() ; 
    bakfile = getDbBackupFileName()  ;
	/* Default creation mode.                                   */
	/* TODO: into header with this one                         */
	st.st_mode = 0400;
	/* better still use ... UMOD? */

	/* If file already exists, rename it to backup file name.   */
	if (stat(realfile, &st) == 0) {
	    int	ret = rename(realfile, bakfile);
        if (ret) {
           yerror(YFILE_RENMV_ERR,procname,bakfile,YX_EXTERNAL_CAUSE ) ; 
        }
    }
	/* Open new file.                                           */
	if ((fp = fopen(realfile, "w")) == NULL)
        yerror(YFILE_CREAT_ERR,procname,realfile,YX_EXTERNAL_CAUSE ) ; 
	/* Make sure database is sorted.                             */
    if (dbentries > 1 ) {
	    UErrorCode status = U_ZERO_ERROR;

	    compareCollator = ucol_open(getCollation(), &status);
	    if (U_SUCCESS(status)) {
		    qsort(db, (size_t) dbentries, sizeof(dbrecord),
	    	      (compFunc) dbsort);
	    } else {
            y_icuerror( YICU_CRECOLL_ERR, procname, "compareCollator", status ) ;
	    }
	    ucol_close(compareCollator);
    }
	/* START: */
	/* Write out entries.                                       */
	/* BUG: det som skjer er at feltet er tomt, så det får ikke noe nytt
	   innhold! */
	for (i = 0; i < dbentries; i++) {
		if ((db[i].db_flag & DB_VALID) == 0)
			continue;

		for (j = 0; j < idx.idx_nlines; j++) {
			if (db[i].db_lens[j] > 0) {
				/* if (usz > 0 ) { */
				(void)utf8FromUnicode(buf, (int32_t) BUFSIZ,
						      db[i].db_lines[j],
						      u_strlen(db[i].
							       db_lines[j]));
				fprintf(fp, "%s\n", buf);
			} else {
				fprintf(fp, "\n");
			}

		}
	}

	/* Set file mode to mode of orig file. Mark db as unmodified. */
	fchmod(fileno(fp), (mode_t) (st.st_mode & (mode_t) 0777));
	dbmodified = 0;

	fclose(fp);
}
            query: { x: 1 },
            update: { y: 1 }
        })json"));

    auto parseStatus = FindAndModifyRequest::parseFromBSON(NamespaceString("a.b"), cmdObj);
    ASSERT_OK(parseStatus.getStatus());

    auto request = parseStatus.getValue();
    ASSERT_EQUALS(NamespaceString("a.b").toString(), request.getNamespaceString().toString());
    ASSERT_BSONOBJ_EQ(BSON("x" << 1), request.getQuery());
    ASSERT_BSONOBJ_EQ(BSON("y" << 1), request.getUpdateObj());
    ASSERT_EQUALS(false, request.isUpsert());
    ASSERT_EQUALS(false, request.isRemove());
    ASSERT_BSONOBJ_EQ(BSONObj(), request.getFields());
    ASSERT_BSONOBJ_EQ(BSONObj(), request.getSort());
    ASSERT_BSONOBJ_EQ(BSONObj(), request.getCollation());
    ASSERT_EQUALS(0u, request.getArrayFilters().size());
    ASSERT_EQUALS(false, request.shouldReturnNew());
}

TEST(FindAndModifyRequest, ParseWithUpdateFullSpec) {
    BSONObj cmdObj(fromjson(R"json({
            query: { x: 1 },
            update: { y: 1 },
            upsert: true,
            fields: { x: 1, y: 1 },
            sort: { z: -1 },
            collation: {locale: 'en_US' },
            arrayFilters: [ { i: 0 } ],
            new: true
        })json"));