/*
 * genrereader.c: a class that reads genre from database
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */
#include "genrereader.h"
#include "tools.h"

static char sqlGenre[] = "SELECT vdr_Type.rowid, vdr_Type.name, count(*) sum FROM vdr_Media "
						 		 "LEFT JOIN vdr_Type ON vdr_Media.genre=vdr_Type.rowid "
						  		 "LEFT JOIN vdr_Type cat ON vdr_Media.type=cat.rowid "
						 		 "WHERE cat.name='%s' GROUP BY vdr_Type.name";

cGenreReader::cGenreReader(char *category) 
{_
  asprintf(&sql, sqlGenre, category);
  Init();
}

cGenreReader::~cGenreReader() 
{_
  SLDEBUG("# destructor of cGenreReader");
  free(sql);
}

cMenuGenreItem * cGenreReader::Read()
{_
  cMenuGenreItem * pGI = new cMenuGenreItem();
  cDataInfo	DatInf[] = {
	  { cDataInfo::INTEGER, (char *)&(pGI->id) - (char *)pGI },
	  { cDataInfo::TEXT,    (char *)&(pGI->name) - (char *)pGI },
	  { cDataInfo::INTEGER, (char *)&(pGI->count) - (char *)pGI },
	  { cDataInfo::UNKNOWN, 0 }
     };
  return Super::Read(pGI, DatInf);	
}
