MCPcopy Create free account
hub / github.com/actiontech/dtle / oracleTp2MySQLTp

Function oracleTp2MySQLTp

driver/oracle/extractor/sql_parse.go:249–405  ·  view source on GitHub ↗
(td *oracle_ast.ColumnDef)

Source from the content-addressed store, hash-verified

247}
248
249func oracleTp2MySQLTp(td *oracle_ast.ColumnDef) *ast.ColumnDef {
250 columnName := IdentifierToString(td.ColumnName)
251 column := &ast.ColumnDef{
252 Name: &ast.ColumnName{
253 Name: model.NewCIStr(columnName),
254 },
255 }
256 for i := range td.Constraints {
257 column.Options = append(column.Options, transConstraintOtoM(td.Constraints[i]))
258 }
259
260 tp := &types.FieldType{
261 Flen: types.UnspecifiedLength,
262 Decimal: types.UnspecifiedLength,
263 }
264
265 switch td.Datatype.DataDef() {
266 case oracle_element.DataDefBFile:
267 tp.Tp = mysql.TypeVarchar
268 tp.Flen = 255
269 case oracle_element.DataDefBinaryFloat:
270 tp.Tp = mysql.TypeFloat
271 case oracle_element.DataDefBinaryDouble:
272 tp.Tp = mysql.TypeDouble
273 case oracle_element.DataDefBlob:
274 tp.Tp = mysql.TypeLongBlob
275 tp.Flag = mysql.BinaryFlag
276 tp.Charset = "binary"
277 tp.Collate = "binary"
278 case oracle_element.DataDefChar:
279 if *td.Datatype.(*oracle_element.Char).Size >= 1 && *td.Datatype.(*oracle_element.Char).Size <= 255 {
280 tp.Tp = mysql.TypeString
281 tp.Flen = *td.Datatype.(*oracle_element.Char).Size
282 } else if *td.Datatype.(*oracle_element.Char).Size >= 256 && *td.Datatype.(*oracle_element.Char).Size <= 2000 {
283 tp.Tp = mysql.TypeVarchar
284 tp.Flen = *td.Datatype.(*oracle_element.Char).Size
285 }
286 case oracle_element.DataDefCharacter:
287 if *td.Datatype.(*oracle_element.Char).Size >= 1 && *td.Datatype.(*oracle_element.Char).Size <= 255 {
288 tp.Tp = mysql.TypeString
289 tp.Flen = *td.Datatype.(*oracle_element.Char).Size
290 } else if *td.Datatype.(*oracle_element.Char).Size >= 256 && *td.Datatype.(*oracle_element.Char).Size <= 2000 {
291 tp.Tp = mysql.TypeVarchar
292 tp.Flen = *td.Datatype.(*oracle_element.Char).Size
293 }
294 case oracle_element.DataDefClob:
295 tp.Tp = mysql.TypeLongBlob
296 case oracle_element.DataDefDate:
297 tp.Tp = mysql.TypeDatetime
298 case oracle_element.DataDefDecimal, oracle_element.DataDefDec:
299 tp.Tp = mysql.TypeNewDecimal
300 tp.Flen = td.Datatype.(*oracle_element.Number).Precision.Number
301 tp.Decimal = LimitSize(*td.Datatype.(*oracle_element.Number).Scale)
302 case oracle_element.DataDefDoublePrecision:
303 tp.Tp = mysql.TypeDouble
304 case oracle_element.DataDefFloat:
305 tp.Tp = mysql.TypeDouble
306 case oracle_element.DataDefInteger:

Callers 1

parseDDLSQLMethod · 0.85

Calls 3

IdentifierToStringFunction · 0.85
transConstraintOtoMFunction · 0.85
LimitSizeFunction · 0.85

Tested by

no test coverage detected