{
	$p_id      = OC_Shorty_Type::req_argument ( 'id',     OC_Shorty_Type::ID,     FALSE );
	$p_query   = OC_Shorty_Type::req_argument ( 'query',  OC_Shorty_Type::STRING, FALSE );
	$p_format  = OC_Shorty_Type::req_argument ( 'format', OC_Shorty_Type::STRING, FALSE );
	$p_sort    = OC_Shorty_Type::req_argument ( 'sort',   OC_Shorty_Type::STRING, 'ka' );
	$param = array (
		':user'   => OCP\User::getUser ( ),
		':id'     => $p_id,
		':sort'   => OC_Shorty_Type::$SORTING[$p_sort],
		':format' => $p_format,
		':sort'   => $p_sort,
		':query'  => $p_query,
	);

	$match = NULL;
	$candidates = OC_Shorty_Hooks::requestQueries();
	foreach ($candidates['list'] as $candidate)
		if ($candidate['id']==$p_query)
			$match = $candidate;
	if ( ! $match )
		throw new OC_Shorty_Exception ( "Request for unknown query '%1'.", array($p_query) );

	// run query
	$query = OCP\DB::prepare ( $match['query'] );
	$result = $query->execute(array_intersect($param,$match['param']));
	$reply = $result->fetchAll();

	// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
	OC_Shorty_Tools::ob_control ( FALSE );

	// output payload