コード例 #1
0
 protected override string ParseColumn(TableColumnSchema column)
 {
     return(string.Format(@"{0} {1} {2} {3} {4}",
                          MakeDdlElementName(column.Name),
                          FBSchemaLoader.TypeDbsmToFb(column),
                          string.Empty, // column.computedBy == null ? string.Empty : ("COMPUTED BY " + column.computedBy),
                          column.DefaultValue.IsNullOrEmpty()
                                 ? string.Empty
                                 : @"DEFAULT {0}".FormatStr(column.DefaultValue),
                          column.Nullable ? string.Empty : @" NOT NULL"));
 }
コード例 #2
0
 /// <summary>
 /// Создать схему метаданных из исходной базы
 /// </summary>
 /// <param name="connStr"></param>
 public override DBSchema LoadExistingSchema(string connStr)
 {
     return(FBSchemaLoader.LoadSchema(connStr));
 }
コード例 #3
0
 protected override string ParseColumnAlter(TableColumnSchema mColumn, TableColumnSchema eColumn)
 {
     return(string.Format(@"{0} TYPE {1}",
                          MakeDdlElementName(eColumn.Name),
                          FBSchemaLoader.TypeDbsmToFb(mColumn)));
 }
コード例 #4
0
        protected override void AfterSchemaComparision(DBSchema existingSchema, DBSchema targetSchema)
        {
            // Drop Generators
            var i = 1;

            foreach (var eGen in existingSchema.Generators)
            {
                if (!targetSchema.IsGeneratorExist(eGen.Name))
                {
                    AddDdlCommand(i,
                                  eGen.Name,
                                  "Generator",
                                  MakeDdlGeneratorDrop(eGen));
                }
                i++;
            }
            // Create Generators
            i = 1;
            foreach (var mGenerator in targetSchema.Generators)
            {
                if (!existingSchema.IsGeneratorExist(mGenerator.Name))
                {
                    AddDdlCommand(i,
                                  mGenerator.Name,
                                  "Generator",
                                  MakeDdlGeneratorCreate(mGenerator));

                    AddDdlCommand(i,
                                  mGenerator.Name,
                                  "Generator",
                                  MakeDdlGeneratorSet(mGenerator));
                }
                i++;
            }

            foreach (var mTable in targetSchema.Tables)
            {
                var eTable = existingSchema.GetTable(mTable.Name);
                if (eTable != null)
                {
                    foreach (var mColumn in mTable.Columns)
                    {
                        var eColumn = eTable.GetColumn(mColumn.Name);
                        if (eColumn == null)
                        {
                            continue;
                        }
                        if (mTable.IsExactColumn(eColumn) || eColumn.Type == ColumnType.BlobSubtype1 ||
                            eColumn.Type == ColumnType.BinaryLargeObject)
                        {
                            continue;
                        }
                        if (mColumn.Type != eColumn.Type)
                        {
                            AddDdlCommand(i,
                                          eTable.Name + @"." + eColumn.Name,
                                          "Column",
                                          MakeDdlColumnAlter(mColumn, eColumn, eTable));
                        }
                        if (mColumn.Nullable && !eColumn.Nullable)
                        {
                            AddDdlCommand(i,
                                          eTable.Name + @"." + eColumn.Name,
                                          "Column",
                                          string.Format(@"
											UPDATE RDB$RELATION_FIELDS
											SET
												RDB$NULL_FLAG = NULL
											WHERE
												(RDB$FIELD_NAME = '{0}') AND (RDB$RELATION_NAME = '{1}')"                                                ,
                                                        eColumn.Name,
                                                        eTable.Name));
                        }
                        if (mColumn.DefaultValue == eColumn.DefaultValue)
                        {
                            continue;
                        }
                        if (mColumn.DefaultValue != null)
                        {
                            AddDdlCommand(i,
                                          eTable.Name + @"." + eColumn.Name,
                                          "Column",
                                          string.Format(@"
												ALTER TABLE {0}
												ADD IBE$$TEMP_COLUMN {1} DEFAULT {2}"                                                ,
                                                        MakeDdlElementName(eTable.Name),
                                                        FBSchemaLoader.TypeDbsmToFb(eColumn),
                                                        mColumn.DefaultValue));

                            AddDdlCommand(i++,
                                          eTable.Name + @"." + eColumn.Name,
                                          "Column",
                                          string.Format(@"
												UPDATE RDB$RELATION_FIELDS F1
												SET
													F1.RDB$DEFAULT_VALUE =
														(SELECT
															F2.RDB$DEFAULT_VALUE
														FROM
															RDB$RELATION_FIELDS F2
														WHERE
															(F2.RDB$RELATION_NAME = '{0}') AND (F2.RDB$FIELD_NAME = 'IBE$$TEMP_COLUMN')),
													F1.RDB$DEFAULT_SOURCE =
														(SELECT
															F3.RDB$DEFAULT_SOURCE
														FROM
															RDB$RELATION_FIELDS F3
														WHERE
															(F3.RDB$RELATION_NAME = '{0}') AND (F3.RDB$FIELD_NAME = 'IBE$$TEMP_COLUMN'))
												WHERE
													(F1.RDB$RELATION_NAME = '{0}') AND (F1.RDB$FIELD_NAME = '{0}')"                                                    ,
                                                        eTable.Name));

                            AddDdlCommand(i++,
                                          eTable.Name + @"." + eColumn.Name,
                                          "Column",
                                          string.Format(@"ALTER TABLE {0} DROP IBE$$TEMP_COLUMN",
                                                        MakeDdlElementName(eTable.Name)));
                        }
                        else
                        {
                            AddDdlCommand(i,
                                          eTable.Name + @"." + eColumn.Name,
                                          "Column",
                                          string.Format(@"
												UPDATE RDB$RELATION_FIELDS F1
												SET
													F1.RDB$DEFAULT_VALUE = NULL,
													F1.RDB$DEFAULT_SOURCE = NULL
												WHERE
													(F1.RDB$RELATION_NAME = '{0}') AND (F1.RDB$FIELD_NAME = '{1}')"                                                    ,
                                                        eTable.Name,
                                                        eColumn.Name));
                        }
                    }
                }
                i++;
            }
        }