The loadTableInfo function supports passing the context. #2297

Merged
lunny merged 1 commits from LinkinStars/xorm:feat_load_table_info_context into master 2023-07-14 07:35:38 +00:00
Contributor

loadTableInfo add context parameter

Main change

+++ func (engine *Engine) loadTableInfo(ctx context.Context, table *schemas.Table) error
--- func (engine *Engine) loadTableInfo(table *schemas.Table) error

Situation

After #2200, I built custom dialect to control the SQL. I find that everything else is fine, except when the SYNC method executes with an exception.
The reason is that the loadTableInfo method calls the GetIndexes and GetColumns methods with the dialect during execution. The context passed to these two methods are all engine.defaultContext not the current session's context. So, I think the loadTableInfo method should add the context parameter to ensure that the correct context is used during execution.

Review Note

  1. dialect's GetColumns and GetIndexes methods are only used here, if the context here is incorrect, then the context parameter is invalid.
  2. loadTableInfo method is only used in SYNC and DBMetas methods, SYNC should pass the session's context, while DBMetas has no problem passing engine.defaultContext.

All in all, I think this change should not affect other function.

## `loadTableInfo` add context parameter ### Main change ```diff +++ func (engine *Engine) loadTableInfo(ctx context.Context, table *schemas.Table) error --- func (engine *Engine) loadTableInfo(table *schemas.Table) error ``` ### Situation After #2200, I built custom dialect to control the SQL. I find that everything else is fine, except when the `SYNC` method executes with an exception. The reason is that the `loadTableInfo` method calls the `GetIndexes` and `GetColumns` methods with the dialect during execution. **The context passed to these two methods are all `engine.defaultContext` not the current session's context.** So, I think the `loadTableInfo` method should add the context parameter to ensure that the correct context is used during execution. ### Review Note 1. dialect's `GetColumns` and `GetIndexes` methods are **only** used here, if the context here is incorrect, then the context parameter is invalid. 2. `loadTableInfo` method is only used in `SYNC` and `DBMetas` methods, `SYNC` should pass the session's context, while `DBMetas` has no problem passing `engine.defaultContext`. All in all, I think this change should not affect other function.
LinkinStars added 1 commit 2023-07-14 03:46:32 +00:00
The loadTableInfo function supports passing the context.
All checks were successful
test mariadb / test mariadb (pull_request) Successful in 4m20s
test cockroach / test cockroach (pull_request) Successful in 6m51s
test mssql / test mssql (pull_request) Successful in 5m10s
test mysql / test mysql (pull_request) Successful in 4m23s
test mysql8 / test mysql8 (pull_request) Successful in 4m39s
test postgres / test postgres (pull_request) Successful in 5m5s
test tidb / test tidb (pull_request) Successful in 5m9s
test sqlite / unit test & test sqlite (pull_request) Successful in 7m50s
0a44021ab8
lunny approved these changes 2023-07-14 07:35:20 +00:00
lunny merged commit 9b71cb49cc into master 2023-07-14 07:35:38 +00:00
lunny added this to the 1.3.3 milestone 2023-07-26 01:29:11 +00:00
Sign in to join this conversation.
No description provided.