| 916 | return dataEvent, fmt.Errorf("parese dateEvent fail , operation Code %v", row.Operation) |
| 917 | } |
| 918 | func (e *ExtractorOracle) parseDMLSQL(oracleRedoSQL, oracleUndoSQL string) (dataEvent common.DataEvent, err error) { |
| 919 | // Convert oracle SQL to MySQL format that can be parsed by tidb parese |
| 920 | OracleToMySQLFormat := func(oracleSQL string) string { |
| 921 | if strings.HasPrefix(oracleSQL, "insert into") { |
| 922 | insertSqlSlice := strings.Split(oracleSQL, ") values (") |
| 923 | if len(insertSqlSlice) == 2 { |
| 924 | oracleSQL = strings.Replace(oracleSQL, insertSqlSlice[0], ReplaceSpecifiedString(insertSqlSlice[0], `"`, "`"), 1) |
| 925 | oracleSQL = strings.Replace(oracleSQL, insertSqlSlice[1], strings.ReplaceAll(insertSqlSlice[1], `\`, `\\`), 1) |
| 926 | } else { |
| 927 | e.logger.Warn("schema/table/column names contain unexpected characters ) values (") |
| 928 | } |
| 929 | |
| 930 | } else if strings.HasPrefix(oracleSQL, "delete") { |
| 931 | delSqlSlice := strings.Split(oracleSQL, " where ") |
| 932 | if len(delSqlSlice) == 2 { |
| 933 | oracleSQL = strings.Replace(oracleSQL, delSqlSlice[0], ReplaceSpecifiedString(delSqlSlice[0], `"`, "`"), 1) |
| 934 | whereExper := delSqlSlice[1] |
| 935 | whereExperSli := strings.Split(whereExper, " and ") |
| 936 | for i := range whereExperSli { |
| 937 | colAndVal := strings.Split(whereExperSli[i], " = ") |
| 938 | if len(colAndVal) == 2 { |
| 939 | whereExperSli[i] = fmt.Sprintf("%s = %s", ReplaceSpecifiedString(colAndVal[0], `"`, "`"), |
| 940 | ReplaceSpecifiedString(colAndVal[1], `\`, `\\`)) |
| 941 | } |
| 942 | } |
| 943 | whereExper = strings.Join(whereExperSli, " and ") |
| 944 | oracleSQL = strings.Replace(oracleSQL, delSqlSlice[1], whereExper, 1) |
| 945 | } |
| 946 | } else if strings.HasPrefix(oracleSQL, "update") { |
| 947 | // update "TEST"."BINARY_FLOAT6" set "COL2" ='500' where "COL1" = '3' and "COL2" = 'NULL'; |
| 948 | updateSqlSlice := strings.Split(oracleSQL, " where ") |
| 949 | if len(updateSqlSlice) == 2 { |
| 950 | // "COL1" = '3' and "COL2" = 'NULL'; |
| 951 | whereExper := updateSqlSlice[1] |
| 952 | whereExperSli := strings.Split(whereExper, " and ") |
| 953 | for i := range whereExperSli { |
| 954 | colAndVal := strings.Split(whereExperSli[i], " = ") |
| 955 | if len(colAndVal) == 2 { |
| 956 | whereExperSli[i] = fmt.Sprintf("%s = %s", ReplaceSpecifiedString(colAndVal[0], `"`, "`"), |
| 957 | ReplaceSpecifiedString(colAndVal[1], `\`, `\\`)) |
| 958 | } |
| 959 | } |
| 960 | whereExper = strings.Join(whereExperSli, " and ") |
| 961 | updateSqlSlice[1] = whereExper |
| 962 | |
| 963 | // update "TEST"."BINARY_FLOAT6" set "COL2" ='500' and "COL1" = 'ss' |
| 964 | headerExper := updateSqlSlice[0] |
| 965 | headExperSli := strings.Split(headerExper, " set ") |
| 966 | if len(headExperSli) == 2 { |
| 967 | // update "TEST"."BINARY_FLOAT6" |
| 968 | headExperSli[0] = ReplaceSpecifiedString(headExperSli[0], `"`, "`") |
| 969 | // "COL2" ='500' and "COL1" = 'ss' |
| 970 | setExperSli := strings.Split(headExperSli[1], " and ") |
| 971 | for i := range setExperSli { |
| 972 | colAndVal := strings.Split(setExperSli[i], " = ") |
| 973 | setExperSli[i] = fmt.Sprintf("%s = %s", ReplaceSpecifiedString(colAndVal[0], `"`, "`"), |
| 974 | ReplaceSpecifiedString(colAndVal[1], `\`, `\\`)) |
| 975 | } |