本文整理汇总了C#中Aurora.Framework.ColumnDefinition类的典型用法代码示例。如果您正苦于以下问题:C# ColumnDefinition类的具体用法?C# ColumnDefinition怎么用?C# ColumnDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ColumnDefinition类属于Aurora.Framework命名空间,在下文中一共展示了ColumnDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyTableToTable
public void CopyTableToTable(string sourceTableName, string destinationTableName, ColumnDefinition[] columnDefinitions)
{
if (!TableExists(sourceTableName))
{
throw new MigrationOperationException("Cannot copy table to new name, source table does not exist: " + sourceTableName);
}
if (TableExists(destinationTableName))
{
throw new MigrationOperationException("Cannot copy table to new name, table with same name already exists: " + destinationTableName);
}
if (!VerifyTableExists(sourceTableName, columnDefinitions))
{
throw new MigrationOperationException("Cannot copy table to new name, source table does not match columnDefinitions: " + destinationTableName);
}
EnsureTableExists(destinationTableName, columnDefinitions);
CopyAllDataBetweenMatchingTables(sourceTableName, destinationTableName, columnDefinitions);
}
示例2: UpdateTable
public override void UpdateTable(string table, ColumnDefinition[] columns,
Dictionary<string, string> renameColumns)
{
table = table.ToLower();
if (!TableExists(table))
{
throw new DataManagerException("Trying to update a table with name of one that does not exist.");
}
List<ColumnDefinition> oldColumns = ExtractColumnsFromTable(table);
Dictionary<string, ColumnDefinition> removedColumns = new Dictionary<string, ColumnDefinition>();
Dictionary<string, ColumnDefinition> modifiedColumns = new Dictionary<string, ColumnDefinition>();
#if (!ISWIN)
Dictionary<string, ColumnDefinition> addedColumns = new Dictionary<string, ColumnDefinition>();
foreach (ColumnDefinition column in columns)
{
if (!oldColumns.Contains(column)) addedColumns.Add(column.Name.ToLower(), column);
}
foreach (ColumnDefinition column in oldColumns)
{
if (!columns.Contains(column))
{
if (addedColumns.ContainsKey(column.Name.ToLower()))
{
if (column.Name.ToLower() != addedColumns[column.Name.ToLower()].Name.ToLower() || column.Type != addedColumns[column.Name.ToLower()].Type)
modifiedColumns.Add(column.Name.ToLower(), addedColumns[column.Name.ToLower()]);
addedColumns.Remove(column.Name.ToLower());
}
else
removedColumns.Add(column.Name.ToLower(), column);
}
}
#else
Dictionary<string, ColumnDefinition> addedColumns =
columns.Where(column => !oldColumns.Contains(column)).ToDictionary(column => column.Name.ToLower());
foreach (ColumnDefinition column in oldColumns.Where(column => !columns.Contains(column)))
{
if (addedColumns.ContainsKey(column.Name.ToLower()))
{
if (column.Name.ToLower() != addedColumns[column.Name.ToLower()].Name.ToLower() ||
column.Type != addedColumns[column.Name.ToLower()].Type)
modifiedColumns.Add(column.Name.ToLower(), addedColumns[column.Name.ToLower()]);
addedColumns.Remove(column.Name.ToLower());
}
else
removedColumns.Add(column.Name.ToLower(), column);
}
#endif
try
{
#if (!ISWIN)
foreach (ColumnDefinition column in addedColumns.Values)
{
string addedColumnsQuery = "add `" + column.Name + "` " + GetColumnTypeStringSymbol(column.Type) + " ";
string query = string.Format("alter table " + table + " " + addedColumnsQuery);
ExecuteNonQuery(query, new Dictionary<string, object>());
}
foreach (ColumnDefinition column in modifiedColumns.Values)
{
string modifiedColumnsQuery = "modify column `" + column.Name + "` " + GetColumnTypeStringSymbol(column.Type) + " ";
string query = string.Format("alter table " + table + " " + modifiedColumnsQuery);
ExecuteNonQuery(query, new Dictionary<string, object>());
}
foreach (ColumnDefinition column in removedColumns.Values)
{
string droppedColumnsQuery = "drop `" + column.Name + "` ";
string query = string.Format("alter table " + table + " " + droppedColumnsQuery);
ExecuteNonQuery(query, new Dictionary<string, object>());
}
#else
foreach (string query in addedColumns.Values.Select(column => "add `" + column.Name + "` " + GetColumnTypeStringSymbol(column.Type) +
" ").Select(addedColumnsQuery => string.Format("alter table " + table + " " + addedColumnsQuery)))
{
ExecuteNonQuery(query, new Dictionary<string, object>());
}
foreach (string query in modifiedColumns.Values.Select(column => "modify column `" + column.Name + "` " +
GetColumnTypeStringSymbol(column.Type) + " ").Select(modifiedColumnsQuery => string.Format("alter table " + table + " " + modifiedColumnsQuery)))
{
ExecuteNonQuery(query, new Dictionary<string, object>());
}
foreach (string query in removedColumns.Values.Select(column => "drop `" + column.Name + "` ").Select(droppedColumnsQuery => string.Format("alter table " + table + " " + droppedColumnsQuery)))
{
ExecuteNonQuery(query, new Dictionary<string, object>());
}
#endif
}
catch (Exception e)
{
MainConsole.Instance.Error("[MySQLDataLoader] UpdateTable", e);
}
}
示例3: CopyAllDataBetweenMatchingTables
protected abstract void CopyAllDataBetweenMatchingTables(string sourceTableName, string destinationTableName, ColumnDefinition[] columnDefinitions, IndexDefinition[] indexDefinitions);
示例4: EnsureTableExists
public void EnsureTableExists(string tableName, ColumnDefinition[] columnDefinitions, IndexDefinition[] indexDefinitions, Dictionary<string, string> renameColumns)
{
if (TableExists(tableName))
{
if (!VerifyTableExists(tableName, columnDefinitions, indexDefinitions))
{
//throw new MigrationOperationException("Cannot create, table with same name and different columns already exists. This should be fixed in a migration: " + tableName);
UpdateTable(tableName, columnDefinitions, indexDefinitions, renameColumns);
}
return;
}
CreateTable(tableName, columnDefinitions, indexDefinitions);
}
示例5: UpdateTable
public override void UpdateTable(string table, ColumnDefinition[] columns,
Dictionary<string, string> renameColumns)
{
if (!TableExists(table))
{
throw new DataManagerException("Trying to update a table with name of one that does not exist.");
}
List<ColumnDefinition> oldColumns = ExtractColumnsFromTable(table);
Dictionary<string, ColumnDefinition> sameColumns = new Dictionary<string, ColumnDefinition>();
foreach (ColumnDefinition column in oldColumns)
{
#if (!ISWIN)
foreach (ColumnDefinition innercolumn in columns)
{
if (innercolumn.Name.ToLower() == column.Name.ToLower() || renameColumns.ContainsKey(column.Name) && renameColumns[column.Name].ToLower() == innercolumn.Name.ToLower())
{
sameColumns.Add(column.Name, column);
break;
}
}
#else
if (columns.Any(innercolumn => innercolumn.Name.ToLower() == column.Name.ToLower() ||
renameColumns.ContainsKey(column.Name) &&
renameColumns[column.Name].ToLower() == innercolumn.Name.ToLower()))
{
sameColumns.Add(column.Name, column);
}
#endif
}
string renamedTempTableColumnDefinition = string.Empty;
string renamedTempTableColumn = string.Empty;
foreach (ColumnDefinition column in oldColumns)
{
if (renamedTempTableColumnDefinition != string.Empty)
{
renamedTempTableColumnDefinition += ", ";
renamedTempTableColumn += ", ";
}
renamedTempTableColumn += column.Name;
renamedTempTableColumnDefinition += column.Name + " " + GetColumnTypeStringSymbol(column.Type);
}
string query = "CREATE TABLE " + table + "__temp(" + renamedTempTableColumnDefinition + ");";
var cmd = new SQLiteCommand {CommandText = query};
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
query = "INSERT INTO " + table + "__temp SELECT " + renamedTempTableColumn + " from " + table + ";";
cmd = new SQLiteCommand {CommandText = query};
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
query = "drop table " + table;
cmd = new SQLiteCommand {CommandText = query};
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
string newTableColumnDefinition = string.Empty;
#if (!ISWIN)
List<ColumnDefinition> primaryColumns = new List<ColumnDefinition>();
foreach (ColumnDefinition column in columns)
{
if (column.IsPrimary) primaryColumns.Add(column);
}
#else
List<ColumnDefinition> primaryColumns = columns.Where(column => column.IsPrimary).ToList();
#endif
bool multiplePrimary = primaryColumns.Count > 1;
foreach (ColumnDefinition column in columns)
{
if (newTableColumnDefinition != string.Empty)
{
newTableColumnDefinition += ", ";
}
newTableColumnDefinition += column.Name + " " + GetColumnTypeStringSymbol(column.Type) +
((column.IsPrimary && !multiplePrimary) ? " PRIMARY KEY" : string.Empty);
}
string multiplePrimaryString = string.Empty;
if (multiplePrimary)
{
string listOfPrimaryNamesString = string.Empty;
foreach (ColumnDefinition column in primaryColumns)
{
if (listOfPrimaryNamesString != string.Empty)
{
listOfPrimaryNamesString += ", ";
}
listOfPrimaryNamesString += column.Name;
}
multiplePrimaryString = string.Format(", PRIMARY KEY ({0}) ", listOfPrimaryNamesString);
}
query = string.Format("create table " + table + " ( {0} {1}) ", newTableColumnDefinition,
multiplePrimaryString);
//.........这里部分代码省略.........
示例6: CopyAllDataBetweenMatchingTables
protected override void CopyAllDataBetweenMatchingTables(string sourceTableName, string destinationTableName,
ColumnDefinition[] columnDefinitions)
{
var cmd = new SQLiteCommand
{
CommandText =
string.Format("insert into {0} select * from {1}", destinationTableName,
sourceTableName)
};
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
}
示例7: UpdateTable
public override void UpdateTable(string table, ColumnDefinition[] columns,
Dictionary<string, string> renameColumns)
{
if (TableExists(table))
{
throw new DataManagerException("Trying to create a table with name of one that already exists.");
}
string columnDefinition = string.Empty;
var primaryColumns = (from cd in columns where cd.IsPrimary select cd);
bool multiplePrimary = primaryColumns.Count() > 1;
foreach (ColumnDefinition column in columns)
{
if (columnDefinition != string.Empty)
{
columnDefinition += ", ";
}
columnDefinition += column.Name + " " + GetColumnTypeStringSymbol(column.Type) +
((column.IsPrimary && !multiplePrimary) ? " PRIMARY KEY" : string.Empty);
}
string multiplePrimaryString = string.Empty;
if (multiplePrimary)
{
string listOfPrimaryNamesString = string.Empty;
foreach (ColumnDefinition column in primaryColumns)
{
if (listOfPrimaryNamesString != string.Empty)
{
listOfPrimaryNamesString += ", ";
}
listOfPrimaryNamesString += column.Name;
}
multiplePrimaryString = string.Format(", PRIMARY KEY ({0}) ", listOfPrimaryNamesString);
}
string query = string.Format("create table " + table + " ( {0} {1}) ", columnDefinition,
multiplePrimaryString);
SqlConnection dbcon = GetLockedConnection();
SqlCommand dbcommand = dbcon.CreateCommand();
dbcommand.CommandText = query;
dbcommand.ExecuteNonQuery();
CloseDatabase(dbcon);
}
示例8: RestoreTempTableToReal
private void RestoreTempTableToReal(IDataConnector genericData, string tablename, ColumnDefinition[] columnDefinitions)
{
genericData.CopyTableToTable(GetTempTableNameFromTableName(GetTempTableNameFromTableName(tablename)), tablename, columnDefinitions);
}
示例9: CreateTable
public override void CreateTable(string table, ColumnDefinition[] columns, IndexDefinition[] indices)
{
if (TableExists(table))
{
throw new DataManagerException("Trying to create a table with name of one that already exists.");
}
IndexDefinition primary = null;
foreach (IndexDefinition index in indices)
{
if (index.Type == IndexType.Primary)
{
primary = index;
break;
}
}
List<string> columnDefinition = new List<string>();
bool has_auto_increment = false;
foreach (ColumnDefinition column in columns)
{
if (column.Type.auto_increment)
{
has_auto_increment = true;
}
columnDefinition.Add(column.Name + " " + GetColumnTypeStringSymbol(column.Type));
}
if (!has_auto_increment && primary != null && primary.Fields.Length > 0)
{
columnDefinition.Add("PRIMARY KEY (" + string.Join(", ", primary.Fields) + ")");
}
var cmd = new SQLiteCommand {
CommandText = string.Format("create table " + table + " ({0})", string.Join(", ", columnDefinition.ToArray()))
};
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
if (indices.Length >= 1 && (primary == null || indices.Length >= 2))
{
columnDefinition = new List<string>(primary != null ? indices.Length : indices.Length - 1); // reusing existing variable for laziness
uint i = 0;
foreach (IndexDefinition index in indices)
{
if (index.Type == IndexType.Primary || index.Fields.Length < 1)
{
continue;
}
i++;
columnDefinition.Add("CREATE " + (index.Type == IndexType.Unique ? "UNIQUE " : string.Empty) + "INDEX idx_" + table + "_" + i.ToString() + " ON " + table + "(" + string.Join(", ", index.Fields) + ")");
}
foreach (string query in columnDefinition)
{
cmd = new SQLiteCommand
{
CommandText = query
};
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
}
}
}
示例10: AddSchema
protected void AddSchema(string table, ColumnDefinition[] definitions, IndexDefinition[] indexes)
{
schema.Add(new SchemaDefinition(table, definitions, indexes));
}
示例11: UpdateTable
public override void UpdateTable(string table, ColumnDefinition[] columns)
{
if (!TableExists(table))
{
throw new DataManagerException("Trying to update a table with name of one that does not exist.");
}
List<ColumnDefinition> oldColumns = ExtractColumnsFromTable(table);
Dictionary<string, ColumnDefinition> sameColumns = new Dictionary<string, ColumnDefinition>();
foreach (ColumnDefinition column in oldColumns)
{
if (columns.Contains(column))
{
sameColumns.Add(column.Name, column);
}
}
string columnDefinition = string.Empty;
/*var primaryColumns = (from cd in columns where cd.IsPrimary == true select cd);
bool multiplePrimary = primaryColumns.Count() > 1;*/
string renamedTempTableColumnDefinition = string.Empty;
string renamedTempTableColumn = string.Empty;
foreach (ColumnDefinition column in oldColumns)
{
if (renamedTempTableColumnDefinition != string.Empty)
{
renamedTempTableColumnDefinition += ", ";
renamedTempTableColumn += ", ";
}
renamedTempTableColumn += column.Name;
renamedTempTableColumnDefinition += column.Name + " " + GetColumnTypeStringSymbol(column.Type);
}
string query = "CREATE TABLE " + table + "__temp(" + renamedTempTableColumnDefinition + ");";
var cmd = new SqliteCommand();
cmd.CommandText = query;
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
query = "INSERT INTO " + table + "__temp SELECT " + renamedTempTableColumn + " from " + table + ";";
cmd = new SqliteCommand();
cmd.CommandText = query;
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
query = "drop table " + table;
cmd = new SqliteCommand();
cmd.CommandText = query;
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
string newTableColumnDefinition = string.Empty;
List<ColumnDefinition> primaryColumns = new List<ColumnDefinition>();
foreach (ColumnDefinition column in columns)
{
if (column.IsPrimary) primaryColumns.Add(column);
}
bool multiplePrimary = primaryColumns.Count > 1;
foreach (ColumnDefinition column in columns)
{
if (newTableColumnDefinition != string.Empty)
{
newTableColumnDefinition += ", ";
}
newTableColumnDefinition += column.Name + " " + GetColumnTypeStringSymbol(column.Type) + ((column.IsPrimary && !multiplePrimary) ? " PRIMARY KEY" : string.Empty);
}
string multiplePrimaryString = string.Empty;
if (multiplePrimary)
{
string listOfPrimaryNamesString = string.Empty;
foreach (ColumnDefinition column in primaryColumns)
{
if (listOfPrimaryNamesString != string.Empty)
{
listOfPrimaryNamesString += ", ";
}
listOfPrimaryNamesString += column.Name;
}
multiplePrimaryString = string.Format(", PRIMARY KEY ({0}) ", listOfPrimaryNamesString);
}
query = string.Format("create table " + table + " ( {0} {1}) ", newTableColumnDefinition, multiplePrimaryString);
cmd = new SqliteCommand();
cmd.CommandText = query;
ExecuteNonQuery(cmd);
CloseReaderCommand(cmd);
string InsertFromTempTableColumnDefinition = string.Empty;
foreach (ColumnDefinition column in sameColumns.Values)
{
if (InsertFromTempTableColumnDefinition != string.Empty)
{
InsertFromTempTableColumnDefinition += ", ";
}
InsertFromTempTableColumnDefinition += column.Name;
}
//.........这里部分代码省略.........
示例12: UpdateTable
public override void UpdateTable(string table, ColumnDefinition[] columns, IndexDefinition[] indices, Dictionary<string, string> renameColumns)
{
table = table.ToLower();
if (!TableExists(table))
{
throw new DataManagerException("Trying to update a table with name of one that does not exist.");
}
List<ColumnDefinition> oldColumns = ExtractColumnsFromTable(table);
Dictionary<string, ColumnDefinition> removedColumns = new Dictionary<string, ColumnDefinition>();
Dictionary<string, ColumnDefinition> modifiedColumns = new Dictionary<string, ColumnDefinition>();
#if (!ISWIN)
Dictionary<string, ColumnDefinition> addedColumns = new Dictionary<string, ColumnDefinition>();
foreach (ColumnDefinition column in columns)
{
if (!oldColumns.Contains(column)) addedColumns.Add(column.Name.ToLower(), column);
}
foreach (ColumnDefinition column in oldColumns)
{
if (!columns.Contains(column))
{
if (addedColumns.ContainsKey(column.Name.ToLower()))
{
if (column.Name.ToLower() != addedColumns[column.Name.ToLower()].Name.ToLower() || column.Type != addedColumns[column.Name.ToLower()].Type)
{
modifiedColumns.Add(column.Name.ToLower(), addedColumns[column.Name.ToLower()]);
}
addedColumns.Remove(column.Name.ToLower());
}
else
{
removedColumns.Add(column.Name.ToLower(), column);
}
}
}
#else
Dictionary<string, ColumnDefinition> addedColumns = columns.Where(column => !oldColumns.Contains(column)).ToDictionary(column => column.Name.ToLower());
foreach (ColumnDefinition column in oldColumns.Where(column => !columns.Contains(column)))
{
if (addedColumns.ContainsKey(column.Name.ToLower()))
{
if (column.Name.ToLower() != addedColumns[column.Name.ToLower()].Name.ToLower() || column.Type != addedColumns[column.Name.ToLower()].Type)
{
modifiedColumns.Add(column.Name.ToLower(), addedColumns[column.Name.ToLower()]);
}
addedColumns.Remove(column.Name.ToLower());
}
else{
removedColumns.Add(column.Name.ToLower(), column);
}
}
#endif
try
{
#if (!ISWIN)
foreach (ColumnDefinition column in addedColumns.Values)
{
string addedColumnsQuery = "add `" + column.Name + "` " + GetColumnTypeStringSymbol(column.Type) + " ";
string query = string.Format("alter table " + table + " " + addedColumnsQuery);
ExecuteNonQuery(query, new Dictionary<string, object>());
}
foreach (ColumnDefinition column in modifiedColumns.Values)
{
string modifiedColumnsQuery = "modify column `" + column.Name + "` " + GetColumnTypeStringSymbol(column.Type) + " ";
string query = string.Format("alter table " + table + " " + modifiedColumnsQuery);
ExecuteNonQuery(query, new Dictionary<string, object>());
}
foreach (ColumnDefinition column in removedColumns.Values)
{
string droppedColumnsQuery = "drop `" + column.Name + "` ";
string query = string.Format("alter table " + table + " " + droppedColumnsQuery);
ExecuteNonQuery(query, new Dictionary<string, object>());
}
#else
foreach (string query in addedColumns.Values.Select(column => "add `" + column.Name + "` " + GetColumnTypeStringSymbol(column.Type) +
" ").Select(addedColumnsQuery => string.Format("alter table " + table + " " + addedColumnsQuery)))
{
ExecuteNonQuery(query, new Dictionary<string, object>());
}
foreach (string query in modifiedColumns.Values.Select(column => "modify column `" + column.Name + "` " +
GetColumnTypeStringSymbol(column.Type) + " ").Select(modifiedColumnsQuery => string.Format("alter table " + table + " " + modifiedColumnsQuery)))
{
ExecuteNonQuery(query, new Dictionary<string, object>());
}
foreach (string query in removedColumns.Values.Select(column => "drop `" + column.Name + "` ").Select(droppedColumnsQuery => string.Format("alter table " + table + " " + droppedColumnsQuery)))
{
ExecuteNonQuery(query, new Dictionary<string, object>());
}
#endif
}
catch (Exception e)
{
MainConsole.Instance.Error("[MySQLDataLoader] UpdateTable", e);
}
Dictionary<string, IndexDefinition> oldIndicesDict = ExtractIndicesFromTable(table);
//.........这里部分代码省略.........
示例13: CreateTable
public override void CreateTable(string table, ColumnDefinition[] columns, IndexDefinition[] indices)
{
table = table.ToLower();
if (TableExists(table))
{
throw new DataManagerException("Trying to create a table with name of one that already exists.");
}
IndexDefinition primary = null;
foreach (IndexDefinition index in indices)
{
if (index.Type == IndexType.Primary)
{
primary = index;
break;
}
}
List<string> columnDefinition = new List<string>();
foreach (ColumnDefinition column in columns)
{
columnDefinition.Add("`" + column.Name + "` " + GetColumnTypeStringSymbol(column.Type));
}
if (primary != null && primary.Fields.Length > 0)
{
columnDefinition.Add("PRIMARY KEY (`" + string.Join("`, `", primary.Fields) + "`)");
}
List<string> indicesQuery = new List<string>(indices.Length);
foreach (IndexDefinition index in indices)
{
string type = "KEY";
switch (index.Type)
{
case IndexType.Primary:
continue;
case IndexType.Unique:
type = "UNIQUE";
break;
case IndexType.Index:
default:
type = "KEY";
break;
}
indicesQuery.Add(string.Format("{0}( {1} )", type, "`" + string.Join("`, `", index.Fields) + "`"));
}
string query = string.Format("create table " + table + " ( {0} {1}) ", string.Join(", ", columnDefinition.ToArray()), indicesQuery.Count > 0 ? ", " + string.Join(", ", indicesQuery.ToArray()) : string.Empty);
try
{
ExecuteNonQuery(query, new Dictionary<string, object>());
}
catch (Exception e)
{
MainConsole.Instance.Error("[MySQLDataLoader] CreateTable", e);
}
}
示例14: UpdateTable
public override void UpdateTable(string table, ColumnDefinition[] columns)
{
table = table.ToLower();
if (!TableExists(table))
{
throw new DataManagerException("Trying to update a table with name of one that does not exist.");
}
List<ColumnDefinition> oldColumns = ExtractColumnsFromTable(table);
Dictionary<string, ColumnDefinition> addedColumns = new Dictionary<string, ColumnDefinition>();
Dictionary<string, ColumnDefinition> removedColumns = new Dictionary<string, ColumnDefinition>();
Dictionary<string, ColumnDefinition> modifiedColumns = new Dictionary<string, ColumnDefinition>();
foreach (ColumnDefinition column in columns)
{
if (!oldColumns.Contains(column))
{
addedColumns.Add(column.Name, column);
}
}
foreach (ColumnDefinition column in oldColumns)
{
if (!columns.Contains(column))
{
if (addedColumns.ContainsKey(column.Name))
{
modifiedColumns.Add(column.Name, addedColumns[column.Name]);
addedColumns.Remove(column.Name);
}
else
removedColumns.Add(column.Name, column);
}
}
string columnDefinition = string.Empty;
/*var primaryColumns = (from cd in columns where cd.IsPrimary == true select cd);
bool multiplePrimary = primaryColumns.Count() > 1;*/
string addedColumnsQuery = "";
string modifiedColumnsQuery = "";
string droppedColumnsQuery = "";
MySqlConnection dbcon = GetLockedConnection();
foreach (ColumnDefinition column in addedColumns.Values)
{
addedColumnsQuery = "add " + column.Name + " " + GetColumnTypeStringSymbol(column.Type) + " ";
string query = string.Format("alter table " + table + " " + addedColumnsQuery);
MySqlCommand dbcommand = dbcon.CreateCommand();
dbcommand.CommandText = query;
try
{
dbcommand.ExecuteNonQuery();
}
catch
{
}
}
foreach (ColumnDefinition column in modifiedColumns.Values)
{
modifiedColumnsQuery = "modify column " + column.Name + " " + GetColumnTypeStringSymbol(column.Type) + " ";
string query = string.Format("alter table " + table + " " + modifiedColumnsQuery);
MySqlCommand dbcommand = dbcon.CreateCommand();
dbcommand.CommandText = query;
try
{
dbcommand.ExecuteNonQuery();
}
catch
{
}
}
foreach (ColumnDefinition column in removedColumns.Values)
{
droppedColumnsQuery = "drop " + column.Name + " ";
string query = string.Format("alter table " + table + " " + droppedColumnsQuery);
MySqlCommand dbcommand = dbcon.CreateCommand();
dbcommand.CommandText = query;
try
{
dbcommand.ExecuteNonQuery();
}
catch
{
}
}
CloseDatabase(dbcon);
}
示例15: UpdateTable
public override void UpdateTable(string table, ColumnDefinition[] columns, IndexDefinition[] indices, Dictionary<string, string> renameColumns)
{
if (TableExists(table))
{
throw new DataManagerException("Trying to create a table with name of one that already exists.");
}
string columnDefinition = string.Empty;
foreach (ColumnDefinition column in columns)
{
if (columnDefinition != string.Empty)
{
columnDefinition += ", ";
}
columnDefinition += column.Name + " " + GetColumnTypeStringSymbol(column.Type);
}
string query = string.Format("create table " + table + " ( {0} {1}) ", columnDefinition, string.Empty);
SqlConnection dbcon = GetLockedConnection();
SqlCommand dbcommand = dbcon.CreateCommand();
dbcommand.CommandText = query;
dbcommand.ExecuteNonQuery();
CloseDatabase(dbcon);
}