Skip to content

Commit

Permalink
Escape column names always. Closes nhibernate#55
Browse files Browse the repository at this point in the history
Note: this will break anyone's code that is doing manual escaping, as it'll probably end up being double-escaped.
  • Loading branch information
jagregory committed Jan 7, 2010
1 parent 85f54bd commit c860199
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void MapsPropertyWithPropertyConvention()
.Conventions.Add<XXAppenderPropertyConvention>();

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("class/property[@name='LineOne']/column").HasAttribute("name", "LineOneXX");
.Element("class/property[@name='LineOne']/column").HasAttribute("name", "`LineOneXX`");
}

[Test]
Expand Down Expand Up @@ -117,7 +117,7 @@ public void OverrideShouldOverrideExistingProperty()
.Element("//property[@name='LineOne']")
.Exists()
.HasThisManyChildNodes(1)
.Element("//property[@name='LineOne']/column").HasAttribute("name", "test");
.Element("//property[@name='LineOne']/column").HasAttribute("name", "`test`");
}

[Test]
Expand All @@ -128,7 +128,7 @@ public void OverrideShouldOverrideExistingId()
.Override<ExampleClass>(c => c.Id(x => x.Id).Column("test"));

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("//id/column").HasAttribute("name", "test");
.Element("//id/column").HasAttribute("name", "`test`");
}

[Test]
Expand All @@ -140,7 +140,7 @@ public void OverrideShouldOverrideExistingComponent()
.Override<ExampleClass>(m => m.Component(x => x.Parent, c => c.Map(x => x.ExampleParentClassId).Column("test")));

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("//component[@name='Parent']/property[@name='ExampleParentClassId']/column").HasAttribute("name", "test");
.Element("//component[@name='Parent']/property[@name='ExampleParentClassId']/column").HasAttribute("name", "`test`");
}

[Test]
Expand Down Expand Up @@ -246,7 +246,7 @@ public void TestAutoMapPropertyMergeOverridesId()

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("class/id").HasAttribute("name", "Id")
.Element("class/id/column").HasAttribute("name", "Column");
.Element("class/id/column").HasAttribute("name", "`Column`");
}

[Test]
Expand All @@ -258,7 +258,7 @@ public void TestAutoMapPropertySetPrimaryKeyConvention()

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("class/id").HasAttribute("name", "Id")
.Element("class/id/column").HasAttribute("name", "IdId");
.Element("class/id/column").HasAttribute("name", "`IdId`");
}

[Test]
Expand All @@ -269,7 +269,7 @@ public void TestAutoMapIdUsesConvention()
.Conventions.Add(new TestIdConvention());

new AutoMappingTester<PrivateIdSetterClass>(autoMapper)
.Element("class/id/column").HasAttribute("name", "test");
.Element("class/id/column").HasAttribute("name", "`test`");
}

[Test]
Expand All @@ -280,7 +280,7 @@ public void AppliesConventionsToManyToOne()
.Conventions.Add(new TestM2OConvention());

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("//many-to-one/column").HasAttribute("name", "test");
.Element("//many-to-one/column").HasAttribute("name", "`test`");
}

[Test]
Expand All @@ -303,7 +303,7 @@ public void TestAutoMapPropertySetFindPrimaryKeyConvention()

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("class/id").HasAttribute("name", "ExampleClassId")
.Element("class/id/column").HasAttribute("name", "ExampleClassId");
.Element("class/id/column").HasAttribute("name", "`ExampleClassId`");
}

[Test]
Expand Down Expand Up @@ -587,7 +587,7 @@ public void ComponentPropertiesAssumeComponentColumnPrefix()
.Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures");

new AutoMappingTester<Customer>(autoMapper)
.Element("class/component[@name='WorkAddress']/property[@name='Number']/column").HasAttribute("name", "WorkAddress_Number");
.Element("class/component[@name='WorkAddress']/property[@name='Number']/column").HasAttribute("name", "`WorkAddress_Number`");
}

[Test]
Expand All @@ -606,7 +606,7 @@ public void ComponentColumnConventionReceivesProperty()

new AutoMappingTester<Customer>(autoMapper)
.Element("class/component[@name='WorkAddress']/property[@name='Number']/column")
.HasAttribute("name", value => value.StartsWith("WorkAddress_"));
.HasAttribute("name", value => value.StartsWith("`WorkAddress_"));
}

[Test]
Expand Down Expand Up @@ -675,7 +675,7 @@ public void JoinedSubclassOverrideShouldOverrideExistingProperty()
.Element("//joined-subclass/property[@name='ExampleProperty']")
.Exists()
.HasThisManyChildNodes(1)
.Element("//joined-subclass/property[@name='ExampleProperty']/column").HasAttribute("name", "test");
.Element("//joined-subclass/property[@name='ExampleProperty']/column").HasAttribute("name", "`test`");
}

[Test]
Expand All @@ -687,7 +687,7 @@ public void JoinedSubclassOverrideShouldOverrideExistingComponent()
.Override<ExampleInheritedClass>(m => m.Component(x => x.Component, c => c.Map(x => x.ExampleParentClassId).Column("test")));

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("//joined-subclass/component[@name='Component']/property[@name='ExampleParentClassId']/column").HasAttribute("name", "test");
.Element("//joined-subclass/component[@name='Component']/property[@name='ExampleParentClassId']/column").HasAttribute("name", "`test`");
}

[Test]
Expand Down Expand Up @@ -764,7 +764,7 @@ public void SubclassOverrideShouldOverrideExistingProperty()
.Element("//subclass/property[@name='ExampleProperty']")
.Exists()
.HasThisManyChildNodes(1)
.Element("//subclass/property[@name='ExampleProperty']/column").HasAttribute("name", "test");
.Element("//subclass/property[@name='ExampleProperty']/column").HasAttribute("name", "`test`");
}

[Test]
Expand All @@ -780,7 +780,7 @@ public void SubclassOverrideShouldOverrideExistingComponent()
.Override<ExampleInheritedClass>(m => m.Component(x => x.Component, c => c.Map(x => x.ExampleParentClassId).Column("test")));

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("//subclass/component[@name='Component']/property[@name='ExampleParentClassId']/column").HasAttribute("name", "test");
.Element("//subclass/component[@name='Component']/property[@name='ExampleParentClassId']/column").HasAttribute("name", "`test`");
}

[Test]
Expand Down Expand Up @@ -859,7 +859,7 @@ public void ShouldBeAbleToOverrideKeyColumnNameOfJoinedSubclassInConvention()

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("class/joined-subclass/key/column")
.HasAttribute("name", "test");
.HasAttribute("name", "`test`");
}

[Test]
Expand Down Expand Up @@ -909,7 +909,7 @@ public void ComponentHasManyShouldHavePrefixedKeyColumn()
});

new AutoMappingTester<ExampleClass>(autoMapper)
.Element("class/component/bag[@name='Examples']/key/column").HasAttribute("name", "Parent_ExampleParentClass_Id");
.Element("class/component/bag[@name='Examples']/key/column").HasAttribute("name", "`Parent_ExampleParentClass_Id`");
}

[Test]
Expand Down
14 changes: 7 additions & 7 deletions src/FluentNHibernate.Testing/AutoMapping/AutoMapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void AutoMapIdentification()
Test<ExampleClass>(mapping =>
{
mapping.Element("//id").HasAttribute("name", "Id");
mapping.Element("//id//column").HasAttribute("name", "Id");
mapping.Element("//id//column").HasAttribute("name", "`Id`");
});
}

Expand All @@ -30,7 +30,7 @@ public void AutoMapVersion()
Test<ExampleClass>(mapping =>
mapping
.Element("//version").HasAttribute("name", "Timestamp")
.Element("//version/column").HasAttribute("name", "Timestamp"));
.Element("//version/column").HasAttribute("name", "`Timestamp`"));
}

[Test]
Expand All @@ -40,7 +40,7 @@ public void AutoMapProperty()
model.Where(type => type == typeof(ExampleClass)));

Test<ExampleClass>(mapping =>
mapping.Element("//property[@name='LineOne']/column").HasAttribute("name", "LineOne"));
mapping.Element("//property[@name='LineOne']/column").HasAttribute("name", "`LineOne`"));
}

[Test]
Expand All @@ -51,7 +51,7 @@ public void AutoMapIgnoreProperty()
.Override<ExampleClass>(m => m.IgnoreProperty(x => x.LineOne)));

Test<ExampleClass>(mapping =>
mapping.Element("//property[@name='LineOne']").DoesntExist());
mapping.Element("//property[@name='`LineOne`']").DoesntExist());
}

[Test]
Expand All @@ -74,7 +74,7 @@ public void AutoMapManyToOne()

Test<ExampleClass>(mapping =>
mapping.Element("//many-to-one").HasAttribute("name", "Parent")
.Element("//many-to-one/column").HasAttribute("name", "Parent_id"));
.Element("//many-to-one/column").HasAttribute("name", "`Parent_id`"));
}

[Test]
Expand All @@ -84,7 +84,7 @@ public void AutoMapManyToMany()
model.Where(type => type == typeof(ManyToMany1)));

Test<ManyToMany1>(mapping =>
mapping.Element("//many-to-many/column").HasAttribute("name", "ManyToMany2_id"));
mapping.Element("//many-to-many/column").HasAttribute("name", "`ManyToMany2_id`"));
}

[Test]
Expand Down Expand Up @@ -136,7 +136,7 @@ public void ShouldAutoMapBitmapPropertyAsColumn()
model.Where(type => type == typeof(ClassWithBitmap)));

Test<ClassWithBitmap>(mapping =>
mapping.Element("//property[@name='Bitmap']/column").HasAttribute("name", "Bitmap"));
mapping.Element("//property[@name='Bitmap']/column").HasAttribute("name", "`Bitmap`"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void DefaultConventionsAreAppliedToJoinedSubClasses()
AutoMap.AssemblyOf<SuperType>()
.Where(x => x.Namespace == typeof(SuperType).Namespace))
.Element("class/joined-subclass[@name='" + typeof(ExampleClass).AssemblyQualifiedName + "']/many-to-one/column")
.HasAttribute("name", "Parent_id");
.HasAttribute("name", "`Parent_id`");
}
}
}
4 changes: 2 additions & 2 deletions src/FluentNHibernate.Testing/AutoMapping/VersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public void PropertyNamedTimestampMappedAsVersion()
{
VerifyAutoMap<ValidTimestampClass>()
.Element("//version").HasAttribute("name", "Timestamp")
.Element("//version/column").HasAttribute("name", "Timestamp");
.Element("//version/column").HasAttribute("name", "`Timestamp`");
}

[Test]
public void PropertyNamedVersionMappedAsVersion()
{
VerifyAutoMap<ValidVersionClass>()
.Element("//version").HasAttribute("name", "Version")
.Element("//version/column").HasAttribute("name", "Version");
.Element("//version/column").HasAttribute("name", "`Version`");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ShouldUseEndsWithConventionForReferencesForeignKey()
new MappingTester<ExampleClass>()
.Conventions(x => x.Add(ForeignKey.EndsWith("Woo")))
.ForMapping(m => m.References(x => x.Parent))
.Element("class/many-to-one/column").HasAttribute("name", "ParentWoo");
.Element("class/many-to-one/column").HasAttribute("name", "`ParentWoo`");
}

[Test]
Expand All @@ -26,7 +26,7 @@ public void ShouldUseFuncConventionForReferencesForeignKey()
new MappingTester<ExampleClass>()
.Conventions(x => x.Add(ForeignKey.Format((p,t) => p.Name + "Woo")))
.ForMapping(m => m.References(x => x.Parent))
.Element("class/many-to-one/column").HasAttribute("name", "ParentWoo");
.Element("class/many-to-one/column").HasAttribute("name", "`ParentWoo`");
}

[Test]
Expand All @@ -35,7 +35,7 @@ public void ShouldUseEndsWithConventionForHasManyForeignKey()
new MappingTester<OneToManyTarget>()
.Conventions(x => x.Add(ForeignKey.EndsWith("Woo")))
.ForMapping(m => m.HasMany(x => x.BagOfChildren))
.Element("class/bag/key/column").HasAttribute("name", "OneToManyTargetWoo");
.Element("class/bag/key/column").HasAttribute("name", "`OneToManyTargetWoo`");
}

[Test]
Expand All @@ -44,7 +44,7 @@ public void ShouldUseFuncConventionForHasManyForeignKey()
new MappingTester<OneToManyTarget>()
.Conventions(x => x.Add(ForeignKey.Format((p, t) => t.Name + "Woo")))
.ForMapping(m => m.HasMany(x => x.BagOfChildren))
.Element("class/bag/key/column").HasAttribute("name", "OneToManyTargetWoo");
.Element("class/bag/key/column").HasAttribute("name", "`OneToManyTargetWoo`");
}

[Test]
Expand All @@ -53,8 +53,8 @@ public void ShouldUseEndsWithConventionForHasManyToManyForeignKey()
new MappingTester<OneToManyTarget>()
.Conventions(x => x.Add(ForeignKey.EndsWith("Woo")))
.ForMapping(m => m.HasManyToMany(x => x.BagOfChildren))
.Element("class/bag/key/column").HasAttribute("name", "OneToManyTargetWoo")
.Element("class/bag/many-to-many/column").HasAttribute("name", "ChildObjectWoo");
.Element("class/bag/key/column").HasAttribute("name", "`OneToManyTargetWoo`")
.Element("class/bag/many-to-many/column").HasAttribute("name", "`ChildObjectWoo`");
}

[Test]
Expand All @@ -63,8 +63,8 @@ public void ShouldUseFuncConventionForHasManyToManyForeignKey()
new MappingTester<OneToManyTarget>()
.Conventions(x => x.Add(ForeignKey.Format((p, t) => t.Name + "Woo")))
.ForMapping(m => m.HasManyToMany(x => x.BagOfChildren))
.Element("class/bag/key/column").HasAttribute("name", "OneToManyTargetWoo")
.Element("class/bag/many-to-many/column").HasAttribute("name", "ChildObjectWoo");
.Element("class/bag/key/column").HasAttribute("name", "`OneToManyTargetWoo`")
.Element("class/bag/many-to-many/column").HasAttribute("name", "`ChildObjectWoo`");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public void CanApplySameInstanceToMultipleParts()
m.Id(x => x.Id);
m.Map(x => x.LineOne);
})
.Element("class/id/column").HasAttribute("name", "id-col")
.Element("class/property[@name='LineOne']/column").HasAttribute("name", "prop-col");
.Element("class/id/column").HasAttribute("name", "`id-col`")
.Element("class/property[@name='LineOne']/column").HasAttribute("name", "`prop-col`");
}

private class CustomConvention : IIdConvention, IPropertyConvention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void EntityTypeColumnWritesBeforeEntityIdColumn()
.EntityTypeColumn("AnyType")
.IdentityType(x => x.Id))
.Element("class/any/column")
.HasAttribute("name", "AnyType")
.HasAttribute("name", "`AnyType`")
.ShouldBeInParentAtPosition(0);
}

Expand Down
Loading

0 comments on commit c860199

Please sign in to comment.