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)
| 192 | // GetSqlDatabaseFromContext returns the database from the context. Uses the context's current database if an empty |
| 193 | // string is provided. Returns nil if the database was not found. |
| 194 | func GetSqlDatabaseFromContext(ctx *sql.Context, database string) (sql.Database, error) { |
| 195 | session := dsess.DSessFromSess(ctx.Session) |
| 196 | if len(database) == 0 { |
| 197 | database = ctx.GetCurrentDatabase() |
| 198 | } |
| 199 | db, err := session.Provider().Database(ctx, database) |
| 200 | if err != nil { |
| 201 | if sql.ErrDatabaseNotFound.Is(err) { |
| 202 | return nil, nil |
| 203 | } |
| 204 | return nil, err |
| 205 | } |
| 206 | return db, nil |
| 207 | } |
| 208 | |
| 209 | // GetSqlTableFromContext returns the table from the context. Uses the context's current database if an empty database |
| 210 | // name is provided. Returns nil if no table was found. |