示例#1
0
        /// <summary>
        /// Generates the SQL string to create this Index in the database.
        /// </summary>
        /// <param name="dialect">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
        /// <param name="p"></param>
        /// <param name="defaultSchema"></param>
        /// <returns>
        /// A string that contains the SQL to create this Index.
        /// </returns>
        public string SqlCreateString(Dialect.Dialect dialect, IMapping p, string defaultSchema)
        {
            // TODO: NH-421
            StringBuilder buf = new StringBuilder("create index ")
                                .Append(dialect.QualifyIndexName ? name : StringHelper.Unqualify(name))
                                .Append(" on ")
                                .Append(table.GetQualifiedName(dialect))
                                .Append(" (");

            bool commaNeeded = false;

            for (int i = 0; i < columns.Count; i++)
            {
                if (commaNeeded)
                {
                    buf.Append(StringHelper.CommaSpace);
                }
                commaNeeded = true;

                buf.Append((( Column )columns[i]).GetQuotedName(dialect));
            }

            buf.Append(StringHelper.ClosedParen);
            return(buf.ToString());
        }
        public void QuotedTableNameWithoutSchemaWithSqlLite()
        {
            Table tbl = new Table();
            tbl.Name = "`name`";

            Assert.AreEqual("\"name\"", tbl.GetQualifiedName(dialect));
        }
示例#3
0
        /// <summary>
        /// Generates the SQL string to create the named Foreign 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="defaultSchema"></param>
        /// <param name="defaultCatalog"></param>
        /// <returns>
        /// A string that contains the SQL to create the named Foreign Key Constraint.
        /// </returns>
        public override string SqlConstraintString(Dialect.Dialect d, string constraintName, string defaultCatalog, string defaultSchema)
        {
            string[]             cols    = new string[ColumnSpan];
            string[]             refcols = new string[ColumnSpan];
            int                  i       = 0;
            IEnumerable <Column> refiter;

            if (IsReferenceToPrimaryKey)
            {
                refiter = referencedTable.PrimaryKey.ColumnIterator;
            }
            else
            {
                refiter = referencedColumns;
            }
            foreach (Column column in ColumnIterator)
            {
                cols[i] = column.GetQuotedName(d);
                i++;
            }

            i = 0;
            foreach (Column column in refiter)
            {
                refcols[i] = column.GetQuotedName(d);
                i++;
            }
            string result = d.GetAddForeignKeyConstraintString(constraintName, cols, referencedTable.GetQualifiedName(d, defaultCatalog, defaultSchema), refcols, IsReferenceToPrimaryKey);

            return(cascadeDeleteEnabled && d.SupportsCascadeDelete ? result + " on delete cascade" : result);
        }
        public void QuotedTableNameWithSqlLite()
        {
            Table tbl = new Table();
            tbl.Name = "`Group`";

            Assert.AreEqual("\"Group\"", tbl.GetQualifiedName(dialect));
        }
示例#5
0
        public static string BuildSqlCreateIndexString(Dialect.Dialect dialect, string name, Table table,
                                                       IEnumerable <Column> columns, bool unique, string defaultCatalog, string defaultSchema)
        {
            //TODO handle supportsNotNullUnique=false, but such a case does not exist in the wild so far
            StringBuilder buf = new StringBuilder("create")
                                .Append(unique ? " unique" : "")
                                .Append(" index ")
                                .Append(dialect.QualifyIndexName ? name : StringHelper.Unqualify(name))
                                .Append(" on ")
                                .Append(table.GetQualifiedName(dialect, defaultCatalog, defaultSchema))
                                .Append(" (");
            bool commaNeeded = false;

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

                buf.Append(column.GetQuotedName(dialect));
            }
            buf.Append(")");

            return(buf.ToString());
        }
示例#6
0
		public static string BuildSqlDropIndexString(Dialect.Dialect dialect, Table table, string name, string defaultCatalog, string defaultSchema)
		{
			string ifExists = dialect.GetIfExistsDropConstraint(table, name);
			string drop = string.Format("drop index {0}", StringHelper.Qualify(table.GetQualifiedName(dialect, defaultCatalog, defaultSchema), name));
			string end = dialect.GetIfExistsDropConstraintEnd(table, name);
			return ifExists + Environment.NewLine + drop + Environment.NewLine + end;
		}
示例#7
0
        /// <summary>
        /// Get the SQL string to drop this Constraint in the database.
        /// </summary>
        /// <param name="dialect">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
        /// <param name="defaultCatalog"></param>
        /// <param name="defaultSchema"></param>
        /// <returns>
        /// A string that contains the SQL to drop this Constraint.
        /// </returns>
        public override string SqlDropString(Dialect.Dialect dialect, string defaultCatalog, string defaultSchema)
        {
            string ifExists = dialect.GetIfExistsDropConstraint(Table, Name);
            string drop     = string.Format("alter table {0}{1}", Table.GetQualifiedName(dialect, defaultCatalog, defaultSchema), dialect.GetDropPrimaryKeyConstraintString(Name));
            string end      = dialect.GetIfExistsDropConstraintEnd(Table, Name);

            return(ifExists + Environment.NewLine + drop + Environment.NewLine + end);
        }
		public void TableNameNotQuoted() 
		{
			Table tbl = new Table();
			tbl.Name = "notkeyword";

			Dialect.Dialect dialect = new Dialect.MsSql2000Dialect();

			Assert.AreEqual( "notkeyword", tbl.GetQuotedName( dialect ) );

			Assert.AreEqual( "dbo.notkeyword", tbl.GetQualifiedName( dialect, "dbo" ) );

			Assert.AreEqual( "notkeyword", tbl.GetQualifiedName( dialect, null ) );

			tbl.Schema = "sch";

			Assert.AreEqual( "sch.notkeyword", tbl.GetQualifiedName( dialect ) );
		}
		public void TableNameQuoted()
		{
			Table tbl = new Table();
			tbl.Name = "`keyword`";

			Dialect.Dialect dialect = new MsSql2000Dialect();

			Assert.AreEqual("[keyword]", tbl.GetQuotedName(dialect));

			Assert.AreEqual("dbo.[keyword]", tbl.GetQualifiedName(dialect, null, "dbo"));

			Assert.AreEqual("[keyword]", tbl.GetQualifiedName(dialect, null, null));

			tbl.Schema = "sch";

			Assert.AreEqual("sch.[keyword]", tbl.GetQualifiedName(dialect));
		}
示例#10
0
        public static string BuildSqlDropIndexString(Dialect.Dialect dialect, Table table, string name, string defaultCatalog, string defaultSchema)
        {
            string ifExists = dialect.GetIfExistsDropConstraint(table, name);
            string drop     = string.Format("drop index {0}", StringHelper.Qualify(table.GetQualifiedName(dialect, defaultCatalog, defaultSchema), name));
            string end      = dialect.GetIfExistsDropConstraintEnd(table, name);

            return(ifExists + Environment.NewLine + drop + Environment.NewLine + end);
        }
        public void QuotedSchemaNameWithUnqoutedTableInSqlLite()
        {
            Table tbl = new Table();
            tbl.Schema = "`schema`";
            tbl.Name = "name";

            Assert.AreEqual("\"schema_name\"", tbl.GetQualifiedName(dialect));
            Assert.AreEqual("\"schema_table\"", dialect.Qualify("", "\"schema\"", "table"));
        }
		public void SchemaNameQuoted()
		{
			Table tbl = new Table();
			tbl.Schema = "`schema`";
			tbl.Name = "name";

			Dialect.Dialect dialect = new Dialect.MsSql2000Dialect();

			Assert.AreEqual( "[schema].name", tbl.GetQualifiedName( dialect ) );
		}
        public void QuotedCatalogSchemaNameWithSqlLite()
        {
            Table tbl = new Table();
            tbl.Catalog = "dbo";
            tbl.Schema = "`schema`";
            tbl.Name = "`name`";

            Assert.AreEqual("\"dbo_schema_name\"", tbl.GetQualifiedName(dialect));
            Assert.AreEqual("\"dbo_schema_table\"", dialect.Qualify("dbo", "\"schema\"", "\"table\""));
        }
示例#14
0
        public static string BuildSqlDropIndexString(Dialect.Dialect dialect, Table table, string name, string defaultCatalog, string defaultSchema)
        {
            var catalog   = table.GetQuotedCatalog(dialect, defaultCatalog);
            var schema    = table.GetQuotedSchema(dialect, defaultSchema);
            var tableName = table.GetQuotedName(dialect);

            return(new StringBuilder()
                   .AppendLine(dialect.GetIfExistsDropConstraint(catalog, schema, tableName, name))
                   .Append("drop index ")
                   .AppendLine(StringHelper.Qualify(table.GetQualifiedName(dialect, defaultCatalog, defaultSchema), name))
                   .Append(dialect.GetIfExistsDropConstraintEnd(catalog, schema, tableName, name))
                   .ToString());
        }
示例#15
0
        /// <summary>
        /// Get the SQL string to drop this Constraint in the database.
        /// </summary>
        /// <param name="dialect">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
        /// <param name="defaultCatalog"></param>
        /// <param name="defaultSchema"></param>
        /// <returns>
        /// A string that contains the SQL to drop this Constraint.
        /// </returns>
        public override string SqlDropString(Dialect.Dialect dialect, string defaultCatalog, string defaultSchema)
        {
            var catalog   = Table.GetQuotedCatalog(dialect, defaultCatalog);
            var schema    = Table.GetQuotedSchema(dialect, defaultSchema);
            var tableName = Table.GetQuotedName(dialect);

            return(new StringBuilder()
                   .AppendLine(dialect.GetIfExistsDropConstraint(catalog, schema, tableName, Name))
                   .Append("alter table ")
                   .Append(Table.GetQualifiedName(dialect, defaultCatalog, defaultSchema))
                   .AppendLine(dialect.GetDropPrimaryKeyConstraintString(Name))
                   .Append(dialect.GetIfExistsDropConstraintEnd(catalog, schema, tableName, Name))
                   .ToString());
        }
示例#16
0
        /// <summary>
        /// Generates the SQL string to create the named Foreign 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="defaultSchema"></param>
        /// <returns>
        /// A string that contains the SQL to create the named Foreign Key Constraint.
        /// </returns>
        public override string SqlConstraintString(Dialect.Dialect d, string constraintName, string defaultSchema)
        {
            string[] cols    = new string[ColumnSpan];
            string[] refcols = new string[ColumnSpan];
            int      i       = 0;

            foreach (Column col in referencedTable.PrimaryKey.ColumnCollection)
            {
                refcols[i] = col.GetQuotedName(d);
                i++;
            }

            i = 0;
            foreach (Column col in ColumnCollection)
            {
                cols[i] = col.GetQuotedName(d);
                i++;
            }

            return(d.GetAddForeignKeyConstraintString(constraintName, cols, referencedTable.GetQualifiedName(d, defaultSchema), refcols));
        }
示例#17
0
		public static string BuildSqlCreateIndexString(Dialect.Dialect dialect, string name, Table table,
			IEnumerable<Column> columns, bool unique, string defaultCatalog, string defaultSchema)
		{
			//TODO handle supportsNotNullUnique=false, but such a case does not exist in the wild so far
			StringBuilder buf = new StringBuilder("create")
				.Append(unique ? " unique" : "")
				.Append(" index ")
				.Append(dialect.QualifyIndexName ? name : StringHelper.Unqualify(name))
				.Append(" on ")
				.Append(table.GetQualifiedName(dialect, defaultCatalog, defaultSchema))
				.Append(" (");
			bool commaNeeded = false;
			foreach (Column column in columns)
			{
				if (commaNeeded)
					buf.Append(StringHelper.CommaSpace);
				commaNeeded = true;

				buf.Append(column.GetQuotedName(dialect));
			}
			buf.Append(")");

			return buf.ToString();
		}
        public void SchemaNameWithSqlLite()
        {
            Table tbl = new Table();
            tbl.Schema = "schema";
            tbl.Name = "name";

            Assert.AreEqual("schema_name", tbl.GetQualifiedName(dialect));
            Assert.AreEqual("schema_table", dialect.Qualify("", "schema", "table"));
        }
示例#19
0
 /// <summary>
 /// Get the SQL string to drop this Constraint in the database.
 /// </summary>
 /// <param name="dialect">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
 /// <param name="defaultSchema"></param>
 /// <returns>
 /// A string that contains the SQL to drop this Constraint.
 /// </returns>
 public override string SqlDropString(NHibernate.Dialect.Dialect dialect, string defaultSchema)
 {
     // TODO: NH-421
     return(string.Format("alter table {0} {1}", Table.GetQualifiedName(dialect, defaultSchema), dialect.GetDropForeignKeyConstraintString(Name)));
 }
示例#20
0
 /// <summary>
 /// Get the SQL string to drop this Constraint in the database.
 /// </summary>
 /// <param name="dialect">The <see cref="Dialect.Dialect"/> to use for SQL rules.</param>
 /// <param name="defaultSchema"></param>
 /// <returns>
 /// A string that contains the SQL to drop this Constraint.
 /// </returns>
 public override string SqlDropString(NHibernate.Dialect.Dialect dialect, string defaultSchema)
 {
     // TODO: NH-421
     return("alter table " + Table.GetQualifiedName(dialect, defaultSchema) + dialect.GetDropIndexConstraintString(Name));
 }