public void TestNumber_When_PrecAndScaleHasValues() { _columnTypeConverter.Initialize(GetConversionsXmlForNumberWithScaleAndPrec()); int length = 22; int prec = 19; int scale = 4; var type = _columnTypeConverter.GetDestinationType("number", ref length, ref prec, ref scale); type.Should().Be("dec"); prec.Should().Be(19); scale.Should().Be(4); }
private void GetColumnInfo(IColumnTypeConverter columnTypeConverter, string tableName, List <IColumn> columns) { var columnFactory = DbContext.PowerPlant.CreateColumnFactory(); var selectStmt = CreateSelectStatementForColumns(tableName); var cursor = DbContext.PowerPlant.CreateDataCursor(); try { var reader = cursor.ExecuteReader(selectStmt); while (reader.Read()) { var name = reader.GetString(0); var type = reader.GetString(1); int length = reader.GetInt16(2); int prec = reader.GetInt16(3); var scale = reader.GetInt32(4); var isNullable = reader.GetString(5) == "Y"; var def = reader.IsDBNull(6) ? "" : reader.GetString(6).TrimEnd(); var sourceType = type.AddParameters(); var colType = columnTypeConverter.GetDestinationType(sourceType, ref length, ref prec, ref scale).ColumnTypeName(); columns.Add(columnFactory.CreateInstance(colType, name, length, prec, scale, isNullable, false, def, "")); } } finally { cursor.Close(); } }
private static void ReadColumn(IColumnFactory columnFactory, IColumnTypeConverter columnsTypeConverter, List <IColumn> columns, XmlNode col) { string colName = col.Attributes["Name"].InnerText; string type = col["Type"].InnerText.ToLower(); bool isNullable = Convert.ToBoolean(col["IsNullable"].InnerText); string def = col["Default"].InnerText; Dictionary <string, object> colDetails = ReadColumnDetails(col); var length = colDetails.ContainsKey("Length") ? Convert.ToInt32(colDetails["Length"]) : 0; var prec = colDetails.ContainsKey("Prec") ? Convert.ToInt32(colDetails["Prec"]) : 0; var scale = colDetails.ContainsKey("Scale") ? Convert.ToInt32(colDetails["Scale"]) : 0; var collation = colDetails.ContainsKey("Collation") ? (string)colDetails["Collation"] : ""; bool isIdentity = colDetails.ContainsKey("IsIdentity") && Convert.ToBoolean(col["IsIdentity"]); var destinationType = columnsTypeConverter.GetDestinationType(type, ref length, ref prec, ref scale).ColumnTypeName(length); columns.Add(columnFactory.CreateInstance(destinationType, colName, length, prec, scale, isNullable, isIdentity, def, collation)); }
private ColumnTypeName GetACopyType(string type, ref int len, ref int prec, ref int scale) { return(_columnTypeConverter.GetDestinationType(type.AddParameters(), ref _length, ref _prec, ref _scale).ColumnTypeName()); }
public override ITableDefinition GetTableDefinition(IColumnTypeConverter columnTypeConverter, string tableName) { string selectStmt = ""; selectStmt += "SELECT c.name, " + "\n"; selectStmt += " t.name AS t_name, " + "\n"; selectStmt += " isnull(c.max_length, 0) as length, " + "\n"; selectStmt += " isnull(c.precision, 0) as prec, " + "\n"; selectStmt += " isnull(c.scale, 0) as scale, " + "\n"; selectStmt += " c.is_nullable, " + "\n"; selectStmt += " convert(varchar(256), isnull(c.collation_name, '')) as collation, " + "\n"; selectStmt += " isnull(object_definition(c.default_object_id), '') as def, " + "\n"; selectStmt += " c.is_identity " + "\n"; selectStmt += "FROM sys.columns c " + "\n"; selectStmt += " JOIN sys.types t " + "\n"; selectStmt += " ON c.user_type_id = t.user_type_id " + "\n"; selectStmt += string.Format("WHERE c.object_id = Object_id('{0}') ", tableName) + "\n"; selectStmt += "ORDER BY c.column_id "; IColumnFactory columnFactory = DbContext.PowerPlant.CreateColumnFactory(); List <IColumn> columns = new List <IColumn>(); bool tableHasBlobColumn = false; IDataCursor cursor = null; try { cursor = DbContext.PowerPlant.CreateDataCursor(); IDataReader reader = cursor.ExecuteReader(selectStmt); while (reader.Read()) { string name = reader.GetString(0); string type = reader.GetString(1); int length = reader.GetInt16(2); if (length != -1 && (type == "nvarchar" || type == "nchar")) { length /= 2; } int prec = reader.GetByte(3); int scale = reader.GetByte(4); if (scale != 0 && type == "datetime2") { prec = 0; } bool isNullable = reader.GetBoolean(5); string collation = reader.GetString(6); string def = reader.GetString(7); bool isIdentity = reader.GetBoolean(8); string sourceType = type.AddParameters(); ColumnTypeName colType = columnTypeConverter.GetDestinationType(sourceType, ref length, ref prec, ref scale).ColumnTypeName(length); if (colType == ColumnTypeName.Blob || colType == ColumnTypeName.OldBlob) { tableHasBlobColumn = true; } columns.Add( columnFactory.CreateInstance( colType, name, length, prec, scale, isNullable, isIdentity, def, collation) ); } } catch (Exception ex) { throw new ADatabaseException("ERROR when Get TableDefinition: " + selectStmt, ex); } finally { if (cursor != null) { cursor.Close(); } } ITableDefinition tableDefinition = DbContext.PowerPlant.CreateTableDefinition(tableName, columns, GetSegmentName(tableName)); tableDefinition.HasBlobColumn = tableHasBlobColumn; tableDefinition.Columns.RemoveAll(c => c.Name == "agrtid"); return(tableDefinition); }
private string GetDestinationTypeWhenOracleToACopy(string input, ref int length, ref int prec, ref int scale) { _columnTypeConverter.Initialize(ConversionXmlHelper.Unit4OracleWriterConversionsXml()); return(_columnTypeConverter.GetDestinationType(input, ref length, ref prec, ref scale)); }