private string CREATE_TABLE() { string format = TableClause.GenerateCREATE_TABLE(schema); string script = string.Format(format, tableName.FormalName); return(script); }
public void Insert(DataRow row) { if (tableScript == null) tableScript = new TableClause(schema); string sql = tableScript.INSERT(row); new SqlCmd(TableName.Provider, sql).ExecuteNonQuery(); }
public static string GenerateIfDropClause(this TableName tname) { TableSchema schema = new TableSchema(tname); var script = new TableClause(schema); StringBuilder builder = new StringBuilder(); builder.Append(script.IF_EXISTS_DROP_TABLE()) .AppendLine(SqlScript.GO); return(builder.ToString()); }
private string Compare(IPrimaryKeys pk, DataTable table1, DataTable table2) { this.PkColumns = pk; this.compareColumns = table1.Columns .OfType<DataColumn>() .Select(row => row.ColumnName) .Except(PkColumns.Keys) .Except(ExceptColumns) .ToArray(); StringBuilder builder = new StringBuilder(); TableClause script = new TableClause(schema1); List<DataRow> R2 = new List<DataRow>(); foreach (DataRow row1 in table1.Rows) { var row2 = table2.AsEnumerable().Where(row => RowCompare.Compare(PkColumns.Keys, row, row1)).FirstOrDefault(); if (row2 != null) { if (!RowCompare.Compare(compareColumns, row1, row2)) { var compare = new RowCompare(this, row1, row2); builder.AppendLine(script.UPDATE(compare)); } R2.Add(row2); } else { builder.Append(script.INSERT(row1)); builder.AppendLine(); } } if (SideType != CompareSideType.copy) { foreach (DataRow row2 in table2.Rows) { if (R2.IndexOf(row2) < 0) { builder.AppendLine(script.DELETE(row2, pk)); } } } if (builder.ToString() != string.Empty && SideType == CompareSideType.compare) builder.AppendLine(TableClause.GO); return builder.ToString(); }
public static string GenerateCreateTableClause(this TableName tname, bool appendGO) { TableSchema schema = new TableSchema(tname); var script = new TableClause(schema); string SQL = script.GenerateCreateTableScript(); if (!appendGO) { return(SQL); } else { return(new StringBuilder(SQL).AppendLine(SqlScript.GO).ToString()); } }