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

static char sqlSubGenre[] = "SELECT vdr_Type.rowid, vdr_Type.name, count(*) sum "
								    "FROM vdr_Media LEFT JOIN vdr_Type ON "
									 "vdr_Media.subgenre=vdr_Type.rowid WHERE vdr_Media.genre=%d "
									 "GROUP BY vdr_Type.name";

cSubGenreReader::cSubGenreReader(int genre) 
{_
  asprintf(&sql, sqlSubGenre, genre);
  Init();
}

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

cMenuSubGenreItem * cSubGenreReader::Read()
{_
  cMenuSubGenreItem * pGI = new cMenuSubGenreItem();
  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);	
}
