apache / apache/incubator-seata

Mysql field name has space cause undo sql syntax error

Open
#3,661 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
26k
Forks
8.8k
Avg merge
1d 8h
Merged PRs (30d)
4

Description

- [x] I have searched the [issues](https://github.com/seata/seata/issues) of this repository and believe that this is not a duplicate.

### Ⅰ. Issue Description
Mysql field name has space cause undo sql syntax error, and rollback will fail.
our Mysql table `sku` has a field named `current_ quantity`.

### Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

```
2021-04-22 17:26:38.561 INFO 41280 --- [h_RMROLE_1_2_16] i.seata.rm.datasource.DataSourceManager : branchRollback failed. branchType:[AT], xid:[192.168.1.35:8091:128548377206075392], branchId:[128548409888092160], resourceId:[jdbc:mysql://*****/***], applicationData:[null]. reason:[Branch session rollback failed and try again later xid = 192.168.1.35:8091:128548377206075392 branchId = 128548409888092160 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'quantity = 7240, update_time = '2021-04-21 15:00:33.0' WHERE sku_id = 1068' at line 1]
2021-04-22 17:26:38.562 INFO 41280 --- [h_RMROLE_1_2_16] io.seata.rm.AbstractRMHandler : Branch Rollbacked result: PhaseTwo_RollbackFailed_Retryable
```

### Ⅲ. Describe what you expected to happen
rollback success

### Ⅳ. How to reproduce it (as minimally and precisely as possible)

1. use any table with field has space in your service
2. make globalTransaction fail and rollback

### Ⅴ. Anything else we need to know?

1. using space in mysql field is not good idea
2. By looking at the source code, ColumnUtils.addEscape only esacpe keyword column name

### Ⅵ. Environment:

- JDK version : 1.8
- OS : macos Big Sur 11.1
- Others: Seata-Server 1.4.1 / Clien seata-spring-boot-starter 1.41

Contributor guide

Open the contributing guide

Research direction

Start at ColumnUtils.addEscape and trace how rollback SQL is generated for the undo log. Reproduce the failure with a MySQL sku table containing the current_ quantity field and a transaction that rolls back; done means the rollback succeeds without a SQL syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mysql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.