本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.TableName.DatabaseName方法的典型用法代码示例。如果您正苦于以下问题:Golang TableName.DatabaseName方法的具体用法?Golang TableName.DatabaseName怎么用?Golang TableName.DatabaseName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/sql/parser.TableName
的用法示例。
在下文中一共展示了TableName.DatabaseName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkDatabaseName
// 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
}
示例2: checkDatabaseName
// 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
}