コード例 #1
0
const NAString QualifiedName::getQualifiedNameAsAnsiNTFilenameString() const
{
  // Preallocate a result buffer that'll be big enough most of the time
  // (so += won't reallocate+copy most of the time).
  NAString result((NASize_T)40, CmpCommon::statementHeap());

  NAString catName(CmpCommon::statementHeap());
  NAString schName(CmpCommon::statementHeap());
  NAString objName(CmpCommon::statementHeap());

  formatAsAnsiIdentifier = TRUE;	// put quotes on delimited identifiers

  if ( NOT getCatalogName().isNull() ) {
    catName = FORMAT(getCatalogName());
    makeSafeFilenamePart(catName, "SQLMX_DEFAULT_CATALOG_");
  }
  if ( NOT getSchemaName().isNull() ) {
    schName = FORMAT(getSchemaName());
    makeSafeFilenamePart(schName, "SQLMX_DEFAULT_SCHEMA_");
  }
  if ( NOT getObjectName().isNull() ) {
    objName = FORMAT(getObjectName());
  }
  makeSafeFilenamePart(objName, "SQLMX_DEFAULT_FILE_");

  formatAsAnsiIdentifier = FALSE;	// reset to initial value

  size_t totlen = catName.length() + schName.length() + objName.length() + 2;

  if ( totlen > 255 ) {					// need to truncate
    // +1 so round off doesn't give us less than what we need to chop
    size_t chopLen = totlen - 255 + 1;  
             
    if ( catName.length() - chopLen/2 <= 0 )		// cat too short
      schName.remove( schName.length() - chopLen );
    else if ( schName.length() - chopLen/2 <= 0 )	// sch too short
      catName.remove( catName.length() - chopLen );
    else {						// chop from both
      // remember position starts at 0 and length is 1 more
      chopLen /= 2;
      catName.remove( catName.length() - chopLen - 1 );
      schName.remove( schName.length() - chopLen - 1 );
    }
  }

  if (NOT catName.isNull()) {
    result = catName;
    result += ".";
  }
  if (NOT schName.isNull()) {
    result += schName;
    result += ".";
  }
  result += objName;

  return result;
}
コード例 #2
0
// This function copies the above applyDefaults() function
// and includes checking for the object existence and 
// search in the public schema if necessary.
// This is used to replace the above function when 
// we need to consider PUBLIC_SCHEMA_NAME
Int32 QualifiedName::applyDefaultsValidate(const SchemaName& defCatSch,
                                         ComAnsiNameSpace nameSpace)
{
  // need to try public schema if it is specified
  // and the object schema is not specified
  NAString publicSchema = "";
  CmpCommon::getDefault(PUBLIC_SCHEMA_NAME, publicSchema, FALSE);
  ComSchemaName pubSchema(publicSchema);
  NAString pubSchemaIntName = "";
  if ( getSchemaName().isNull() && 
       !pubSchema.isEmpty() )
  {
    pubSchemaIntName = pubSchema.getSchemaNamePart().getInternalName();
  }

  Int32 ret = extractAndDefaultNameParts( defCatSch 
				                              , catalogName_
                                      , schemaName_
                                      , objectName_
                                   );

  // try public schema if the table does not exist 
  if (!pubSchemaIntName.isNull())
  {
    *(CmpCommon::diags()) << DgSqlCode(-4222)
                          << DgString0("Public Access Schema");
  }

  return ret;
}
コード例 #3
0
const NAString SchemaName::getSchemaNameAsAnsiString() const
{
  QualifiedName q("X", getSchemaName(), getCatalogName());
  NAString result(q.getQualifiedNameAsAnsiString(), CmpCommon::statementHeap());
  CMPASSERT(result[result.length()-1] == 'X');
  result.remove(result.length()-2);		// remove the '.X'
  return result;
}
コード例 #4
0
NAString QualifiedName::getQualifiedNameAsString(NABoolean formatForDisplay,
						 NABoolean externalDisplay) const
{
  // Preallocate a result buffer that'll be big enough most of the time
  // (so += won't reallocate+copy most of the time).
  NAString result((NASize_T)40, CmpCommon::statementHeap());

  // The object name can be empty if it's an ambiguous column reference
  // (in a join), e.g.  In that case, do NOT prepend "cat.sch." to colrefname
  // which would yield the incorrect string "cat.sch..col".
  //
  if (NOT getObjectName().isNull()) 
  {
    // If volatile, only output the object part of the external name.
    // cat/sch names are internal.
    if ((formatForDisplay) &&
	(isVolatile()))
      {
	result += FORMAT(getObjectName());
      }
    else
      {
	if (NOT getCatalogName().isNull() && NOT externalDisplay) 
	  {
	    if ((SqlParser_NADefaults_Glob != NULL) AND
		(SqlParser_NADefaults_Glob->NAMETYPE_ == DF_SHORTANSI) AND
		(*getCatalogName().data() == '\\'))
	      {
		formatAsAnsiIdentifier = FALSE;
	      }
	    result = FORMAT(getCatalogName());
	    result += ".";
	    CMPASSERT(NOT getSchemaName().isNull());
	  }
	
	if (NOT getSchemaName().isNull())
	  {
	    result += FORMAT(getSchemaName());
	    result += ".";
	  }
	result += FORMAT(getObjectName());
      }
  }
  
  return result;
}
コード例 #5
0
void SchemaName::print(FILE* ofd, const char* indent, const char* title) const
{
#ifndef NDEBUG
  fprintf(ofd,"c=%s s=%s%s",
	  getCatalogName().data(),
	  getSchemaName().data(),
	  indent);	// just to prevent warnings
  if (strcmp(title,"")) fprintf(ofd,"\n");
#endif
}
コード例 #6
0
// Constructor that parses a 1-, 2-, or 3-part external (Ansi) name string
// and optionally applies default catalog and schema to it.
// Use this on a string gotten from a trusted source (Sql Catalog), because
// if it doesn't parse, the ctor cannot return an error so it CMPASSERTs.
//
// This code cloned for CorrName::applyPrototype below.
//
QualifiedName::QualifiedName(const NAString &ansiString, 
                             Int32 minNameParts,
                             CollHeap * h, 
                             BindWA *bindWA) :
     SchemaName(h),
     objectName_(h),
     objectNameSpace_(COM_UNKNOWN_NAME),
     flagbits_(0)
{
  if (HasMPLocPrefix(ansiString.data())) {
    ComMPLoc loc(ansiString);
    catalogName_ = loc.getSysDotVol();
    schemaName_ = loc.getSubvolName();
    objectName_ = loc.getFileName();
  }
  else
  {
    CmpContext *cmpContext = bindWA ? bindWA->currentCmpContext() : NULL;
    Parser parser(cmpContext);
    NAString ns("TABLE " + ansiString + ";", CmpCommon::statementHeap());
#pragma nowarn(1506)   // warning elimination 
    // save the current parserflags setting
    ULng32 savedParserFlags = Get_SqlParser_Flags (0xFFFFFFFF);
    StmtQuery *stmt = (StmtQuery *)parser.parseDML(ns, ns.length(), GetAnsiNameCharSet());
    // Restore parser flags settings 
    Set_SqlParser_Flags (savedParserFlags);
#pragma warn(1506)  // warning elimination 
    if (stmt) {
      CMPASSERT(stmt->getOperatorType() == STM_QUERY);
      *this = stmt->getQueryExpression()->getScanNode()->getTableName().getQualifiedNameObj();
      delete stmt;
    } else {
      // It is possible for the parser to get errors when parsing SQL/MP
      // stored text.  The caller is expected to check the contents of
      // this QualifiedName.
      //
      return;
    }
  }

  Int32 nameParts = 0;
  if (minNameParts > 0) {
    nameParts = getCatalogName() != "" ? 3 :
		getSchemaName()  != "" ? 2 :
		getObjectName()  != "" ? 1 : 0;
    CMPASSERT(nameParts >= minNameParts);
  }

  if (bindWA && nameParts < 3)
    applyDefaults(bindWA->getDefaultSchema());
} // end of QualifiedName::QualifiedName 
コード例 #7
0
const NAString
StmtDDLDropSchema::displayLabel1() const
{
  return NAString("Schema name: ") + getSchemaName();
}
コード例 #8
0
NABoolean QualifiedName::isSeabasePrivMgrMD() const
{
  return CmpSeabaseDDL::isSeabasePrivMgrMD
    (getCatalogName(), getSchemaName());
}
コード例 #9
0
// Name parts return in string parameters, defaulted if not yet present;
// this object is not modified.
// Function return value is the number of names that match the default,
// {0, 1, 2} = {no matches, catalog matches, catalog&schema match}.
//
// If NAMETYPE is NSK, the SchemaDB puts the current MPLOC into the defCatSch;
// so this method has to handle **only one** tiny NSK naming detail.
//
Int32 QualifiedName::extractAndDefaultNameParts(const SchemaName& defCatSch
					     , NAString& catName 	// OUT
					     , NAString& schName	// OUT
					     , NAString& objName	// OUT
                                             ) const
{
  catName = getCatalogName();
  schName = getSchemaName();
  objName = getObjectName();
  CMPASSERT(NOT objName.isNull());		// no default for this!

  {
    if (catName.isNull()) {
      if((ActiveSchemaDB()->getDefaults().schSetToUserID()) &&
         (SqlParser_NAMETYPE == DF_SHORTANSI))
      {
        // If NAMETYPE is SHORTANSI and  schema is not set 
        // in DEFAULTS table or by user, for dml, catName  
        // gets \SYS.$VOL from set or default MPLOC. 
        catName =  SqlParser_MPLOC.getSysDotVol();
      }
      else
      {
      // If NAMETYPE NSK, catName will become  \SYS.$VOL
        catName = defCatSch.getCatalogName();
      }
    }
    else if (SqlParser_NAMETYPE == DF_NSK &&
	     *catName.data() == '$' &&
	     SqlParser_MPLOC.hasSystemName()) {
      // If user specified only a $VOL, fill in the current default \SYS.
      catName.prepend(SqlParser_MPLOC.getSystemName() + ".");
    }

    if (schName.isNull()) {
      if((ActiveSchemaDB()->getDefaults().schSetToUserID()) &&
         (SqlParser_NAMETYPE == DF_SHORTANSI))
      {
        // If NAMETYPE is SHORTANSI and  schema is not set 
        // in DEFAULTS table or by user, for dml, schName  
        // gets subvol from set or default MPLOC. 
        schName =  SqlParser_MPLOC.getSubvolName();
      }
      else
        schName = defCatSch.getSchemaName();
    }
  }

  CMPASSERT(NOT catName.isNull());
  CMPASSERT(NOT schName.isNull());

  Int32 defaultMatches = 0;
  if (catName == defCatSch.getCatalogName()) {
    defaultMatches++;
    if (schName == defCatSch.getSchemaName())
      defaultMatches++;
  }

  // Next comes support for table name resolution for SHORTANSI nametype, 
  // implemented as internal feature for ODBC use only. 
  //
  // For the name resolution of table name when nametype is SHORTANSI, 
  // check is made to see if schName contains an '_', thus ensuring
  // the method applyShortAnsiDefault is called only once.
  // Correct syntax for schName is "systemName_volumeName_subvolName"
  // of the MPLoc where the objName is actually located.
  // Complete syntax checking is done inside applyShortAnsiDefault.
  //
  if (SqlParser_NAMETYPE == DF_SHORTANSI && schName.first('_') != NA_NPOS) {
    applyShortAnsiDefault(catName, schName);
  }

  return defaultMatches;
}
コード例 #10
0
ファイル: Function.c プロジェクト: SuperDzej/pljava
static void Function_init(Function self, ParseResult info, Form_pg_proc procStruct, PG_FUNCTION_ARGS)
{
	StringInfoData sign;
	jobject loader;
	jstring className;

	/* Get the ClassLoader for the schema that this function belongs to
	 */
	jstring schemaName = getSchemaName(procStruct->pronamespace);

	/* Install the type map for the current schema. This must be done ASAP since
	 * many other functions (including obtaining the loader) depends on it.
	 */
	jobject tmp = JNI_callStaticObjectMethod(s_Loader_class, s_Loader_getTypeMap, schemaName);
	self->func.nonudt.typeMap = JNI_newGlobalRef(tmp);
	JNI_deleteLocalRef(tmp);

	self->readOnly = (procStruct->provolatile != PROVOLATILE_VOLATILE);
	self->isUDT = info->isUDT;

	currentInvocation->function = self;

	/* Get the ClassLoader for the schema that this function belongs to
	 */
	loader = JNI_callStaticObjectMethod(s_Loader_class, s_Loader_getSchemaLoader, schemaName);
	JNI_deleteLocalRef(schemaName);

	elog(DEBUG1, "Loading class %s", info->className);
	className = String_createJavaStringFromNTS(info->className);

	tmp = JNI_callObjectMethod(loader, s_ClassLoader_loadClass, className);
	JNI_deleteLocalRef(loader);
	JNI_deleteLocalRef(className);

	self->clazz = (jclass)JNI_newGlobalRef(tmp);
	JNI_deleteLocalRef(tmp);

	if(self->isUDT)
	{
		setupUDT(self, info, procStruct);
		return;
	}

	if(CALLED_AS_TRIGGER(fcinfo))
	{
		self->func.nonudt.typeMap = 0;
		setupTriggerParams(self, info);
	}
	else
	{
		setupFunctionParams(self, info, procStruct, fcinfo);
	}


	initStringInfo(&sign);
	buildSignature(self, &sign, self->func.nonudt.returnType, false);

	elog(DEBUG1, "Obtaining method %s.%s %s", info->className, info->methodName, sign.data);
	self->func.nonudt.method = JNI_getStaticMethodIDOrNull(self->clazz, info->methodName, sign.data);

	if(self->func.nonudt.method == 0)
	{
		char* origSign = sign.data;
		Type altType = 0;
		Type realRetType = self->func.nonudt.returnType;

		elog(DEBUG1, "Method %s.%s %s not found", info->className, info->methodName, origSign);

		if(Type_isPrimitive(self->func.nonudt.returnType))
		{
			/*
			 * One valid reason for not finding the method is when
			 * the return type used in the signature is a primitive and
			 * the true return type of the method is the object class that
			 * corresponds to that primitive.
			 */
			altType = Type_getObjectType(self->func.nonudt.returnType);
			realRetType = altType;
		}
		else if(strcmp(Type_getJavaTypeName(self->func.nonudt.returnType), "java.sql.ResultSet") == 0)
		{
			/*
			 * Another reason might be that we expected a ResultSetProvider
			 * but the implementation returns a ResultSetHandle that needs to be
			 * wrapped. The wrapping is internal so we retain the original
			 * return type anyway.
			 */
			altType = realRetType;
		}

		if(altType != 0)
		{
			JNI_exceptionClear();
			initStringInfo(&sign);
			buildSignature(self, &sign, altType, true);

			elog(DEBUG1, "Obtaining method %s.%s %s", info->className, info->methodName, sign.data);
			self->func.nonudt.method = JNI_getStaticMethodIDOrNull(self->clazz, info->methodName, sign.data);
	
			if(self->func.nonudt.method != 0)
				self->func.nonudt.returnType = realRetType;
		}
		if(self->func.nonudt.method == 0)
			PgObject_throwMemberError(self->clazz, info->methodName, origSign, true, true);

		if(sign.data != origSign)
			pfree(origSign);
	}
	pfree(sign.data);
}
コード例 #11
0
const NAString
StmtDDLSchGrant::displayLabel1() const
{
    return NAString("Schema Name ") + getSchemaName();
}