Пример #1
0
        /// <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);
        }
Пример #3
0
        /// <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);
        }
Пример #5
0
        /// <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(");");
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
        /// <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;
        }
Пример #8
0
        /// <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), ", ");
 }
Пример #11
0
 /// <summary>
 ///
 /// </summary>
 protected void SetColumnInfo()
 {
     ScriptBuilder.Append($" {Column.GetSqlName()} {Column.Type.GetColumnType()}");
     ScriptBuilder.AppendIf(!Column.IsAllowNull, " NOT");
     ScriptBuilder.Append(" NULL");
 }
Пример #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="column"></param>
 private void BuildNullableInfo(ColumnInfo column)
 {
     ScriptBuilder.AppendIf(!column.IsAllowNull, " NOT");
     ScriptBuilder.Append(" NULL");
 }