Пример #1
0
        public IEnumerable<GenericDatabaseColumn> GetColumns(string table)
        {
            StringBuilder query = new StringBuilder();
            query.Append("USE [");
            query.Append(this.Credentials.Database);
            query.Append("] SELECT *, columnproperty(object_id(table_name), column_name, 'IsIdentity') as is_identity FROM information_schema.columns WHERE TABLE_CATALOG = '");
            query.Append(this.Credentials.Database);
            query.Append("' AND TABLE_NAME='");
            query.Append(table);
            query.Append("'");

            foreach (System.Data.IDataRecord record in SqlServer.ExecuteQueryText(query.ToString()))
            {
                GenericDatabaseColumn column = new GenericDatabaseColumn();
                column.Name = GetValue("COLUMN_NAME", record).ToString();
                column.ColumnDefault = (string) GetValue("COLUMN_DEFAULT", record);
                column.DataType = InferType((string) GetValue("DATA_TYPE", record));
                column.IsNullable = ((string) GetValue("IS_NULLABLE", record)).Equals("yes", StringComparison.OrdinalIgnoreCase);
                column.MaxLength = Convert.ToInt32(GetValue("CHARACTER_MAXIMUM_LENGTH", record));
                column.OrdinalPosition = Convert.ToInt32(GetValue("ORDINAL_POSITION", record));
                column.IsIdentity = Convert.ToBoolean(GetValue("is_identity", record));

                yield return column;
            }
        }
        public IEnumerable <GenericDatabaseColumn> GetColumns(string table)
        {
            StringBuilder query = new StringBuilder();

            query.Append("USE [");
            query.Append(this.Credentials.Database);
            query.Append("] SELECT *, columnproperty(object_id(table_name), column_name, 'IsIdentity') as is_identity FROM information_schema.columns WHERE TABLE_CATALOG = '");
            query.Append(this.Credentials.Database);
            query.Append("' AND TABLE_NAME='");
            query.Append(table);
            query.Append("'");

            foreach (System.Data.IDataRecord record in SqlServer.ExecuteQueryText(query.ToString()))
            {
                GenericDatabaseColumn column = new GenericDatabaseColumn();
                column.Name            = GetValue("COLUMN_NAME", record).ToString();
                column.ColumnDefault   = (string)GetValue("COLUMN_DEFAULT", record);
                column.DataType        = InferType((string)GetValue("DATA_TYPE", record));
                column.IsNullable      = ((string)GetValue("IS_NULLABLE", record)).Equals("yes", StringComparison.OrdinalIgnoreCase);
                column.MaxLength       = Convert.ToInt32(GetValue("CHARACTER_MAXIMUM_LENGTH", record));
                column.OrdinalPosition = Convert.ToInt32(GetValue("ORDINAL_POSITION", record));
                column.IsIdentity      = Convert.ToBoolean(GetValue("is_identity", record));

                yield return(column);
            }
        }