// checkDatabaseName checks whether the given TableName is unambiguous // within this source and if it is, qualifies the missing database name. func (src *dataSourceInfo) checkDatabaseName(tn parser.TableName) (parser.TableName, error) { found := false if tn.DatabaseName == "" { // No database name yet. Try to find one. for name := range src.sourceAliases { if name.TableName == tn.TableName { if found { return parser.TableName{}, fmt.Errorf("ambiguous source name: %q", tn.TableName) } tn.DatabaseName = name.DatabaseName found = true } } if !found { return parser.TableName{}, fmt.Errorf("source name %q not found in FROM clause", tn.TableName) } return tn, nil } // Database given. Check that the name is unambiguous. if _, ok := src.sourceAliases[tn]; ok { if found { return parser.TableName{}, fmt.Errorf("ambiguous source name: %q (within database %q)", tn.TableName, tn.DatabaseName) } found = true } if !found { return parser.TableName{}, fmt.Errorf("table %q not selected in FROM clause", &tn) } return tn, nil }
// checkDatabaseName checks whether the given TableName is unambiguous // within this source and if it is, qualifies the missing database name. func (src *dataSourceInfo) checkDatabaseName(tn parser.TableName) (parser.TableName, error) { if tn.DatabaseName == "" { // No database name yet. Try to find one. found := false for _, alias := range src.sourceAliases { if alias.name.TableName == tn.TableName { if found { return parser.TableName{}, fmt.Errorf("ambiguous source name: %q", tn.TableName) } found = true tn.DatabaseName = alias.name.DatabaseName } } if !found { return parser.TableName{}, fmt.Errorf("source name %q not found in FROM clause", tn.TableName) } return tn, nil } // Database given. if _, found := src.sourceAliases.srcIdx(tn); !found { return parser.TableName{}, fmt.Errorf("table %q not selected in FROM clause", &tn) } return tn, nil }