common = require('./RuntimeData/ODBC/common') MySQL = {} MySQL.AlteryxToC = { [common.types.Bool] = {c_type = common.CTypes.SQL_C_SSHORT, c_length = 2, create_type = "BOOL"}, [common.types.Byte] = {c_type = common.CTypes.SQL_C_UTINYINT, c_length = 1, create_type = "tinyint unsigned"}, [common.types.Int16] = {c_type = common.CTypes.SQL_C_SSHORT, c_length = common.lengths.Int16, create_type = "smallint"}, [common.types.Int32] = {c_type = common.CTypes.SQL_C_SLONG, c_length = common.lengths.Int32, create_type = "int"}, [common.types.Int64] = {c_type = common.CTypes.SQL_C_SBIGINT, c_length = common.lengths.Int64, create_type = "bigint"}, [common.types.Float] = {c_type = common.CTypes.SQL_C_FLOAT, c_length = common.lengths.Float, create_type = "float"}, [common.types.Double] = {c_type = common.CTypes.SQL_C_DOUBLE, c_length = common.lengths.Double, create_type = "double"}, [common.types.DateTime] = {c_type = common.CTypes.SQL_C_TYPE_TIMESTAMP, c_length = common.lengths.DateTime, create_type = "datetime"}, [common.types.Date] = {c_type = common.CTypes.SQL_C_TYPE_DATE, c_length = common.lengths.Date, create_type = "datetime"}, [common.types.Time] = {c_type = common.CTypes.SQL_C_CHAR, c_length = 9, create_type = "char(8)"}, [common.types.FixedDecimal] = {c_type = common.CTypes.SQL_C_CHAR, c_length = common.lengths.FixedDecimal, create_type = "decimal(size, scale)"}, [common.types.String] = {c_type = common.CTypes.SQL_C_CHAR, c_length = common.lengths.String, create_type = "char(size)"}, [common.types.WString] = {c_type = common.CTypes.SQL_C_WCHAR,c_length = common.lengths.WString, create_type = "nchar(size)"}, [common.types.V_String] = {c_type = common.CTypes.SQL_C_CHAR, c_length = common.lengths.V_String, create_type = "varchar(size)"}, [common.types.V_WString] = {c_type = common.CTypes.SQL_C_WCHAR, c_length = common.lengths.V_WString, create_type = "nvarchar(size)"}, [common.types.Blob] = {c_type = common.CTypes.SQL_C_BINARY, c_length = common.lengths.Blob, create_type = "longblob"}, [common.types.SpatialObj] = {c_type = common.CTypes.SQL_C_BINARY, c_length = common.lengths.Blob, create_type = "longblob"} } MySQL.ODBCToAlteryx = { [common.ODBCTypes.SQL_BIT] = common.types.Bool, [common.ODBCTypes.SQL_TINYINT] = common.types.Int16, [common.ODBCTypes.SQL_SMALLINT] = common.types.Int16, [common.ODBCTypes.SQL_INTEGER] = common.types.Int32, [common.ODBCTypes.SQL_BIGINT] = common.types.Int64, [common.ODBCTypes.SQL_FLOAT] = common.types.Double, [common.ODBCTypes.SQL_REAL] = common.types.Double, [common.ODBCTypes.SQL_DOUBLE] = common.types.Double, [common.ODBCTypes.SQL_DECIMAL] = common.types.FixedDecimal, [common.ODBCTypes.SQL_NUMERIC] = common.types.FixedDecimal, [common.ODBCTypes.SQL_WCHAR] = common.types.WString, [common.ODBCTypes.SQL_WVARCHAR] = common.types.V_WString, [common.ODBCTypes.SQL_WLONGVARCHAR]= common.types.V_WString, [common.ODBCTypes.SQL_CHAR] = common.types.String, [common.ODBCTypes.SQL_VARCHAR] = common.types.V_String, [common.ODBCTypes.SQL_TYPE_DATE] = common.types.Date, [common.ODBCTypes.SQL_TYPE_TIME] = common.types.Time, [common.ODBCTypes.SQL_TYPE_TIMESTAMP] = common.types.DateTime, [common.ODBCTypes.SQL_VARBINARY] = common.types.Blob, [common.ODBCTypes.SQL_LONGVARBINARY] = common.types.Blob, [common.ODBCTypes.SQL_LONGVARCHAR] = common.types.V_String, [common.ODBCTypes.SQL_BINARY] = common.types.V_String } function MySQL:getFieldInfo(odbcFields) odbcVal = odbcFields["odbcType"] alteryxType = MySQL.ODBCToAlteryx[odbcVal] scale = odbcFields["scale"] precision = odbcFields["precision"] if (odbcFields["bUnsigned"]) then if (odbcVal == common.ODBCTypes.SQL_SMALLINT) then alteryxType = common.types.Int32 elseif (odbcVal == common.ODBCTypes.SQL_INTEGER) then alteryxType = common.types.Int64 elseif (odbcVal == common.ODBCTypes.SQL_BIGINT) then alteryxType = common.types.String end elseif (odbcVal == common.ODBCTypes.SQL_FLOAT) or (odbcVal == common.ODBCTypes.SQL_REAL) then if (precision <= 4) then alteryxType = common.types.Float end end if (alteryxType == nil or alteryxType == '') then alteryxType = common.types.V_String end return alteryxType end function MySQL:getCType(altType) alteryxType = altType["altType"] cType = MySQL.AlteryxToC[alteryxType].c_type return cType end function MySQL:getLength(altType) alteryxType = altType["altType"] cLength = MySQL.AlteryxToC[alteryxType].c_length return cLength end function MySQL:getCreateType(colInfo) alteryxType = colInfo["altType"] size = colInfo["size"] version = colInfo["version"] createType = MySQL.AlteryxToC[alteryxType].create_type if (version < 500) and (alteryxType == common.types.Bool) then createType = "bit" end if (size >= 1024) then if (alteryxType == common.types.V_String) then createType = "text" elseif (alteryxType == common.types.V_WString) then createType = "text CHARACTER SET utf8" end end return createType end function MySQL:getSpatialType(SpatialInfo) bIsSpatial = SpatialInfo["IsSpatial"] if (bIsSpatial) then spatialType = "geometry" else spatialType = "longblob" end return spatialType end function MySQL:getWKBFunct(SpatialInfo) wkbFunction = "ST_GeomFromWKB" return wkbFunction end return MySQL