NABoolean SchemaName::matchDefaultPublicSchema() { if (schemaName_.isNull()) return TRUE; NABoolean matched = FALSE; // get default schema NAString defCat; NAString defSch; ActiveSchemaDB()->getDefaults().getCatalogAndSchema(defCat, defSch); ToInternalIdentifier(defCat); ToInternalIdentifier(defSch); // get public schema NAString publicSchema = ActiveSchemaDB()->getDefaults().getValue(PUBLIC_SCHEMA_NAME); ComSchemaName pubSchema(publicSchema); NAString pubCat = pubSchema.getCatalogNamePart().getInternalName(); NAString pubSch = pubSchema.getSchemaNamePart().getInternalName(); // if catalog was not specified NAString catName = (catalogName_.isNull()? defCat:catalogName_); pubCat = (pubCat.isNull()? defCat:pubCat); if (((catName==defCat) && (schemaName_==defSch)) || ((catName==pubCat) && (schemaName_==pubSch))) matched = TRUE; return matched; }
void SchemaDB::initPerStatement(NABoolean lightweight) { if (!lightweight) { //CMPASSERT(domainDList_.entries() == 0); //CMPASSERT(valueDArray_.entries() == 1); //CMPASSERT(tableDB_.entries() == 0); // WE CANNOT DO THIS HERE: // TransMode::IsolationLevel il; // if (getDefaults().getIsolationLevel(il)) // CmpCommon::transMode()->isolationLevel() = il; // BECAUSE THEN WE'D BE RESETTING DURING A TXN UNDER THE AEGIS OF // A "SET TRANSACTION" STMT, WHICH WOULD BE WRONG... // Instead, a] CmpCommon::transMode() init's itself once, // and b] NADefaults::validateAndInsert() updates CmpCommon::transMode glob // when necessary... } // The defaults table contains EXTERNAL names (and has validated them). // The SchemaName object we fill in here has to be INTERNAL format. // First, ensure the NADefaults and the SqlParser_NADefaults globals // have been initialized. // NAString cat, sch; getDefaults().getCatalogAndSchema(cat, sch); // NB: These two ToInternalIdentifier() calls are essential to making // delimited identifiers work properly. Is it not useless emitting their // return codes into cerr? Would it not be better to CMPASSERT them instead? Lng32 err1, err2; err1 = ToInternalIdentifier(cat); err2 = ToInternalIdentifier(sch); if (err1 || err2) cerr << err1 << ' ' << cat << '\t' << err2 << ' ' << sch << endl; defaultSchema_.setCatalogName(cat); defaultSchema_.setSchemaName (sch); }
Int32 ValidateRoleNameList::validate( const char *value, const NADefaults *nad, Int32 attrEnum, Int32 errOrWarn, float *) const { // Validate a list of role names. Based on ValidateAnsiList // List format: comma separated list of role names which use either . or _ // example: "role.user1", "ROLE.user2", "role_user3" // SeaQuest example: DB__Root, DB__Services, db_role12, db_user3 // Validate using a copy of "*value" char tempStr[1000]; // max length of ATTR_VALUE if ( strlen(value) >= 1000 ) return FALSE; // just in case if ( strlen(value) == 0 ) return TRUE; // empty string ATTR_VALUE is OK strcpy(tempStr, value); // prepare to extract the role names/tokens from the default string const char *token, *sep = " ," ; token = strtok( tempStr, sep ); // iterate thru list of role names; return false iff any name is invalid // (Also an appropriate error/warning would be issued.) while ( token != NULL ) { NAString tokenObj(token); Lng32 sqlcode = ToInternalIdentifier(tokenObj, TRUE /*upCase*/, FALSE /*acceptCircumflex*/, 0 /*toInternalIdentifierFlags*/); if (sqlcode && ABS(sqlcode) != 3128) { // 3004 A delimited identifier must contain at least one character. // 3118 Identifier too long. // 3127 Illegal character in identifier $0~string0. // 3128 $1~string1 is a reserved word. if (errOrWarn) *CmpCommon::diags() << DgSqlCode(ERRWARN(2055)) << DgString0(token) << DgString1("INVALID AUTHORIZATION IDENTIFIER"); } token = strtok( NULL, sep ); } return TRUE; }
// return next token ExtQualModuleNames::tokenType ExtQualModuleNames::scanner() { currentToken_ = ""; if (atEnd()) { return SCANEOF; } while (!atEnd()) { const char cc = returnAdvanceChar(); if (isspace((unsigned char)cc)) { // For VS2003... continue; // do nothing } else if (isalpha(cc)) { // regular identifier currentToken_ += cc; while (isalnum(currentChar()) || currentChar() == '_') { currentToken_ += currentChar(); advanceChar(); } // convert id to internal format (ie, uppercase it) NAString id(currentToken_.c_str()); if (ToInternalIdentifier(id) != 0) { *mxCUMptr << FAIL << DgSqlCode(-2215) << DgString0(currentToken_.c_str()); } currentToken_ = id.data(); return checkReserved(); } currentToken_ += cc; switch (cc) { case '{' : case '}' : case ',' : case '.' : case '=' : return tokenType(cc); case '"': // "delimited identifier" specified by \"([^\"]|"\"\"")*\" while (!atEnd()) { const char c1 = returnAdvanceChar(); currentToken_ += c1; if (c1 == '"') { if (currentChar() == '"') { currentToken_ += currentChar(); } else { // end of delimited identifier // convert delimited id to internal format NAString id(currentToken_.c_str()); if (ToInternalIdentifier(id, FALSE, TRUE) != 0) { *mxCUMptr << FAIL << DgSqlCode(-2209) << DgString0(currentToken_.c_str()); } currentToken_ = id.data(); return ID; } } } *mxCUMptr << FAIL << DgSqlCode(-2210); // unterminated string return ID; default: advanceChar(); *mxCUMptr << FAIL << DgSqlCode(-2211) << DgString0(currentToken_.c_str()); return SCANERROR; } } return SCANEOF; }