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

static char sqlMediaType[] = "SELECT vdr_Type.rowid, vdr_Type.name, count(*) "
	"sum FROM vdr_Media LEFT JOIN vdr_Type ON vdr_Media.type=vdr_Type.rowid "
	"LEFT JOIN vdr_Type cat ON vdr_Media.type=cat.rowid GROUP BY vdr_Type.name";

cMediaTypeReader::cMediaTypeReader() 
{_
  asprintf(&sql, sqlMediaType);
  Init();
}

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

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