Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Bug in Custom Macro?? View modes: 
User avatar
Member
Member
Darren-DesignReligion.co - 2/2/2010 11:32:52 AM
   
Bug in Custom Macro??
Hi all,

I have put together a very simple custom macro - utilising the ResolveCustomMacro.cs file in app_code/global/cms/cmscustom.cs

Its for use in the Where field in a datalist

here is the code:


public static string ResolveCustomMacro(MacroResolver sender, string expression, out bool match)
{
match = false;
string result = "";

// Add your custom macro evaluation

switch (expression.ToLower())
{
case "checkmusiccategory":
match = true;
string cat = QueryHelper.GetString("cat", "");
if (cat != "")
{
HttpContext.Current.Response.Write(cat);
result = " Category = '" + cat + "' ";
HttpContext.Current.Response.Write("<br />" + result);
}
break;
}


return result;
}


Now, if ?cat doesn't exists in the Qstring then nothing is returned = datalist shows all documents which is what i want.

however, if there is a ?cat then i get the following error:


[DataConnection.ExecuteQuery]: Query: SELECT * FROM View_custom_YouTube_Joined WHERE (((((SiteName = N'DownsSyndromeThailand') AND (Published = 1)) AND (DocumentCulture = N'en-US')) AND (NodeAliasPath LIKE N'/Music/Music-Library/%')) AND ( Category = ''Kids'' )) ORDER BY documentcreatedwhen DESC : caused exception: Incorrect syntax near 'Kids'.


Notice the additional ' in the where clause around Kids

whats causing this??

Darren





User avatar
Member
Member
Darren-DesignReligion.co - 2/3/2010 3:51:18 AM
   
RE:Bug in Custom Macro??
Still chipping away at this one.

I have tried escaping - \' and using char values; all sorts - just no matter what i do i seem to gain an additional single quote in my where clause - either that or ' is being converted to "

If i type the where clause category = 'Kids' it works fine.

regards
darren

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 2/4/2010 3:38:42 AM
   
RE:Bug in Custom Macro??
Hi,

If you are using for example Repeater web part to display your data, you need to use following code in SetupControl method in ~\CMSWebParts\Viewers\cmsrepeater.ascx.cs file:

this.SQLProperties = "";

I hope this will help you.

Best regards,
Miroslav Remias.