yasser777 / nettiers

Automatically exported from code.google.com/p/nettiers
0 stars 0 forks source link

Exception raised in SELECT statements when order by/sort expression is missing, bug induced in latest release #381

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The latest change adds a bug:

4/18/2011
    - Fixed a bug where the EntityGridViewSearch dropdown was not using the friendly name.

--------------
DIFF:
--------------

--- netTiers/Entities/EntityInstanceBase.generated.cst  Wed Apr 20 14:21:39 2011
+++ netTiers/Entities/EntityInstanceBase.generated.cst  Wed Apr 20 11:44:46 2011
@@ -1498,7 +1498,7 @@
        /// <summary>
        /// <%=GetPropertyName(cols[x])%> : <%=GetColumnXmlComment(cols[x],2)%>
        /// </summary>
-       [EnumTextValue("<%= cols[x].Name %>")]
+       [EnumTextValue("<%= GetFriendlyName(cols[x]) %>")]
        [ColumnEnum(<%= GetColumnEnumAttributeParams(cols[x]) %>)]
        <%=GetPropertyName(cols[x])%> = <%= (x+1) %><%if(x < cols.Count -1) {%>,<%}%>
        <% }// end for %>   

---------------
GENERATED CODE: (example)
---------------
public enum PostcodeColumn : int
    {
        /// <summary>
        /// PostcodeId : 
        /// </summary>
        [EnumTextValue("Postcode Id")]
        [ColumnEnum("PostcodeId", typeof(System.Int32), System.Data.DbType.Int32, true, true, false)]
        PostcodeId = 1,
        /// <summary>
        /// Postcode : 
        /// </summary>
        [EnumTextValue("Postcode")]
        [ColumnEnum("Postcode", typeof(System.String), System.Data.DbType.String, false, false, false, 10)]
        Postcode = 2
    }//End enum

-------------------------------
The EnumTextValue is read here:(netTiers/DataAccessLayer/Utility.cst : Line 312)
-------------------------------
            if ( String.IsNullOrEmpty(sort) )
            {
                <%if(ProviderInvariantName == "MySql.Data.MySqlClient" || ProviderInvariantName == "System.Data.OracleClient"){%>
                sort = String.Format("'{0}'", EntityHelper.GetEnumTextValue((Enum)Enum.Parse(columnEnum, Enum.GetName(columnEnum, 1), true)));
                <%}else{%>
                sort = String.Format("[{0}]", EntityHelper.GetEnumTextValue((Enum)Enum.Parse(columnEnum, Enum.GetName(columnEnum, 1), true)));
                <%}%>
            }

Which returns "Postcode Id" as the sort expression in our example (should be 
"PostcodeId")

That causes the SQL to look like:

SELECT ... FROM ...WHERE ... ORDER BY [Postcode Id]

instead of

SELECT ... FROM ...WHERE ... ORDER BY [PostcodeId]

The extra space causes a SQL Exception.

Can this be fixed quickly? Thanks

Sorry of this post is unprofessional. I am not a big issue tracker user.

Original issue reported on code.google.com by vaibhavk...@gmail.com on 20 Apr 2011 at 9:04

GoogleCodeExporter commented 9 years ago
Looks like this code should be using the ColumnEnum Attribute (sigh). Anyone 
willing to create a patch for this :)? I can create a patch but it may take a 
bit.

-Blake

Original comment by bniemyj...@codesmithtools.com on 21 Apr 2011 at 12:12

GoogleCodeExporter commented 9 years ago
Here is my attempt:

Index: DataAccessLayer/Query/SqlStringBuilder.cst
===================================================================
--- DataAccessLayer/Query/SqlStringBuilder.cst  (revision 886)
+++ DataAccessLayer/Query/SqlStringBuilder.cst  (working copy)
@@ -1840,7 +1840,7 @@
         /// <returns></returns>
         protected virtual String GetColumnName(EntityColumn column)
         {
-            String name = EntityHelper.GetEnumTextValue(column as Enum);
+            String name = 
EntityHelper.GetAttribute<ColumnEnumAttribute>(column as Enum).Name;

             if (string.IsNullOrEmpty(name))
             {
@@ -2982,7 +2982,7 @@
         /// <returns></returns>
         protected virtual String GetColumnName(EntityColumn column)
         {
-            String name = EntityHelper.GetEnumTextValue(column as Enum);
+            String name = 
EntityHelper.GetAttribute<ColumnEnumAttribute>(column as Enum).Name;

             if (string.IsNullOrEmpty(name))
             {
Index: DataAccessLayer/Utility.cst
===================================================================
--- DataAccessLayer/Utility.cst (revision 886)
+++ DataAccessLayer/Utility.cst (working copy)
@@ -285,7 +285,7 @@
                        try
                        {
                            col = (Enum) Enum.Parse(columnEnum, column, true);
-                           name = EntityHelper.GetEnumTextValue(col);
+                           name = EntityHelper.GetAttribute<ColumnEnumAttribute>(col).Name;

                            if ( sb.Length > 0 )
                            {
@@ -312,9 +312,9 @@
            if ( String.IsNullOrEmpty(sort) )
            {
                <%if(ProviderInvariantName == "MySql.Data.MySqlClient" || ProviderInvariantName == "System.Data.OracleClient"){%>
-               sort = String.Format("'{0}'", 
EntityHelper.GetEnumTextValue((Enum)Enum.Parse(columnEnum, 
Enum.GetName(columnEnum, 1), true)));
+               sort = String.Format("'{0}'", 
EntityHelper.GetAttribute<ColumnEnumAttribute>((Enum)Enum.Parse(columnEnum, 
Enum.GetName(columnEnum, 1), true)).Name);
                <%}else{%>
-               sort = String.Format("[{0}]", 
EntityHelper.GetEnumTextValue((Enum)Enum.Parse(columnEnum, 
Enum.GetName(columnEnum, 1), true)));
+               sort = String.Format("[{0}]", 
EntityHelper.GetAttribute<ColumnEnumAttribute>((Enum)Enum.Parse(columnEnum, 
Enum.GetName(columnEnum, 1), true)).Name);
                <%}%>
            }

Original comment by vaibhavk...@gmail.com on 21 Apr 2011 at 4:20

Attachments:

GoogleCodeExporter commented 9 years ago
Any update guys?

Original comment by vaibhavk...@gmail.com on 27 Apr 2011 at 10:37

GoogleCodeExporter commented 9 years ago
Hello,

Thanks for your patch. I did a visual code review and the changes looked good 
so I have committed the changes.

Thanks
-Blake Niemyjski

Original comment by bniemyjski on 27 Apr 2011 at 4:47