Esempio n. 1
0
        /// <summary>
        /// Generates the SQL string to create the Unique Key Constraint in the database.
        /// </summary>
        /// <param name="dialect">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
        /// <param name="constraintName"></param>
        /// <param name="defaultCatalog"></param>
        /// <param name="defaultSchema"></param>
        /// <returns>
        /// A string that contains the SQL to create the Unique Key Constraint.
        /// </returns>
        public override string SqlConstraintString(Dialect.Dialect dialect, string constraintName, string defaultCatalog, string defaultSchema)
        {
            StringBuilder buf = new StringBuilder(dialect.GetAddPrimaryKeyConstraintString(constraintName))
                                .Append(StringHelper.OpenParen);

            bool commaNeeded = false;
            bool nullable    = false;

            foreach (Column column in ColumnIterator)
            {
                if (!nullable && column.IsNullable)
                {
                    nullable = true;
                }
                if (commaNeeded)
                {
                    buf.Append(StringHelper.CommaSpace);
                }
                commaNeeded = true;
                buf.Append(column.GetQuotedName(dialect));
            }

            return
                (!nullable || dialect.SupportsNotNullUnique
                                        ? StringHelper.Replace(buf.Append(StringHelper.ClosedParen).ToString(), "primary key", "unique")
                                        : null);
        }
Esempio n. 2
0
        /// <summary>
        /// Generates the SQL string to create the named Primary Key Constraint in the database.
        /// </summary>
        /// <param name="d">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
        /// <param name="constraintName">The name to use as the identifier of the constraint in the database.</param>
        /// <param name="defaultCatalog"></param>
        /// <param name="defaultSchema"></param>
        /// <returns>
        /// A string that contains the SQL to create the named Primary Key Constraint.
        /// </returns>
        public override string SqlConstraintString(Dialect.Dialect d, string constraintName, string defaultCatalog, string defaultSchema)
        {
            StringBuilder buf = new StringBuilder(
                d.GetAddPrimaryKeyConstraintString(constraintName))
                                .Append('(');
            int i = 0;

            foreach (Column col in ColumnIterator)
            {
                buf.Append(col.GetQuotedName(d));
                if (i < ColumnSpan - 1)
                {
                    buf.Append(StringHelper.CommaSpace);
                }
                i++;
            }
            return(buf.Append(StringHelper.ClosedParen).ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Generates the SQL string to create the Unique Key Constraint in the database.
        /// </summary>
        /// <param name="d">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
        /// <param name="constraintName"></param>
        /// <param name="defaultSchema"></param>
        /// <returns>
        /// A string that contains the SQL to create the Unique Key Constraint.
        /// </returns>
        public override string SqlConstraintString(Dialect.Dialect d, string constraintName, string defaultSchema)
        {
            StringBuilder buf = new StringBuilder(
                d.GetAddPrimaryKeyConstraintString(constraintName))
                                .Append('(');

            bool commaNeeded = false;

            foreach (Column col in ColumnCollection)
            {
                if (commaNeeded)
                {
                    buf.Append(StringHelper.CommaSpace);
                }
                commaNeeded = true;

                buf.Append(col.GetQuotedName(d));
            }

            return(StringHelper.Replace(buf.Append(StringHelper.ClosedParen).ToString(), "primary key", "unique"));
        }