• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DataSchema.DatabaseColumn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DatabaseSchemaReader.DataSchema.DatabaseColumn的典型用法代码示例。如果您正苦于以下问题:C# DatabaseColumn类的具体用法?C# DatabaseColumn怎么用?C# DatabaseColumn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DatabaseColumn类属于DatabaseSchemaReader.DataSchema命名空间,在下文中一共展示了DatabaseColumn类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: WriteDataType

        public override string WriteDataType(DatabaseColumn column)
        {
            var type = new DataTypeWriter().WriteDataType(column);
            if (column.IsPrimaryKey && (Table.PrimaryKey == null || Table.PrimaryKey.Columns.Count == 1))
            {
                type += " PRIMARY KEY";
                if (column.IsAutoNumber) //must be integer primary key
                {
                    return "INTEGER PRIMARY KEY AUTOINCREMENT";
                }
            }
            if (!column.Nullable) type += " NOT NULL";
            //if there's a default value, and it's not a guid generator or autonumber
            if (!string.IsNullOrEmpty(column.DefaultValue) &&
                !SqlTranslator.IsGuidGenerator(column.DefaultValue) &&
                !column.IsAutoNumber)
            {
                var value = SqlTranslator.Fix(column.DefaultValue);
                //SqlServer (N'string') format
                if (value.StartsWith("(N'", StringComparison.OrdinalIgnoreCase))
                    value = value.Replace("(N'", "('");
                type += " DEFAULT " + value;
            }

            return type;
        }
开发者ID:roadrunner75,项目名称:dbschemareader,代码行数:26,代码来源:TableGenerator.cs


示例2: AddDataType

 /// <summary>
 /// Adds a dataType object to a column.
 /// </summary>
 /// <param name="column">The column.</param>
 public static void AddDataType(DatabaseColumn column)
 {
     if (column == null) return;
     //there is no data type at all
     if (string.IsNullOrEmpty(column.DbDataType)) return;
     //a datatype already assigned
     if (column.DataType != null) return;
     //use upper case
     var dbType = column.DbDataType.ToUpperInvariant();
     //nothing to convert
     if (string.IsNullOrEmpty(dbType)) return;
     var sqlType = SqlType.SqlServer;
     var dataTypeList = new List<DataType>();
     if (column.Table != null)
     {
         //look up the full schema if it exists
         var schema = column.Table.DatabaseSchema;
         if (schema != null)
         {
             var provider = schema.Provider;
             sqlType = ProviderToSqlType.Convert(provider) ?? SqlType.SqlServer;
             dataTypeList = schema.DataTypes;
         }
     }
     //does the schema data types contain this type? if so, assign it.
     var dataType = FindDataType(dbType, dataTypeList, sqlType, column.Length);
     column.DataType = dataType;
 }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:32,代码来源:DataTypeConverter.cs


示例3: WriteDataType

        public string WriteDataType(DatabaseColumn column)
        {
            if (column == null) return string.Empty;
            if (string.IsNullOrEmpty(column.DbDataType)) return string.Empty;
            var dataType = column.DbDataTypeStandard();

            dataType = OtherDatabaseTypesToPostgreSql(dataType, column);

            if ((dataType.StartsWith("TIMESTAMP", StringComparison.OrdinalIgnoreCase) || dataType == "TIME") &&
                column.DateTimePrecision > 0)
                dataType = dataType + " (" + column.DateTimePrecision + ")";

            //write out datatype definition
            if ((dataType == "VARCHAR" || dataType == "CHAR") && column.Length > 0)
            {
                dataType = dataType + " (" + column.Length + ")";
            }

            if (dataType == "NUMERIC" || dataType == "DECIMAL")
            {
                var scale = column.Scale;
                var precision = column.Precision;

                var writeScale = ((scale != null) && (scale > 0) ? "," + scale : "");
                if (precision > 0) //Postgresql can have no specified precision
                    dataType = dataType + " (" + precision + writeScale + ")";
            }

            return dataType;
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:30,代码来源:DataTypeWriter.cs


示例4: WriteDataType

        protected override string WriteDataType(DatabaseColumn column)
        {
            var type = new DataTypeWriter().WriteDataType(column);
            type += (!column.Nullable ? " NOT NULL" : string.Empty);

            var defaultValue = column.DefaultValue;
            if (!string.IsNullOrEmpty(defaultValue))
            {
                defaultValue = FixDefaultValue(defaultValue);
                const string defaultConstraint = " DEFAULT ";

                var dbDataType = column.DbDataType.ToUpperInvariant();
                if (DataTypeConverter.IsVariableString(dbDataType))
                {
                    type += defaultConstraint + "'" + defaultValue + "'";
                }
                else //numeric default
                {
                    type += defaultConstraint + defaultValue;
                }
            }

            //cannot detect the "GENERATED BY DEFAULT" vs "GENERATED ALWAYS" version?
            if (column.IsAutoNumber) type += " GENERATED BY DEFAULT AS IDENTITY";
            if (column.IsPrimaryKey && Table.PrimaryKey.Columns.Count == 1)
                type += " PRIMARY KEY";

            return type;
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:29,代码来源:TableGenerator.cs


示例5: GivenAlteredColumn

        public void GivenAlteredColumn()
        {
            //arrange
            DatabaseSchema schema1 = CreateSchema();
            var productsTable = CreateProductsTable();
            schema1.Tables.Add(productsTable);
            var nameColumn = new DatabaseColumn { Name = "Name", DbDataType = "NVARCHAR", Length = 10, Nullable = false };
            productsTable.Columns.Add(nameColumn);

            DatabaseSchema schema2 = CreateSchema();
            var productsTable2 = CreateProductsTable();
            var nameColumn2 = new DatabaseColumn { Name = "Name", DbDataType = "NVARCHAR", Length = 20, Nullable = true };
            productsTable2.Columns.Add(nameColumn2);
            schema2.Tables.Add(productsTable2);

            //act
            var comparison = new CompareSchemas(schema1, schema2);
            var result = comparison.ExecuteResult();

            //assert
            var alterColumn = result.FirstOrDefault(x =>
                                             x.ResultType == ResultType.Change &&
                                             x.SchemaObjectType == SchemaObjectType.Column &&
                                             x.TableName == "Products" &&
                                             x.Name == "Name");
            Assert.IsNotNull(alterColumn);
        }
开发者ID:roadrunner75,项目名称:dbschemareader,代码行数:27,代码来源:CompareSchemaResultsTest.cs


示例6: AddColumn

 public virtual string AddColumn(DatabaseTable databaseTable, DatabaseColumn databaseColumn)
 {
     var tableGenerator = CreateTableGenerator(databaseTable);
     var addColumn = tableGenerator.WriteColumn(databaseColumn).Trim();
     if (string.IsNullOrEmpty(databaseColumn.DefaultValue) && !databaseColumn.Nullable)
     {
         var dt = databaseColumn.DataType;
         if (dt == null || dt.IsString)
         {
             addColumn += " DEFAULT ''"; //empty string
         }
         else if (dt.IsNumeric)
         {
             addColumn += " DEFAULT 0";
         }
         else if (dt.IsDateTime)
         {
             addColumn += " DEFAULT CURRENT_TIMESTAMP";
         }
         //make sure the NOT NULL is AFTER the default
         addColumn = addColumn.Replace(" NOT NULL ", " ") + " NOT NULL";
     }
     return string.Format(CultureInfo.InvariantCulture,
         "ALTER TABLE {0} ADD {1}",
         TableName(databaseTable),
         addColumn) + LineEnding();
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:27,代码来源:MigrationGenerator.cs


示例7: DropColumn

 public override string DropColumn(DatabaseTable databaseTable, DatabaseColumn databaseColumn)
 {
     return string.Format(CultureInfo.InvariantCulture,
         "ALTER TABLE {0} DROP COLUMN {1} CASCADE;",
         TableName(databaseTable),
         Escape(databaseColumn.Name));
 }
开发者ID:faddiv,项目名称:dbschemareader,代码行数:7,代码来源:PostgreSqlMigrationGenerator.cs


示例8: GetProviderType

 private static int GetProviderType(DatabaseColumn column)
 {
     int providerType = -1;
     if (column.DataType != null)
         providerType = column.DataType.ProviderDbType;
     return providerType;
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:7,代码来源:DataTypeWriter.cs


示例9: AlterColumn

        public override string AlterColumn(DatabaseTable databaseTable, DatabaseColumn databaseColumn, DatabaseColumn originalColumn)
        {
            var sb = new StringBuilder();
            var defaultName = "DF_" + databaseTable.Name + "_" + databaseColumn.Name;
            if (originalColumn != null)
            {
                if (originalColumn.DefaultValue != null)
                {
                    //have to drop default contraint
                    var df = FindDefaultConstraint(databaseTable, databaseColumn.Name);
                    if (df != null)
                    {
                        defaultName = df.Name;
                        sb.AppendLine("ALTER TABLE " + TableName(databaseTable)
                                      + " DROP CONSTRAINT " + Escape(defaultName) + ";");
                    }
                }
            }
            //we could check if any of the properties are changed here
            sb.AppendLine(base.AlterColumn(databaseTable, databaseColumn, originalColumn));
            if (databaseColumn.DefaultValue != null)
            {
                //add default contraint
                sb.AppendLine("ALTER TABLE " + TableName(databaseTable) +
                    " ADD CONSTRAINT " + Escape(defaultName) +
                    " DEFAULT " + databaseColumn.DefaultValue +
                    " FOR " + Escape(databaseColumn.Name) + ";");
            }

            return sb.ToString();
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:31,代码来源:SqlServerMigrationGenerator.cs


示例10: IsStringColumn

 private static bool IsStringColumn(DatabaseColumn column)
 {
     var dataType = column.DbDataType.ToUpperInvariant();
     var isString = (dataType == "NVARCHAR" || dataType == "VARCHAR" || dataType == "CHAR");
     var dt = column.DataType;
     if (dt != null && dt.IsString) isString = true;
     return isString;
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:8,代码来源:TableGenerator.cs


示例11: ConvertDataTable

        private void ConvertDataTable()
        {
            var columnsKeyMap = new ColumnsKeyMap(ColumnsDataTable);
            var hasIsUnsigned = !string.IsNullOrEmpty(columnsKeyMap.IsUnsignedKey);

            foreach (DataRowView row in ColumnsDataTable.DefaultView)
            {
                var column = new DatabaseColumn();
                column.Name = row[columnsKeyMap.Key].ToString();
                column.TableName = row[columnsKeyMap.TableKey].ToString();

                if (!string.IsNullOrEmpty(columnsKeyMap.SchemaKey))
                    column.SchemaOwner = row[columnsKeyMap.SchemaKey].ToString();
                if (string.Equals("sqlite_default_schema", column.SchemaOwner, StringComparison.OrdinalIgnoreCase))
                    column.SchemaOwner = string.Empty;

                if (!string.IsNullOrEmpty(columnsKeyMap.OrdinalKey))
                    column.Ordinal = Convert.ToInt32(row[columnsKeyMap.OrdinalKey], CultureInfo.CurrentCulture);
                if (!string.IsNullOrEmpty(columnsKeyMap.DatatypeKey))
                    column.DbDataType = row[columnsKeyMap.DatatypeKey].ToString();
                if (hasIsUnsigned && CastToBoolean(row, columnsKeyMap.IsUnsignedKey))
                    column.DbDataType += " unsigned";

                AddNullability(row, columnsKeyMap.NullableKey, column);
                //the length unless it's an OleDb blob or clob
                if (!string.IsNullOrEmpty(columnsKeyMap.LengthKey))
                    column.Length = GetNullableInt(row[columnsKeyMap.LengthKey]);
                if (!string.IsNullOrEmpty(columnsKeyMap.DataLengthKey))
                {
                    //oracle only
                    var dataLength = GetNullableInt(row[columnsKeyMap.DataLengthKey]);
                    //column length already set for char/varchar. For other data types, get data length
                    if (column.Length < 1)
                        column.Length = dataLength;
                }
                if (!string.IsNullOrEmpty(columnsKeyMap.PrecisionKey))
                    column.Precision = GetNullableInt(row[columnsKeyMap.PrecisionKey]);
                if (!string.IsNullOrEmpty(columnsKeyMap.ScaleKey))
                    column.Scale = GetNullableInt(row[columnsKeyMap.ScaleKey]);
                if (columnsKeyMap.DateTimePrecision != null)
                {
                    column.DateTimePrecision = GetNullableInt(row[columnsKeyMap.DateTimePrecision]);
                }

                AddColumnDefault(row, columnsKeyMap.DefaultKey, column);
                if (!string.IsNullOrEmpty(columnsKeyMap.PrimaryKeyKey) && (bool)row[columnsKeyMap.PrimaryKeyKey])
                    column.IsPrimaryKey = true;
                if (!string.IsNullOrEmpty(columnsKeyMap.AutoIncrementKey) && (bool)row[columnsKeyMap.AutoIncrementKey])
                    column.IsAutoNumber = true;
                if (!string.IsNullOrEmpty(columnsKeyMap.UniqueKey) && CastToBoolean(row, columnsKeyMap.UniqueKey))
                    column.IsUniqueKey = true;

                _list.Add(column);
            }

            // Sort columns according to ordinal to get the original order in CREATE TABLE
            _list.Sort((x, y) => x.Ordinal.CompareTo(y.Ordinal));
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:58,代码来源:ColumnConverter.cs


示例12: OtherDatabaseTypesToPostgreSql

        private static string OtherDatabaseTypesToPostgreSql(string dataType, DatabaseColumn column)
        {
            //string types
            //character(n) (aka char(n)) character varying(n) aka varchar(n) and text
            if (DataTypeConverter.IsFixedLengthString(dataType))
            {
                return "CHAR";
            }
            if (DataTypeConverter.IsLongString(dataType))
            {
                return "TEXT";
            }
            if (DataTypeConverter.IsVariableString(dataType))
            {
                if (column.Length == -1) return "TEXT";
                return "VARCHAR";
            }

            //numeric types
            if (dataType == "INT") return "INTEGER";
            if (dataType == "INT4") return "INTEGER"; //this is a PostgreSql alias, we'll use standard SQL
            //else if (dataType == "SERIAL") return "INTEGER"; //this is a PostgreSql alias, we'll use standard SQL
            //else if (dataType == "BIGSERIAL") return "BIGINT"; //this is a PostgreSql alias, we'll use standard SQL
            if (dataType == "INT8") return "BIGINT"; //this is a PostgreSql alias, we'll use standard SQL
            if (dataType == "INT2") return "SMALLINT"; //this is a PostgreSql alias, we'll use standard SQL
            if (dataType == "TINYINT") return "SMALLINT"; //this is a MsSql alias, we'll use standard SQL
            if (dataType == "NUMBER")
                return DataTypeConverter.OracleNumberConversion(column.Precision, column.Scale);

            //float and real
            if (dataType == "FLOAT4") return "REAL"; //this is a PostgreSql alias, we'll use standard SQL
            if (dataType == "FLOAT") return "DOUBLE PRECISION";

            //date times
            //SqlServer Timestamp is a binary
            if (DataTypeConverter.IsSqlServerTimestamp(dataType, column))
                return "BYTEA"; //this is just a byte array- functionally you should redesign the table and perhaps use the system extension columns

            if (DataTypeConverter.IsDateTime(dataType))
                return "TIMESTAMP";

            //bytes
            if (DataTypeConverter.IsBlob(dataType, column.Length))
                return "OID";//blobs become object ids
            if (DataTypeConverter.IsBinary(dataType))
            {
                return "BYTEA";
            }

            //there is a native BIT(n) type in Postgresql, but in conversion we probably mean boolean.
            if (dataType == "BIT" && !column.Length.HasValue) return "BOOLEAN";

            //other types
            if (dataType == "XMLTYPE") return "XML";
            if (dataType == "UNIQUEIDENTIFIER") return "UUID";
            return dataType;
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:57,代码来源:DataTypeWriter.cs


示例13: IsString

 public static bool IsString(DatabaseColumn column, string dataType)
 {
     //all aliases for CHAR and VARCHAR. there's also a LONG VARCHAR
     if (DataTypeConverter.IsVariableString(dataType) ||
         DataTypeConverter.IsFixedLengthString(dataType))
         return true;
     if (column.DataType == null) return false;
     return column.DataType.IsString;
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:9,代码来源:DataTypeWriter.cs


示例14: IsSqlServerTimestamp

 public static bool IsSqlServerTimestamp(string dataType, DatabaseColumn column)
 {
     if (!dataType.StartsWith("TIMESTAMP", StringComparison.OrdinalIgnoreCase))
         return false;
     int providerType = -1;
     if (column.DataType != null)
         providerType = column.DataType.ProviderDbType;
     return (providerType == (int)SqlDbType.Timestamp); //this is just a byte array
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:9,代码来源:DataTypeConverter.cs


示例15: LooksLikeOracleIdentityColumn

 /// <summary>
 /// If a table has a trigger, we assume it's an Oracle trigger/sequence which is translated to identity for the primary key
 /// </summary>
 /// <param name="table">The table.</param>
 /// <param name="column">The column.</param>
 /// <returns></returns>
 public static bool LooksLikeOracleIdentityColumn(DatabaseTable table, DatabaseColumn column)
 {
     if (!column.IsPrimaryKey) return false;
     if (table.Triggers.Count == 0) return false;
     //is there a trigger body which looks like it's using a sequence?
     //if there's a sequence there, it's autogenerating a column - we assume the primary key!
     return table.Triggers.Any(t => t.TriggerBody
                                        .ToUpperInvariant()
                                        .Contains(".NEXTVAL "));
 }
开发者ID:roadrunner75,项目名称:dbschemareader,代码行数:16,代码来源:DataTypeWriter.cs


示例16: CreateData

 /// <summary>
 /// Creates sample data from a <see cref="DatabaseSchemaReader.DataSchema.DataType"/>
 /// </summary>
 /// <param name="column">The column.</param>
 /// <returns></returns>
 /// <exception cref="InvalidOperationException">Column is a non-nullable foreign key</exception>
 public static object CreateData(DatabaseColumn column)
 {
     if (column.IsForeignKey)
     {
         if (column.Nullable)
             return null;
         throw new InvalidOperationException("Column is a non-nullable foreign key - cannot generate data");
     }
     return CreateData(column.DataType, column.Length, column.Precision, column.Scale);
 }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:16,代码来源:DummyDataCreator.cs


示例17: TestDataTypeDefinitionForInt

        public void TestDataTypeDefinitionForInt()
        {
            //arrange
            var column = new DatabaseColumn { DbDataType = "int", DataType = new DataType("int", "int") };

            //act
            var result = column.DataTypeDefinition();

            //assert
            Assert.AreEqual("int", result);
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:11,代码来源:DatabaseColumnTest.cs


示例18: TypeString

        public void TypeString()
        {
            var typewriter = new DataTypeWriter();

            var column = new DatabaseColumn();
            column.DataType = new DataType("VARCHAR2", "System.String");

            var result = typewriter.Write(column);

            Assert.AreEqual("string", result);
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:11,代码来源:DataTypeWriterTest.cs


示例19: TypeInteger

        public void TypeInteger()
        {
            var typewriter = new DataTypeWriter();

            var column = new DatabaseColumn();
            column.DataType = new DataType("NUMBER", "System.Int32");

            var result = typewriter.Write(column);

            Assert.AreEqual("int", result);
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:11,代码来源:DataTypeWriterTest.cs


示例20: OtherDatabaseTypesToDb2

        private static string OtherDatabaseTypesToDb2(string dataType, DatabaseColumn column)
        {
            //string types
            if (DataTypeConverter.IsFixedLengthString(dataType))
            {
                return "CHAR";
            }
            if (DataTypeConverter.IsLongString(dataType))
            {
                return dataType == "CLOB" ? "CLOB" : "DBCLOB";
            }
            if (DataTypeConverter.IsVariableString(dataType))
            {
                if (column.Length == -1) return "DBCLOB";
                return "VARCHAR";
            }

            //numeric types
            if (dataType == "SMALLINT") return dataType;
            if (dataType == "BIGINT") return dataType;
            if (dataType == "INTEGER") return dataType;

            if (dataType == "INT") return "INTEGER";
            if (dataType == "NUM") return "NUMERIC"; //DB2 alias
            if (dataType == "DEC") return "DECIMAL"; //DB2 alias
            if (dataType == "MONEY") return "DECIMAL(19,4)";
            if (dataType == "BIT") return "SMALLINT"; //could be CHAR(1) but nicer with an integer
            if (dataType == "NUMBER")
                return DataTypeConverter.OracleNumberConversion(column.Precision, column.Scale);

            //date times
            //SqlServer Timestamp is a binary
            if (DataTypeConverter.IsSqlServerTimestamp(dataType, column))
                return "GRAPHIC";

            if (DataTypeConverter.IsDateTime(dataType))
                return "TIMESTAMP";

            //bytes
            if (DataTypeConverter.IsBlob(dataType, column.Length))
                return "BLOB";
            if (DataTypeConverter.IsBinary(dataType))
            {
                if (dataType == "LONG VARGRAPHIC") return dataType;
                if (dataType == "GRAPHIC") return dataType;
                return "VARGRAPHIC";
            }

            //other types
            if (dataType == "XMLTYPE") return "XML";
            if (dataType == "UNIQUEIDENTIFIER") return "CHAR(16) FOR BIT DATA";
            return dataType;
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:53,代码来源:DataTypeWriter.cs



注:本文中的DatabaseSchemaReader.DataSchema.DatabaseColumn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DataSchema.DatabaseSchema类代码示例发布时间:2022-05-24
下一篇:
C# DataTier.Data类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap