GetSqlDatabaseFromContext returns the database from the context. Uses the context's current database if an empty string is provided. Returns nil if the database was not found.
(ctx *sql.Context, database string)
| 23 | // GetSqlDatabaseFromContext returns the database from the context. Uses the context's current database if an empty |
| 24 | // string is provided. Returns nil if the database was not found. |
| 25 | func GetSqlDatabaseFromContext(ctx *sql.Context, database string) (sql.Database, error) { |
| 26 | session := ctx.Session.(*backend.Session) |
| 27 | if len(database) == 0 { |
| 28 | database = ctx.GetCurrentDatabase() |
| 29 | } |
| 30 | ctx.GetLogger().Tracef("Getting database from context: %v", database) |
| 31 | db, err := session.Provider().Database(ctx, database) |
| 32 | if err != nil { |
| 33 | if sql.ErrDatabaseNotFound.Is(err) { |
| 34 | return nil, nil |
| 35 | } |
| 36 | return nil, err |
| 37 | } |
| 38 | return db, nil |
| 39 | } |
| 40 | |
| 41 | // GetSqlTableFromContext returns the table from the context. Uses the context's current database if an empty database |
| 42 | // name is provided. Returns nil if no table was found. |
no test coverage detected