anchor.diff:          Else ->     ?ClientError({"Bad sort field type", Else})
       end;
   sort_fun_any({Cp,Direction},_,ColMaps) when is_integer(Cp) ->
  -    %% SortSpec given referencing ColMap position    
  +    %% SortSpec given referencing ColMap position
       #ddColMap{tind=Ti,cind=Ci,type=Type} = lists:nth(Cp,ColMaps),
  +    ?Log("sort on col position ~p Ti=~p Ci=~p ~p~n",[Cp,Ti,Ci,lists:nth(Cp,ColMaps)]),    
       sort_fun(Type,Ti,Ci,Direction);
   sort_fun_any({CName,Direction},FullMaps,_) ->
       %% SortSpec given referencing FullMap alias    
       case lists:keysearch(CName, #ddColMap.alias, FullMaps) of
           #ddColMap{tind=Ti,cind=Ci,type=Type} ->
  +            ?Log("sort on col name  ~p Ti=~p Ci=~p ~p~n",[CName,Ti,Ci,Type]),    
               sort_fun(Type,Ti,Ci,Direction);
           Else ->     
               ?ClientError({"Bad sort field", Else})
  
positive.code: -export([ exec/5
          , parse/1
          ]).
  
  -export([ field_qname/1
          , field_name/1
  
negative.code: sort_spec_order([],_,_,Acc) -> 
      lists:reverse(Acc);        
  sort_spec_order([SS|SortSpecs],FullMaps,ColMaps, Acc) ->
      sort_spec_order(SortSpecs,FullMaps,ColMaps,[sort_order(SS,FullMaps,ColMaps)|Acc]).
  
  sort_order({Ti,Ci,Direction},FullMaps,_) ->
      %% SortSpec given referencing FullMap Ti,Ci    
      case [{S,T,N} || #ddColMap{tind=Tind,cind=Cind,schema=S,table=T,name=N} <- FullMaps, Tind==Ti, Cind==Ci] of
          [QN] -> {list_to_binary(field_name(QN)),Direction};
          _ ->    ?ClientError({"Bad sort field reference", {Ti,Ci}})
      end;
  sort_order({Cp,Direction},_,ColMaps) when is_integer(Cp) ->
      %% SortSpec given referencing ColMap position    
      #ddColMap{schema=S,table=T,name=N} = lists:nth(Cp,ColMaps),
      {list_to_binary(field_name({S,T,N})),Direction};
  sort_order({CName,Direction},FullMaps,_) ->
      %% SortSpec given referencing FullMap alias    
      case lists:keysearch(CName, #ddColMap.alias, FullMaps) of
          #ddColMap{schema=S,table=T,name=N} ->
              {list_to_binary(field_name({S,T,N})),Direction};
          _ -> 
              ?ClientError({"Bad sort field name", CName})
      end.
  