public virtual void AddColumn(DatabaseOperationArgs args, DiscoveredTable table, string name, string dataType, bool allowNulls) { var syntax = table.GetQuerySyntaxHelper(); using (var con = args.GetManagedConnection(table)) { using (var cmd = table.Database.Server.GetCommand("ALTER TABLE " + table.GetFullyQualifiedName() + " ADD " + syntax.EnsureWrapped(name) + " " + dataType + " " + (allowNulls ? "NULL" : "NOT NULL"), con)) args.ExecuteNonQuery(cmd); } }
public virtual void RenameTable(DiscoveredTable discoveredTable, string newName, IManagedConnection connection) { if (discoveredTable.TableType != TableType.Table) { throw new NotSupportedException(string.Format(FAnsiStrings.DiscoveredTableHelper_RenameTable_Rename_is_not_supported_for_TableType__0_, discoveredTable.TableType)); } discoveredTable.GetQuerySyntaxHelper().ValidateTableName(newName); using (DbCommand cmd = discoveredTable.Database.Server.Helper.GetCommand(GetRenameTableSql(discoveredTable, newName), connection.Connection, connection.Transaction)) cmd.ExecuteNonQuery(); }
public virtual void CreatePrimaryKey(DatabaseOperationArgs args, DiscoveredTable table, DiscoveredColumn[] discoverColumns) { var syntax = table.GetQuerySyntaxHelper(); using (var connection = args.GetManagedConnection(table)) { try{ string sql = string.Format("ALTER TABLE {0} ADD PRIMARY KEY ({1})", table.GetFullyQualifiedName(), string.Join(",", discoverColumns.Select(c => syntax.EnsureWrapped(c.GetRuntimeName()))) ); using (DbCommand cmd = table.Database.Server.Helper.GetCommand(sql, connection.Connection, connection.Transaction)) args.ExecuteNonQuery(cmd); } catch (Exception e) { throw new AlterFailedException(string.Format(FAnsiStrings.DiscoveredTableHelper_CreatePrimaryKey_Failed_to_create_primary_key_on_table__0__using_columns___1__, table, string.Join(",", discoverColumns.Select(c => c.GetRuntimeName()))), e); } } }