本文整理匯總了Golang中github.com/cockroachdb/cockroach/sql/parser.TableName.DatabaseName方法的典型用法代碼示例。如果您正苦於以下問題:Golang TableName.DatabaseName方法的具體用法?Golang TableName.DatabaseName怎麽用?Golang TableName.DatabaseName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/sql/parser.TableName
的用法示例。
在下文中一共展示了TableName.DatabaseName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}