// VerifyLegalHandle returns an error if handle is
// not an acceptable source handle value.
// Valid input must match:
//
// \A[@][a-zA-Z][a-zA-Z0-9_]*$
funcVerifyLegalHandle(handlestring)error{
matches:=handlePattern.MatchString(handle)
if!matches{
returnerrz.Errorf(`invalid data source handle %q: must begin with @, followed by a letter, followed by zero or more letters, digits, or underscores, e.g. "@my_db1"`,handle)
}
returnnil
}
// verifyLegalTableName returns an error if table is not an
// acceptable table name. Valid input must match:
//
// \A[a-zA-Z_][a-zA-Z0-9_]*$`
//
funcverifyLegalTableName(tablestring)error{
matches:=tablePattern.MatchString(table)
if!matches{
returnerrz.Errorf(`invalid table name %q: must begin a letter or underscore, followed by zero or more letters, digits, or underscores, e.g. "tbl1" or "_tbl2"`,table)
}
returnnil
}
// handleTypeAliases is a map of type names to the
// more user-friendly suffix returned by SuggestHandle.
varhandleTypeAliases=map[string]string{
typeSL3.String():"sqlite",
typePg.String():"pg",
typeMS.String():"mssql",
typeMy.String():"my",
}
// SuggestHandle suggests a handle based on location and type.
// If typ is TypeNone, the type will be inferred from loc.
// The takenFn is used to determine if a suggested handle
// is free to be used (e.g. "@sakila_csv" -> "@sakila_csv_1", etc).
//
// If the base name (derived from loc) contains illegal handle runes,
// those are replaced with underscore. If the handle would start with
// a number or underscore, it will be prefixed with "h" (for "handle").