private void AddCKConstraints() { DataTable dt = SQLSvrDbi.GetCKConstraints(SchemaName, TableName); if (dt != null & dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { String constrDef = row["ConstraintDefinition"].ToString().Replace( "[", String.Empty).Replace("]", String.Empty); if (constrDef.Contains("year") || constrDef.Contains("getdate()")) // Ignore this constraint { continue; } //if (constrDef.Contains("year")) // constrDef = constrDef.Replace("year", "YEAR(CURRENT_DATE)"); //if (constrDef.Contains("getdate()")) // constrDef = constrDef.Replace("getdate()", "CURRENT_DATE"); if (row["ConstraintName"].ToString() == "CK_ProductInventory_Shelf") { continue; } Constraints.Add(String.Format( "CONSTRAINT {0} CHECK {1} ", row["ConstraintName"].ToString(), constrDef)); } } }
private void MigrateData() { Helper.Log(String.Format("Start migrating table {0}", TableFullName)); DataTable sqlTable = null; Migrator.OnMigrateEvent(new MigrateEventArgs( Result.Unknown, String.Format("Copying table {0} data...", TableFullName))); sqlTable = SQLSvrDbi.GetTableData(TableFullName); GFXDClientConnection connection = GemFireXDDbi.OpenNewConnection(); GemFireXDDbi.BatchInsert(connection, GetInsertSql(), sqlTable, this); while (connection.State == ConnectionState.Executing) { Helper.Log("Connection is still executing"); Thread.Sleep(5000); } Validate(sqlTable); Helper.Log(String.Format("Table {0} migrated", TableFullName)); }
private void AddFKConstraints() { DataTable dt = SQLSvrDbi.GetFKConstraints(SchemaName, TableName); if (dt != null & dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { String referencedTable = String.Format("{0}.{1}", SQLSvrDbi.GetTableSchema(row["ReferencedTableName"].ToString()), row["ReferencedTableName"].ToString().ToUpper()); for (int i = 0; i < Constraints.Count; i++) { if (Constraints[i].Contains(row["ConstraintName"].ToString())) { int startIndex = Constraints[i].IndexOf(row["ConstraintName"].ToString()); int endIndex = Constraints[i].IndexOf(')', startIndex); Constraints[i] = Constraints[i].Insert( endIndex, String.Format(", {0}", row["ColumnName"].ToString())); startIndex = Constraints[i].IndexOf(')', startIndex) + 1; endIndex = Constraints[i].IndexOf(')', startIndex); Constraints[i] = Constraints[i].Insert( endIndex, String.Format(", {0}", row["ReferencedColumnName"].ToString())); return; } } Constraints.Add(String.Format("CONSTRAINT {0} FOREIGN KEY ({1}) REFERENCES {2}({3}) ", row["ConstraintName"].ToString(), row["ColumnName"].ToString(), referencedTable, row["ReferencedColumnName"].ToString())); referencedTables.Add(referencedTable); if (referencedTable == TableFullName) { SelfRefColumn = row["ColumnName"].ToString(); } } } }
private void AddPKConstraint() { DataTable dt = SQLSvrDbi.GetPKConstraint(SchemaName, TableName); StringBuilder constraint = new StringBuilder(); if (dt != null & dt.Rows.Count > 0) { constraint.AppendFormat("CONSTRAINT {0} PRIMARY KEY (", dt.Rows[0]["ConstraintName"].ToString()); foreach (DataRow row in dt.Rows) { constraint.AppendFormat("{0}, ", row["ColumnName"].ToString()); } constraint = constraint.Remove(constraint.Length - 2, 1).Append(") "); Constraints.Add(constraint.ToString()); } }
private static void MigrateDbViews() { Helper.Log("Start migrating database views"); DataTable dt = SQLSvrDbi.GetViews(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { DbModule module = new DbModule(row["SchemaName"].ToString(), row["ViewName"].ToString(), row["ViewDefinition"].ToString(), ModuleType.View); module.Migrate(); } } Helper.Log("Finished migrating database views"); }
private static void MigrateDbStoredProcedures() { Helper.Log("Start migrating stored procedures"); DataTable dt = SQLSvrDbi.GetStoredProcedures(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { DbModule module = new DbModule( row["SchemaName"].ToString(), row["ProcedureName"].ToString(), row["ProcedureDefinition"].ToString(), ModuleType.StoredProcedure); module.Migrate(); } } Helper.Log("Finished migrating stored procedures"); }
private static void MigrateDbIndexes() { Helper.Log("Start migrating database indexes"); DataTable dt = SQLSvrDbi.GetIndexes(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { DbIndex index = new DbIndex( row["SchemaName"].ToString().ToUpper(), row["TableName"].ToString().ToUpper(), row["IndexName"].ToString().ToUpper(), row["ColumnName"].ToString().ToUpper(), bool.Parse(row["IsUnique"].ToString())); index.Migrate(); } } Helper.Log("Finished migrating database indexes"); }
private void AddColumns() { DataTable dt = SQLSvrDbi.GetTableColumns(SchemaName, TableName); if (dt != null & dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { DbField field = new DbField(); String colName = row["ColumnName"].ToString().Trim(); if (GemFireXDDbi.IsReservedWord(colName)) { colName = String.Format("\"{0}\"", colName); } if (colName.Contains(" ")) { colName = colName.Replace(" ", "_"); } field.FieldName = colName; if (!String.IsNullOrEmpty(row["CharMaxLength"].ToString())) { field.Length = Convert.ToInt32(row["CharMaxLength"].ToString()); } field.FieldType = DbTypeMap.GetGFXDTypeFromSqlType(row["DataType"].ToString()); if (row["IsNullable"].ToString().Trim() == "YES") { field.IsNullable = true; } Columns.Add(field); } } }
private static void MigrateDbTables() { Helper.Log("Start migrating database tables"); DataTable dt = SQLSvrDbi.GetTableNames(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { DbTable table = new DbTable( row["SchemaName"].ToString().ToUpper(), row["TableName"].ToString().ToUpper()); dbTableList.Add(table.TableFullName, table); } foreach (DbTable table in dbTableList.Values) { table.Migrate(); } } Helper.Log("Finished migrating database tables"); }