/// <summary> /// /// </summary> private void BuildUpdateCommand() { ScriptBuilder.Append("UPDATE "); ScriptBuilder.AppendFormat(Table.ToString()); ScriptBuilder.Append(" SET "); foreach (var column in Table.GetAdditionalColumns()) { ScriptBuilder.Append(column.Name); ScriptBuilder.Append(Strings.Equal); ScriptBuilder.Append($"@{column.Name}"); ScriptBuilder.AppendIf(Columns.IsNotLast(column), Strings.Comma); ScriptBuilder.Append(Strings.WhiteSpace); } var primaryColumn = Table.GetPrimaryColumnName(); ScriptBuilder.Append("WHERE "); ScriptBuilder.Append(primaryColumn); ScriptBuilder.Append(Strings.Equal); ScriptBuilder.Append($"@{primaryColumn}"); ScriptBuilder.AppendLine(); ScriptBuilder.AppendLine("ELSE"); }
/// <summary> /// /// </summary> /// <param name="column"></param> private void BuildUpdateSet(ColumnInfo column) { ScriptBuilder.Append(column.GetPgSqlName()); ScriptBuilder.Append(" = "); ScriptBuilder.Append($"@{column.Name}"); ScriptBuilder.AppendIf(Columns.IsNotLast(column), Strings.Comma); ScriptBuilder.Append(Strings.WhiteSpace); }
/// <summary> /// /// </summary> /// <param name="column"></param> private void BuildColumn(ColumnInfo column) { ScriptBuilder.AppendLine(); ScriptBuilder.Append($"{column.GetPgSqlName()} "); ScriptBuilder.Append(column.Type.GetColumnType()); BuildNullableInfo(column); BuildPrimaryKeyAndIdentity(column); ScriptBuilder.AppendIf(Columns.IsNotLast(column), Strings.Comma); }
/// <summary> /// /// </summary> /// <param name="column"></param> private void BuildColumn(ColumnInfo column) { ScriptBuilder.AppendLine(); ScriptBuilder.Append($"{column.GetSqlName()} "); ScriptBuilder.Append(column.Type.GetColumnType()); BuildIdentity(column); BuildNullableInfo(column); ScriptBuilder.AppendIf(column.IsPrimary(), " PRIMARY KEY"); ScriptBuilder.Append(Strings.Comma); }
/// <summary> /// /// </summary> protected void BuildMultipleColumnUnique() { ScriptBuilder.AppendLine($"ALTER TABLE {Table.GetPgSqlName()}"); ScriptBuilder.Append($"ADD CONSTRAINT {UniqueName} UNIQUE ("); foreach (var column in UniqueColumns) { ScriptBuilder.Append(column.GetPgSqlName()); ScriptBuilder.AppendIf(UniqueColumns.IsNotLast(column), " ,"); } ScriptBuilder.Append(");"); }
/// <summary> /// /// </summary> /// <param name="column"></param> private void BuildColumn(ColumnInfo column) { ScriptBuilder.AppendLine(); ScriptBuilder.Append($"{column.GetMySqlName()} "); ScriptBuilder.Append(column.Type.GetColumnType()); if (column.Identity != null) { ScriptBuilder.Append(" AUTO_INCREMENT"); } BuildNullableInfo(column); ScriptBuilder.Append($" COMMENT '{column.Description}'"); ScriptBuilder.AppendIf(Columns.IsNotLast(column), Strings.Comma); }
/// <summary> /// /// </summary> /// <param name="column"></param> private void BuildPrimaryKeyAndIdentity(ColumnInfo column) { ScriptBuilder.AppendIf(column.IsPrimary(), " PRIMARY KEY"); if (column.Identity == null) { return; } ScriptBuilder.Append($" DEFAULT nextval('\"{GetSequenceName()}\"')"); var scriptBuilder = new StringBuilder(); scriptBuilder.AppendLine($"CREATE SEQUENCE \"{GetSequenceName()}\";"); scriptBuilder.AppendLine(); scriptBuilder.Append(ScriptBuilder); ScriptBuilder = scriptBuilder; }
/// <summary> /// /// </summary> private void BuildInsertCommand() { ScriptBuilder.Append("INSERT INTO "); ScriptBuilder.AppendFormat(Table.ToString()); ScriptBuilder.Append(Strings.LBracket); foreach (var column in Columns) { ScriptBuilder.Append(column.Name); ScriptBuilder.AppendIf(Columns.IsNotLast(column), ", "); } ScriptBuilder.AppendLine(Strings.RBracket); ScriptBuilder.Append("VALUES("); foreach (var column in Columns) { ScriptBuilder.Append($"@{column.Name}"); ScriptBuilder.AppendIf(Columns.IsNotLast(column), ", "); } ScriptBuilder.Append(Strings.RBracket); ScriptBuilder.Append(Strings.Semicolon); }
/// <summary> /// /// </summary> /// <param name="column"></param> private void BuildValue(ColumnInfo column) { ScriptBuilder.Append($"@{column.Name}"); ScriptBuilder.AppendIf(Columns.IsNotLast(column), ", "); }
/// <summary> /// /// </summary> private void BuildColumn(ColumnInfo column) { ScriptBuilder.Append(column.GetPgSqlName()); ScriptBuilder.AppendIf(Columns.IsNotLast(column), ", "); }
/// <summary> /// /// </summary> protected void SetColumnInfo() { ScriptBuilder.Append($" {Column.GetSqlName()} {Column.Type.GetColumnType()}"); ScriptBuilder.AppendIf(!Column.IsAllowNull, " NOT"); ScriptBuilder.Append(" NULL"); }
/// <summary> /// /// </summary> /// <param name="column"></param> private void BuildNullableInfo(ColumnInfo column) { ScriptBuilder.AppendIf(!column.IsAllowNull, " NOT"); ScriptBuilder.Append(" NULL"); }