My favorites | Sign in
Project Logo
       
New issue | Search
for
| Advanced search | Search tips
Issue 55: Bug: Escaped column names
1 person starred this issue and may be notified of changes. Back to list
Status:  Accepted
Owner:  ----
Type-Defect
Priority-Medium


Sign in to add a comment
 
Reported by agr...@therightstuff.de, Oct 14, 2008
When using a ClassMap Fluent NH wraps the table name in square brackets by
default. This breaks NH SchemaUpdate because SchemaUpdates searches for
existing tables using the wrapped name as is.

That is, a class Foo will be mapped as <class name="Foo" table="[Foo]"
xmlns="...">. The schema updater will later try to find a table named
"[Foo]" which is not available (whereas "Foo" is).

An example query, logged with SQL Server Profiler:
exec sp_executesql
N'select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE from
INFORMATION_SCHEMA.TABLES where (TABLE_CATALOG = @Catalog or (@Catalog is
null)) and (TABLE_SCHEMA = @Owner or (@Owner is null)) and (TABLE_NAME =
@Name or (@Name is null)) and (TABLE_TYPE = @TableType or (@TableType is
null))',
N'@Catalog nvarchar(4000),@Owner nvarchar(4000),@Name
nvarchar(6),@TableType nvarchar(4000)',
@Catalog=NULL,
@Owner=NULL,
@Name=N'[Foo]', <-- square brackets
@TableType=NULL

Please note that I'm a NH beginner, and I'm note sure if this is a problem
in NH ider FNH. However, when I changed ClassMap such that tables will be
wrapped in `TableName` the problem went away.

Comment 1 by jagregory.com, Oct 15, 2008
The way fluent-nhib's tables are escaped was a hack, I believe. The backtick is the 
correct method for escaping tables in NHibernate, so we should really use that 
method.
Status: Accepted
Comment 2 by agr...@therightstuff.de, Oct 22, 2008
I've attached a patch.
Backticks.patch
1.2 KB   Download
Comment 3 by agr...@therightstuff.de, Nov 02, 2008
Please review the updated patch (which is attached). It makes sure that not only
table names are escaped, but also column names. If you are aware of other attributes
that may require escaping, please add them to to the list of attributes in
StringExtensions.cs.
EscapeTablesAndColumnNames.patch
28.8 KB   Download
Comment 4 by paul.batum, Dec 14, 2008
(No comment was entered for this change.)
Summary: Escaped column names
Comment 5 by jagregory.com, Jan 03, 2009
I believe this has been implemented, please reopen if this is not the case.
Status: Fixed
Comment 6 by agr...@therightstuff.de, Jan 04, 2009
This has been implemented for table names, but not for column names in the current
trunk. The fix should be an easy one using EscapeTablesAndColumnNames.patch. Since
that patch has been generated for an older version of the trunk there might be some
additional work involved (like adjusting new tests), but I have been using it along
with some other refinements without having any problems.

Given the things I said above, do I have to do anything else to re-open the ticket?
Comment 7 by jagregory.com, Jan 05, 2009
Good point, I was unaware that we hadn't implemented the fix for column names. 
Reopened.
Status: Accepted
Comment 8 by jaymedavis, Jan 08, 2009
Waiting on this guy :)
Comment 9 by mpsk2nov, Mar 15, 2009
I'm using Fluent NH for mapping and NH as ORM in my C# application.. The problem is
with schemaupdate class.. if I create an instance of that.. using the configuration I
got from my exposeconfiguration function.. It doesnot update the schema.. I need some
better documentation on SchemaUpdate class.. or might be.. setting the configuration
to accomodate the new schema in an old database.. for versioning purposes..

I have tried a lot of variations but no DDL command is reflected on the actual
database using SchemaUpdate :(
Comment 10 by Hudson.Akridge, Apr 25, 2009
(No comment was entered for this change.)
Summary: Bug: Escaped column names
Sign in to add a comment

Hosted by Google Code