Пример #1
0
        private string GenerateForeignKeyScript(ConstraintForeignKey c)
        {
            if (c == null)
            {
                return(string.Empty);
            }

            return($"EXECUTE IMMEDIATE 'ALTER TABLE {c.Schema}.{c.TableName} ADD CONSTRAINT {c.Name} FOREIGN KEY ({c.TableColumnName}) REFERENCES {c.ReferencedTableSchemaName}.{c.ReferencedTableName}({c.ReferencedTableColumnName})';");
        }
Пример #2
0
 public static ConstraintForeignKey MockConstraintForeignKey() => ConstraintForeignKey.CreateNew(
     Schema,
     NameConstraint,
     NameTable,
     NameTableColumn,
     ReferencedSchemaName,
     ReferencedTableName,
     ReferencedColumnName,
     null);
Пример #3
0
        private Column TabToModelColumn()
        {
            columnDataLengthTextBox.Text.ParseNullable(out var dataLength);

            ConstraintForeignKey foreignKey = null;

            if (columnIsFkCheckBox.Checked)
            {
                var index = Constraint.CreateNew(columnsSchemaTextBox.Text, columnIndexNameTextBox.Text, columnsTableNameTextBox.Text, columnColumnTextBox.Text, null);

                foreignKey = ConstraintForeignKey.CreateNew(columnsSchemaTextBox.Text, columnFkNameTextBox.Text, columnsTableNameTextBox.Text,
                                                            columnColumnTextBox.Text, columnRefSchemaNameTextBox.Text, columnRefTableNameTextBox.Text, columnRefColumnNameTextBox.Text, index);
            }

            tabColumn = Column.CreateNew(columnsSchemaTextBox.Text, columnsTableNameTextBox.Text, columnColumnTextBox.Text,
                                         (DataType)columnTypeComboBox.SelectedValue, dataLength, columnDefaultTextBox.Text, columnIsNullableCheckBox.Checked,
                                         columnCommentTextBox.Text, false, null, false, null, columnIsFkCheckBox.Checked, foreignKey);

            return(tabColumn);
        }
Пример #4
0
 /// <summary>
 /// Creates a new column
 /// </summary>
 /// <param name="tableSchema"></param>
 /// <param name="tableName"></param>
 /// <param name="name"></param>
 /// <param name="dataType"></param>
 /// <param name="dataLength"></param>
 /// <param name="defaultValue"></param>
 /// <param name="isNullable"></param>
 /// <param name="comment"></param>
 /// <param name="hasPrimaryKeyConstraint"></param>
 /// <param name="primaryKey"></param>
 /// <param name="hasUniqueConstraint"></param>
 /// <param name="uniqueConstraint"></param>
 /// <param name="hasForeignKeyConstraint"></param>
 /// <param name="foreignKey"></param>
 /// <returns></returns>
 public static Column CreateNew(string tableSchema, string tableName, string name, DataType dataType, int?dataLength, string defaultValue,
                                bool isNullable, string comment, bool hasPrimaryKeyConstraint, Constraint primaryKey, bool hasUniqueConstraint, Constraint uniqueConstraint,
                                bool hasForeignKeyConstraint, ConstraintForeignKey foreignKey)
 {
     return(new Column()
     {
         TableSchema = tableSchema,
         TableName = tableName,
         Name = name,
         DataType = dataType,
         DataLength = dataLength,
         DefaultValue = defaultValue,
         IsNullable = isNullable,
         Comment = comment,
         HasPrimaryKeyConstraint = hasPrimaryKeyConstraint,
         PrimaryKey = primaryKey,
         HasUniqueConstraint = hasUniqueConstraint,
         UniqueConstraint = uniqueConstraint,
         HasForeignKeyConstraint = hasForeignKeyConstraint,
         ForeignKey = foreignKey
     });
 }
Пример #5
0
        private Table TabToModelTable()
        {
            var columns = new HashSet <Column>();

            //Loop through each row and form column, comment, foreign key script values.
            foreach (DataGridViewRow row in tableColumnsGrid.Rows)
            {
                ConstraintForeignKey foreignKey = null;

                var hasForeignKeyConstraint = GetCellValueBool(row, tableCellKeyIsForeignKey);
                if (hasForeignKeyConstraint)
                {
                    var index = Constraint.CreateNew(
                        tableSchemaTextBox.Text,
                        GetCellValue <string>(row, tableCellKeyIndexName),
                        tableTableNameTextBox.Text,
                        GetCellValue <string>(row, tableCellKeyName),
                        null);

                    foreignKey = ConstraintForeignKey.CreateNew(
                        tableSchemaTextBox.Text,
                        GetCellValue <string>(row, tableCellKeyForeignKeyName),
                        tableTableNameTextBox.Text,
                        GetCellValue <string>(row, tableCellKeyName),
                        GetCellValue <string>(row, tableCellKeyForeignKeyReferencedSchema),
                        GetCellValue <string>(row, tableCellKeyForeignKeyReferencedTable),
                        GetCellValue <string>(row, tableCellKeyForeignKeyReferencedTableColumn),
                        index);
                }

                var        hasPrimaryKey = GetCellValueBool(row, tableCellKeyIsPrimaryKey);
                Constraint primaryKey    = null;
                if (hasPrimaryKey)
                {
                    primaryKey = Constraint.CreateNew(
                        tableSchemaTextBox.Text,
                        tablePKTextBox.Text,
                        tableTableNameTextBox.Text,
                        GetCellValue <string>(row, tableCellKeyName),
                        null);
                }

                var        hasUniqueConstraint = GetCellValueBool(row, tableCellKeyIsUnique);
                Constraint uniqueConstraint    = null;
                if (hasUniqueConstraint)
                {
                    uniqueConstraint = Constraint.CreateNew(
                        tableSchemaTextBox.Text,
                        GetCellValue <string>(row, tableCellKeyUniqueConstraintName),
                        tableTableNameTextBox.Text,
                        GetCellValue <string>(row, tableCellKeyName),
                        null);
                }

                GetCellValue <string>(row, tableCellKeyDataLength).ParseNullable(out var dataLength);
                var isNullable = GetCellValueBool(row, tableCellKeyIsNullable);

                var column = Column.CreateNew(
                    tableSchemaTextBox.Text,
                    tableTableNameTextBox.Text,
                    GetCellValue <string>(row, tableCellKeyName),
                    GetCellValue <DataType>(row, tableCellKeyType),
                    dataLength,
                    GetCellValue <string>(row, tableCellKeyDefault),
                    isNullable,
                    GetCellValue <string>(row, tableCellKeyComment),
                    hasPrimaryKey,
                    primaryKey,
                    hasUniqueConstraint,
                    uniqueConstraint,
                    hasForeignKeyConstraint,
                    foreignKey);

                columns.Add(column);
            }

            tabTable = Table.CreateNew(
                tableTableNameTextBox.Text,
                tableSchemaTextBox.Text,
                tableTableCommentTextBox.Text,
                tableTablespaceTextBox.Text,
                columns);

            return(tabTable);
        }