Jitmisra opened a new pull request, #1059:
URL: https://github.com/apache/incubator-seata-go/pull/1059

   #### What this PR does
   
   Removes all hardcoded `types.DBTypeMySQL` references across the AT executor 
layer, replacing them with `execContext.DBType` to enable multi-database AT 
mode support. Also extends escape handling to support MariaDB (backtick, same 
as MySQL) and Oracle (double-quote standard SQL) escaping.
   
   #### Why
   
   Every AT executor was hardcoded to look up only the MySQL table metadata 
cache:
   
   ```go
   // BEFORE — always MySQL, panic for other DBs
   metaData, err := 
datasource.GetTableCache(types.DBTypeMySQL).GetTableMeta(ctx, ...)
   
   // AFTER — uses the actual database type from execution context
   metaData, err := 
datasource.GetTableCache(u.execContext.DBType).GetTableMeta(ctx, ...)
   ```
   
   #### Changes Summary
   
   **Source files — replace `types.DBTypeMySQL` with `execContext.DBType` (11 
files):**
   
   | File                            | Changes                                  
                                             |
   | ------------------------------- | 
-------------------------------------------------------------------------------------
 |
   | `escape.go`                     | `DelEscape`/`AddEscape`/`checkEscape` → 
handle MariaDB backtick + Oracle double-quote |
   | `at_executor.go`                | Register AT executor for MariaDB + 
Oracle                                             |
   | `insert_executor.go`            | 7 instances (`GetTableCache` + 
`DelEscape` + `getNeedColumns`)                        |
   | `update_executor.go`            | 3 instances (`GetTableCache`)            
                                             |
   | `delete_executor.go`            | 2 instances (`GetTableCache`)            
                                             |
   | `multi_update_excutor.go`       | 2 instances (`GetTableCache`)            
                                             |
   | `multi_delete_executor.go`      | 2 instances (`GetTableCache`)            
                                             |
   | `insert_on_update_executor.go`  | 4 instances + **variable shadowing fix** 
(loop var `i` → `idx`)                       |
   | `select_for_update_executor.go` | 1 instance (`GetTableCache`)             
                                             |
   | `update_executor.go`            | 3 instances (`GetTableCache`)            
                                             |
   | `update_join_executor.go`       | 2 instances (`GetTableCache`)            
                                             |
   
   **Test files — add `DBType: types.DBTypeMySQL` to test `ExecContext` (8 
files):**
   
   | File                                | Changes                              
                                                                                
                                                                                
      |
   | ----------------------------------- | 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 |
   | `escape_multidb_test.go`            | **[NEW]** 7 tests: 
`TestDelEscapeMariaDB`, `TestDelEscapeOracle`, `TestAddEscapeMariaDB`, 
`TestAddEscapeOracle`, `TestCheckEscapeMariaDB`, `TestCheckEscapeOracle`, 
`TestBuildWhereConditionByPKs_MultiDB` |
   | `at_executor_test.go`               | Add `DBType: types.DBTypeMySQL` (5 
locations)                                                                      
                                                                                
        |
   | `insert_executor_test.go`           | Add `DBType: types.DBTypeMySQL` (3 
locations)                                                                      
                                                                                
        |
   | `insert_on_update_executor_test.go` | Add `execContext` with `DBType: 
types.DBTypeMySQL` (1 location)                                                 
                                                                                
           |
   | `update_executor_test.go`           | Add `DBType: types.DBTypeMySQL` (1 
location)                                                                       
                                                                                
        |
   | `multi_update_excutor_test.go`      | Add `DBType: types.DBTypeMySQL` (4 
locations)                                                                      
                                                                                
        |
   | `delete_executor_test.go`           | Add `DBType: types.DBTypeMySQL` (1 
location)                                                                       
                                                                                
        |
   | `update_join_executor_test.go`      | Add `DBType: types.DBTypeMySQL` (1 
location)                                                                       
                                                                                
        |
   
   **Total: 19 files (11 source + 1 new test + 7 modified tests)**
   
   #### Escape handling improvements
   
   - `DelEscape`: MariaDB uses backtick escaping (same as MySQL); Oracle only 
uses double-quote
   - `AddEscape`: MariaDB → backtick; Oracle → double-quote (standard SQL)
   - `checkEscape`: MariaDB shares MySQL keyword list; Oracle escapes all 
identifiers (safe default)
   
   #### Bug fix
   
   - `insert_on_update_executor.go` line 219: Loop variable `i` (int) shadowed 
receiver `i *insertOnUpdateExecutor`. Fixed by renaming loop var to `idx` and 
capturing `dbType` before the loop.
   
   #### Testing
   
   ```
   ✅ gofmt -s       — Clean (all 19 files)
   ✅ go vet          — Clean
   ✅ go build        — Clean
   ✅ All new escape tests (7) — PASS
   ✅ All existing executor tests — PASS
   ✅ License headers  — ASF 2.0 present on new file
   ✅ No cross-imports to PR#2/PR#3 packages
   ```
   
   > **Note:** `TestATExecutor_ExecWithValue_ParserError` is a pre-existing 
flaky test caused by `gomonkey` stub race conditions between test functions. It 
fails on the **original unmodified code** as well (verified by running `git 
stash` + test on original). It passes when run in isolation. Not related to 
this PR.
   
   #### Verification (pre-existing flaky test proof)
   
   ```bash
   # Passes in isolation:
   $ go test -run "TestATExecutor_ExecWithValue_ParserError$" 
./pkg/datasource/sql/exec/at/...
   ok  seata.apache.org/seata-go/v2/pkg/datasource/sql/exec/at  0.423s
   
   # Fails on ORIGINAL unmodified code too:
   $ git stash && go test ./pkg/datasource/sql/exec/at/...
   FAIL  seata.apache.org/seata-go/v2/pkg/datasource/sql/exec/at  0.634s
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to