MCPcopy Index your code
hub / github.com/bytebase/bytebase / defineView

Function defineView

backend/plugin/parser/tidb/completion.go:285–299  ·  view source on GitHub ↗

defineView installs a view in the catalog. Unlike tables, the only structured input is the view's definition SQL, whose exact shape varies (full "CREATE VIEW ..." vs. a bare SELECT). We try the definition as-is, then wrapped in CREATE VIEW, and finally fall back to a trivial view so the view name st

(cat *catalog.Catalog, name, definition string)

Source from the content-addressed store, hash-verified

283// name still surfaces as a candidate (matching mysql, which reads view names
284// straight from metadata) even when the definition cannot be parsed.
285func defineView(cat *catalog.Catalog, name, definition string) {
286 var attempts []string
287 if definition != "" {
288 attempts = append(attempts,
289 definition,
290 fmt.Sprintf("CREATE VIEW %s AS %s", backtickIdentifier(name), definition),
291 )
292 }
293 attempts = append(attempts, fmt.Sprintf("CREATE VIEW %s AS SELECT 1", backtickIdentifier(name)))
294 for _, ddl := range attempts {
295 if execOK(cat, ddl) {
296 return
297 }
298 }
299}
300
301// execOK runs DDL against the catalog and reports whether it actually installed
302// a schema object: every statement parsed without error AND at least one was a

Callers 1

loadDatabaseObjectsFunction · 0.85

Calls 2

backtickIdentifierFunction · 0.85
execOKFunction · 0.85

Tested by

no test coverage detected