Пример #1
0
        protected override void FillTableColumns(DBSchemaTableColumnCollection atablecolumns, DataTable dtColumns)
        {
            DataColumn TableNameColumn          = GetColumn(dtColumns, "TABLE_NAME", true);
            DataColumn TableSchemaColumn        = GetColumn(dtColumns, "TABLE_SCHEMA", false);
            DataColumn TableCatalogColumn       = GetColumn(dtColumns, "TABLE_CATALOG", false);
            DataColumn ColumnNameColumn         = GetColumn(dtColumns, "COLUMN_NAME", true);
            DataColumn OrdinalPositionColumn    = GetColumn(dtColumns, "ORDINAL_POSITION", true);
            DataColumn DefaultValueColumn       = GetColumn(dtColumns, "COLUMN_DEFAULT", false);
            DataColumn IsNullableColumn         = GetColumn(dtColumns, "IS_NULLABLE", true);
            DataColumn DataTypeColumn           = GetColumn(dtColumns, "EDM_TYPE", true);
            DataColumn MaxCharacterLengthColumn = GetColumn(dtColumns, "CHARACTER_MAXIMUM_LENGTH", false);
            DataColumn AutoNumberColumn         = GetColumn(dtColumns, "AUTOINCREMENT", false);
            DataColumn PrimaryKeyColumn         = GetColumn(dtColumns, "PRIMARY_KEY", false);
            DataColumn CharacterSetColumn       = GetColumn(dtColumns, "CHARACTER_SET_NAME", false);

            foreach (DataRow row in dtColumns.Rows)
            {
                DBSchemaTableColumn col = new DBSchemaTableColumn();
                col.Name            = GetColumnStringValue(row, ColumnNameColumn);
                col.OrdinalPosition = GetColumnIntValue(row, OrdinalPositionColumn);
                col.DefaultValue    = GetColumnStringValue(row, DefaultValueColumn);
                col.Nullable        = GetColumnBoolValue(row, IsNullableColumn);
                col.NativeType      = GetColumnStringValue(row, DataTypeColumn);
                col.DbType          = GetDbTypeForNativeType(col.NativeType, GetColumnStringValue(row, CharacterSetColumn));
                col.Type            = GetSystemTypeForNativeType(GetColumnStringValue(row, DataTypeColumn));
                col.Size            = GetColumnIntValue(row, MaxCharacterLengthColumn);
                col.AutoAssign      = GetColumnBoolValue(row, AutoNumberColumn);
                col.PrimaryKey      = GetColumnBoolValue(row, PrimaryKeyColumn);
                col.ReadOnly        = col.AutoAssign;
                col.HasDefault      = !string.IsNullOrEmpty(col.DefaultValue);

                atablecolumns.Add(col);
            }
        }
Пример #2
0
        protected override void FillTableColumns(DBSchemaTableColumnCollection atablecolumns, DataTable dtColumns)
        {
            DataColumn autoinc            = GetColumn(dtColumns, "IsAutoIncrement", true);
            DataColumn colname            = GetColumn(dtColumns, "ColumnName", true);
            DataColumn ispk               = GetColumn(dtColumns, "IsKey", true);
            DataColumn isRO               = GetColumn(dtColumns, "IsReadOnly", true);
            DataColumn type               = GetColumn(dtColumns, "DataType", true);
            DataColumn allownull          = GetColumn(dtColumns, "AllowDBNull", true);
            DataColumn pos                = GetColumn(dtColumns, "ColumnOrdinal", true);
            DataColumn size               = GetColumn(dtColumns, "ColumnSize", true);
            DataColumn dataType           = GetColumn(dtColumns, "DataTypeName", true);
            DataColumn CharacterSetColumn = GetColumn(dtColumns, "CHARACTERSET", false);

            foreach (DataRow coldef in dtColumns.Rows)
            {
                DBSchemaTableColumn tcol = new DBSchemaTableColumn();
                tcol.Name            = GetColumnStringValue(coldef, colname);
                tcol.AutoAssign      = GetColumnBoolValue(coldef, autoinc);
                tcol.HasDefault      = false;
                tcol.Nullable        = GetColumnBoolValue(coldef, allownull);
                tcol.OrdinalPosition = GetColumnIntValue(coldef, pos);
                tcol.PrimaryKey      = GetColumnBoolValue(coldef, ispk);
                tcol.ReadOnly        = GetColumnBoolValue(coldef, isRO);
                tcol.Size            = GetColumnIntValue(coldef, size);
                tcol.Type            = Type.GetType(GetColumnStringValue(coldef, type));
                tcol.NativeType      = GetColumnStringValue(coldef, dataType);
                tcol.DbType          = this.GetDbTypeForNativeType(tcol.NativeType, GetColumnStringValue(coldef, CharacterSetColumn));

                atablecolumns.Add(tcol);
            }
        }
Пример #3
0
        /// <summary>
        /// Fills the information in atablecolumns with the data from dtColumns
        /// </summary>
        /// <param name="atablecolumns"></param>
        /// <param name="dtColumns"></param>
        protected override void FillTableColumns(DBSchemaTableColumnCollection atablecolumns, DataTable dtColumns)
        {
            DataColumn TableNameColumn          = GetColumn(dtColumns, "TABLE_NAME", true);
            DataColumn TableSchemaColumn        = GetColumn(dtColumns, "TABLE_SCHEMA", false);
            DataColumn TableCatalogColumn       = GetColumn(dtColumns, "TABLE_CATALOG", false);
            DataColumn ColumnNameColumn         = GetColumn(dtColumns, "COLUMN_NAME", true);
            DataColumn OrdinalPositionColumn    = GetColumn(dtColumns, "ORDINAL_POSITION", true);
            DataColumn DefaultValueColumn       = GetColumn(dtColumns, "COLUMN_DEFAULT", false);
            DataColumn IsNullableColumn         = GetColumn(dtColumns, "IS_NULLABLE", true);
            DataColumn DataTypeColumn           = GetColumn(dtColumns, "DATA_TYPE", true);
            DataColumn MaxCharacterLengthColumn = GetColumn(dtColumns, "CHARACTER_MAXIMUM_LENGTH", false);
            DataColumn AutoNumberColumn         = GetColumn(dtColumns, "AUTOINCREMENT", false);
            DataColumn PrimaryKeyColumn         = GetColumn(dtColumns, "PRIMARY_KEY", false);

            foreach (DataRow row in dtColumns.Rows)
            {
                DBSchemaTableColumn col = new DBSchemaTableColumn();
                col.Name            = GetColumnStringValue(row, ColumnNameColumn);
                col.OrdinalPosition = GetColumnIntValue(row, OrdinalPositionColumn);
                col.DefaultValue    = GetColumnStringValue(row, DefaultValueColumn);
                col.Nullable        = GetColumnBoolValue(row, IsNullableColumn);
                int type = GetColumnIntValue(row, DataTypeColumn, -1);
                DBMSAccessTypeMapping map;

                if (type > 0 && this.Types.TryGetType(type, out map))
                {
                    col.NativeType = map.TypeName;
                    col.DbType     = GetDbTypeForNativeType(map.TypeName, string.Empty);
                    col.Type       = map.RuntimeType;
                    if (col.DbType == DbType.Object && null != map.RuntimeType)
                    {
                        col.DbType = DBHelper.GetDBTypeForRuntimeType(map.RuntimeType);
                    }
                }
                col.Size       = GetColumnIntValue(row, MaxCharacterLengthColumn);
                col.AutoAssign = GetColumnBoolValue(row, AutoNumberColumn);
                col.PrimaryKey = GetColumnBoolValue(row, PrimaryKeyColumn);
                col.ReadOnly   = col.AutoAssign;
                col.HasDefault = !string.IsNullOrEmpty(col.DefaultValue);

                atablecolumns.Add(col);
            }
        }
        private void ScriptCreateTableColumn(DBSchemaTableColumn tc, int index)
        {
            if (string.IsNullOrEmpty(tc.Name))
            {
                throw new ArgumentNullException("schemaTable.Columns[" + tc.OrdinalPosition + "].Name");
            }
            this.BeginIdentifier();
            this.WriteObjectName(tc.Name);
            this.EndIdentifier();
            this.WriteSpace();

            string options;
            string type = this.GetNativeTypeForDbType(tc.DbType, tc.Size, tc.Precision, tc.ColumnFlags, out options);

            this.WriteRawSQLString(type);
            if (string.IsNullOrEmpty(options) == false)
            {
                this.WriteRawSQLString(options);
            }

            if (tc.Nullable == false)
            {
                this.WriteRawSQLString(" NOT NULL");
            }
            if (tc.AutoAssign)
            {
                this.WriteRawSQLString(" AUTO_INCREMENT");
            }
            //if (tc.PrimaryKey)
            //    this.WriteRaw(" PRIMARY KEY");

            if (tc.HasDefault && string.IsNullOrEmpty(tc.DefaultValue))
            {
                this.WriteRawSQLString(" DEFAULT ");
                this.WriteRawSQLString(tc.DefaultValue);
            }
        }