anchor.diff:  add_custompivot_join(Table, SearchSql) ->
       add_custompivot_join("rsc", Table, SearchSql).
   add_custompivot_join(RscTable, Table, Search) ->
  +    Table1 = sql_safe(Table),
  +    RscTable1 = sql_safe(RscTable),
       Alias = "pivot" ++ integer_to_list(length(Search#search_sql.tables)),
  -    JoinClause = "(" ++ RscTable ++ ".id = " ++ Alias ++ ".id)",
  +    JoinClause = "(" ++ RscTable1 ++ ".id = " ++ Alias ++ ".id)",
       Search#search_sql{
         tables=Search#search_sql.tables ++ [{Table, Alias}],
  -      from=Search#search_sql.from ++ " left join pivot_" ++ Table ++ " " ++ Alias ++ " on " ++ JoinClause
  +      from=Search#search_sql.from ++ " left join pivot_" ++ Table1 ++ " " ++ Alias ++ " on " ++ JoinClause
        }.
   
   %% Add an AND clause to the WHERE of a #search_sql
  +%% Clause is already supposed to be safe.
   add_where(Clause, Search) ->
       case Search#search_sql.where of
           [] ->
  
positive.code:             Search#search_sql{where=C ++ " AND " ++ Clause}
      end.
  
  %% Add an AND clause to the WHERE of a #search_sql
  add_order(Clause, Search) ->
      case Search#search_sql.order of
          [] ->
              Search#search_sql{order=Clause};
  
negative.code: ]).
  
  -include_lib("zotonic.hrl").
  
  -define(SQL_SAFE_REGEXP, "^[a-zA-Z_\.]+$").
  
  search(Query, Context) ->
      Start = #search_sql{select="rsc.id",
  