anchor.diff:  
   -spec query_bucket(Cont, Id, Product) -> Result
   	when
  -		Cont :: start | eof | any(),
  -		Id :: string() | undefined | '_',
  -		Product :: string() | undefined | '_',
  -		Result :: {Cont, [#bucket{}]} | {error, Reason},
  +		Cont :: start | any(),
  +		Id :: Match,
  +		Product :: Match,
  +		Match :: {exact, string()} | {notexact, string()} | {like, string()},
  +		Result :: {Cont, [#bucket{}]} | eof | {error, Reason},
   		Reason :: term().
   %% @doc Query bucket
  -query_bucket(Cont, Id, undefined) ->
  -	query_bucket(Cont, Id, '_');
  -query_bucket(Cont, undefined, Product) ->
  -	query_bucket(Cont, '_', Product);
  -query_bucket(start, Id, Product) ->
  +query_bucket(Cont, '_', Product) ->
   	MatchSpec = [{'_', [], ['$_']}],
  -	F = fun F(start, Acc) ->
  -				F(mnesia:select(bucket, MatchSpec,
  -						?CHUNKSIZE, read), Acc);
  -			F('$end_of_table', Acc) ->
  -				lists:flatten(lists:reverse(Acc));
  -			F({error, Reason}, _Acc) ->
  -				{error, Reason};
  -			F({Services, Cont}, Acc) ->
  -				F(mnesia:select(Cont), [Services | Acc])
  -	end,
  -	case mnesia:transaction(F, [start, []]) of
  -		{aborted, Reason} ->
  +	query_bucket2(Cont, MatchSpec, Product);
  +query_bucket(Cont, {like, Id}, Product) when is_list(Id) ->
  +	MatchSpec = case lists:last(Id) of
  +		$% ->
  +			Prefix = lists:droplast(Id),
  +			MatchHead = #bucket{id = Prefix, _ = '_'},
  +			[{MatchHead, [], ['$_']}];
  +		_ ->
  +			MatchHead = #bucket{id = Id, _ = '_'},
  +			[{MatchHead, [], ['$_']}]
  +	end,
  +	query_bucket2(Cont, MatchSpec, Product);
  +query_bucket(Cont, MatchId, Product) when is_tuple(MatchId) ->
  +	MatchCondition = [match_condition('$1', MatchId)],
  +	MatchHead = #bucket{id = '$1', _ = '_'},
  +	MatchSpec = [{MatchHead, MatchCondition, ['$_']}],
  +	query_users2(Cont, MatchSpec, Product).
  +%% @hidden
  +query_bucket2(start, MatchSpec, Product) ->
  +	F = fun() ->
  +		mnesia:select(bucket, MatchSpec, ?CHUNKSIZE, read)
  +	end,
  +	case catch mnesia:ets(F)  of
  +		{'EXIT', Reason} ->
   			{error, Reason};
  -		{atomic, Buckets} ->
  -			{eof, query_bucket1(Id, Product, Buckets)}
  -	end.
  -%% @hidden
  -query_bucket1('_', Product, Buckets) ->
  -	query_bucket2(Product, Buckets);
  -query_bucket1(Id, Product, Buckets) ->
  -	F = fun(#bucket{id = Id1}) -> lists:prefix(Id, Id1) end,
  -	NewBuckets = lists:filter(F, Buckets),
  -	query_bucket2(Product, NewBuckets).
  -%% @hidden
  -query_bucket2('_', Buckets) ->
  -	Buckets;
  -query_bucket2(Product, Buckets) ->
  -	F1 = fun(#bucket{product = Products}) ->
  -		F2 = fun(Product1) -> lists:prefix(Product, Product1) end,
  -		lists:any(F2, Products)
  -	end,
  -	lists:filter(F1, Buckets).
  +		{Buckets, Cont} ->
  +			query_bucket3(Cont, Buckets, Product);
  +		'$end_of_table' ->
  +			eof
  +	end;
  +query_bucket2(Cont, _MatchSpec, Product) ->
  +	F = fun() -> mnesia:select(Cont) end,
  +	case catch mnesia:ets(F)  of
  +		{'EXIT', Reason} ->
  +			{error, Reason};
  +		{Buckets, Cont} ->
  +			query_bucket3(Cont, Buckets, Product);
  +		'$end_of_table' ->
  +			eof
  +	end.
  +%% @hidden
  +query_bucket3(Cont, Buckets, '_') ->
  +	{Cont, Buckets};
  +query_bucket3(Cont, Buckets, {Operator, Product}) ->
  +	F = fun(#bucket{product = Products}) ->
  +				F2 = fun(P) -> match(Operator, Product, P) end,
  +				lists:any(F2, Products)
  +	end,
  +	{Cont, lists:filter(F, Buckets)}.
   
   -spec delete_bucket(BucketId) -> ok
   	when
  
positive.code: 		{aborted, Reason} ->
  			exit(Reason)
  	end.
  
  -spec query_clients(Cont, Address, Identifier, Port, Protocol, Secret) -> Result
  	when
  		Cont :: start | eof | any(),
  		Address :: undefined | string(),
  		Identifier :: undefined | string(),
  		Port :: undefined | string(),
  		Protocol :: undefined | string(),
  		Secret :: undefined | string(),
  		Result :: {Cont, [#client{}]} | {error, Reason},
  		Reason :: term().
  query_clients(start, Address, Identifier, Port, Protocol, Secret) ->
  	MatchSpec = [{'_', [], ['$_']}],
  	F = fun() ->
  		mnesia:select(client, MatchSpec, read)
  	end,
  	case mnesia:transaction(F) of
  		{atomic, Clients} ->
  			query_clients1(Clients, Address, Identifier, Port, Protocol, Secret);
  		{aborted, Reason} ->
  			{error, Reason}
  	end.
  %% @hidden
  query_clients1(Clients, Address, Identifier, Port, Protocol, undefined) ->
  	query_clients2(Clients, Address, Identifier, Port, Protocol);
  query_clients1(Clients, Address, Identifier, Port, Protocol, Secret) ->
  	SecretBin = list_to_binary(Secret),
  	SecretLen = size(SecretBin),
  	Fun = fun(#client{secret = S}) ->
  			case S of
  				<<SecretBin:SecretLen/binary, _/binary>> ->
  					true;
  				_ ->
  					false
  			end
  	end,
  	FilteredClients = lists:filter(Fun, Clients),
  	query_clients2(FilteredClients, Address, Identifier, Port, Protocol).
  %% @hidden
  query_clients2(Clients, Address, Identifier, Port, undefined) ->
  	query_clients3(Clients, Address, Identifier, Port);
  query_clients2(Clients, Address, Identifier, Port, Protocol) ->
  	P1 = string:to_upper(Protocol),
  	Fun = fun(#client{protocol = P}) ->
  				P2 = string:to_upper(atom_to_list(P)),
  				lists:prefix(P1, P2)
  	end,
  	FilteredClients = lists:filter(Fun, Clients),
  	query_clients3(FilteredClients, Address, Identifier, Port).
  %% @hidden
  query_clients3(Clients, Address, Identifier, undefined) ->
  	query_clients4(Clients, Address, Identifier);
  query_clients3(Clients, Address, Identifier, Port) ->
  	Fun = fun(#client{port = P}) -> lists:prefix(Port, integer_to_list(P)) end,
  	FilteredClients = lists:filter(Fun, Clients),
  	query_clients4(FilteredClients, Address, Identifier).
  %% @hidden
  query_clients4(Clients, Address, undefined) ->
  	query_clients4(Clients, Address);
  query_clients4(Clients, Address, Identifier) ->
  	IdBin = list_to_binary(Identifier),
  	IdLen = size(IdBin),
  	Fun = fun(#client{identifier = I}) ->
  			case I of
  				<<IdBin:IdLen/binary, _/binary>> ->
  					true;
  				_ ->
  					false
  			end
  	end,
  	FilteredClients = lists:filter(Fun, Clients),
  	query_clients4(FilteredClients, Address).
  %% @hidden
  query_clients4(Clients, undefined) ->
  	{eof, Clients};
  query_clients4(Clients, Address) ->
  	Fun = fun(#client{address = A}) -> lists:prefix(Address, inet:ntoa(A)) end,
  	{eof, lists:filter(Fun, Clients)}.
  
  get_products()->
  	MatchSpec = [{'_', [], ['$_']}],
  
negative.code: 
  -spec query_offer(Cont, Name, Description, Status, SDT, EDT, Price) -> Result
  	when
  		Cont :: start | any(),
  		Name :: Match,
  		Description :: Match,
  		Status :: Match,
  		SDT :: Match,
  		EDT:: Match,
  		Price :: Match,
  		Match :: {exact, string()} | {notexact, string()} | {like, string()} | '_',
  		Result :: {Cont, [#offer{}]} | eof | {error, Reason},
  		Reason :: term().
  %% @doc Query offer entires
  query_offer(Con, '_', '_', Status, STD, EDT, Price) ->
  	query_offer4(Con, Status, STD, EDT, Price, #offer{_ = '_'}, []);
  query_offer(Con, Name, Description, Status, STD, EDT, Price) ->
  	query_offer2(Con, Name, Description, Status, STD, EDT, Price, #offer{_ = '_'}, []).
  %% @hidden
  query_offer1(String) ->
  	case lists:last(String) of
  		$% ->
  			lists:droplast(String) ++ '_';
  		_ ->
  			String
  	end.
  query_offer2(Con, '_', Description, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	query_offer3(Con, Description, Status, STD, EDT, Price, MatchHead, MatchConditions);
  query_offer2(Con, {like, Name}, Description, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	Name1 = query_offer1(Name),
  	MatchHead1 = MatchHead#offer{name = Name1},
  	query_offer3(Con, Description, Status, STD, EDT, Price, MatchHead1, MatchConditions);
  query_offer2(Con, MatchName, Description, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	MatchConditions1 = [match_condition('$1', MatchName) | MatchConditions],
  	MatchHead1 = MatchHead#offer{name = '$1'},
  	query_offer3(Con, Description, Status, STD, EDT, Price, MatchHead1, MatchConditions1).
  %% @hidden
  query_offer3(Con, '_', Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	query_offer4(Con, Status, STD, EDT, Price, MatchHead, MatchConditions);
  query_offer3(Con, {like, Description}, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	Des = query_offer1(Description),
  	MatchHead1 = MatchHead#offer{description = Des},
  	query_offer4(Con, Status, STD, EDT, Price, MatchHead1, MatchConditions);
  query_offer3(Con, MatchDescription, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	MatchConditions1 = [match_condition('$2', MatchDescription) | MatchConditions],
  	MatchHead1 = MatchHead#offer{name = '$3'},
  	query_offer4(Con, Status, STD, EDT, Price, MatchHead1, MatchConditions1).
  %% @hidden
  query_offer4(start, Status, STD, EDT, Price, MatchHead, MatchConditions) ->
  	MatchSpec = [{MatchHead, MatchConditions, ['$_']}],
  	F = fun() -> mnesia:select(offer, MatchSpec, ?CHUNKSIZE, read) end,
  	case mnesia:ets(F) of
  		{'EXIT', Reason} ->
  			{error, Reason};
  		{Offers, Cont} ->
  			query_offer5(Status, STD, EDT, Price, Cont, Offers);
  		'$end_of_table' ->
  			eof
  	end;
  query_offer4(Con, Status, STD, EDT, Price, _MatchHead, _MatchConditions) ->
  	F = fun() -> mnesia:select(Con) end,
  	case mnesia:ets(F) of
  		{'EXIT', Reason} ->
  			{error, Reason};
  		{Offers, Cont} ->
  			query_offer5(Status, STD, EDT, Price, Cont, Offers);
  		'$end_of_table' ->
  			eof
  	end.
  %% @hidden
  query_offer5('_', STD, EDT, Price, Cont, Offers) ->
  	query_offer6(STD, EDT, Price, Cont, Offers);
  query_offer5({Operator, Status}, STD, EDT, Price, Cont, Offers) ->
  	F = fun(#offer{status = Status1}) ->
  			Status2 = atom_to_list(Status1),
  			match(Operator, Status, Status2)
  	end,
  	NewOffers = lists:filter(F, Offers),
  	query_offer6(STD, EDT, Price, Cont, NewOffers).
  %% @hidden
  query_offer6('_', EDT, Price, Cont, Offers) ->
  	query_offer7(EDT, Price, Cont, Offers);
  query_offer6({Operator, STD}, EDT, Price, Cont, Offers) ->
  	F = fun(#offer{start_date = STD1}) when is_integer(STD1) ->
  			SDT2 = integer_to_list(STD1),
  			match(Operator, STD, SDT2);
  		(_) ->
  			false
  	end,
  	NewOffers = lists:filter(F, Offers),
  	query_offer7(EDT, Price, Cont, NewOffers).
  %% @hidden
  query_offer7('_', Price, Cont, Offers) ->
  	query_offer8(Price, Cont, Offers);
  query_offer7({Operator, EDT}, Price, Cont, Offers) ->
  	F = fun(#offer{end_date = ETD1}) when is_integer(ETD1) ->
  			EDT2 = integer_to_list(ETD1),
  			match(Operator, EDT, EDT2);
  		(_) ->
  			false
  	end,
  	NewOffers = lists:filter(F, Offers),
  	query_offer8(Price, Cont, NewOffers).
  %% @hidden
  query_offer8('_', Cont, Offers) ->
  	{Cont, Offers};
  query_offer8({Operator, Price}, Cont, Offers) ->
  	F = fun(#offer{price = Prices}) ->
  			F2 = fun(#price{name = Price1}) ->
  					match(Operator, Price, Price1)
  			end,
  			list:any(F2, Prices)
  	end,
  	{Cont, lists:filter(F, Offers)}.
  
  -spec query_table(Cont, Name, Prefix, Description, Rate, LM) -> Result
  	when
  