nettiers – GetBy Index problem with StoredProcedure long name

Today I’ve discovered a problem with CodeSmith¬†nettiers templates¬†because it was possible to generate two SPs with the same name, for different entities.

This happens when there are two indexes for two different tables that have the same column names and the column names reach the maximum lenght (128 for SQL). In this case the generated SP name doesn’t contain the table name as a prefix.

Here is the original nettiers code for the GetProcNameForGetByIX method in CommonSqlCode.cs:

// get the key names one at a time until we run out of space
stringbuilder names = new stringbuilder(maxlen);
string keyname;
for(int x = 0; x < keys.length; x++)
  keyname = getpropertyname(keys[x]);
  if (names.length + keyname.length <= maxlen)
return names.tostring();

I’ve upgraded the method to receive the index name and the new code is:

if (string.IsNullOrEmpty(indexName))
   throw new Exception("Need index name");
 string name = string.Concat(prefix, indexName);
 if (name.Length > maxLen)
   throw new Exception("SP name continues to be greater than maxlen");
 return name;

Then I needed to pass the index name on all the places that this method was call. Just use find in files and search for that method.

Leave a Reply

Your email address will not be published. Required fields are marked *