/***************************************************************************
                          sqloutputtext.h  -  description
                             -------------------
    begin                : Fre Mär 8 2002
    copyright            : (C) 2002 by Harald Fernengel
    email                : harry@kdevelop.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SQLOUTPUTTEXT_H
#define SQLOUTPUTTEXT_H

#include "sqloutputiface.h"

/**Outputs plain text
  *@author Harald Fernengel
  */

class SqlOutputText : public SqlOutputIface  {
public:
  /** the requested URL and the database connection */
  SqlOutputText( const KURL&, QSqlDatabase* = 0 );
  ~SqlOutputText();

  void setDatabase( QSqlDatabase* sdb ) { db = sdb; }
  QSqlDatabase* database() const { return db; }

  /** returns a list of available tables */
  QString showTables();
  /** shows the contents of a query */
  QString showQuery( const QString& );
  /** shows the contents of a table  */
  QString showTable( const QString&, int limit = -1, int limitOffset = -1 );
  /** displays the error message and the error from the database */
  void error( const QString&, const QSqlError& = QSqlError() );
  /** An action was successful */
  QString success( const QString& );
  /** shows the start page if no host/plugin/database is given */
  virtual QString showStartPage();
  /** the mimetype of the returned data */
  QString mimeType() const { return QString::fromLatin1( "text/plain" ); }
  /** the text of the last error that occured */
  QString lastError() const { return lastErr; }
  /** shows table structure and meta-data */
  QString showMetaData( const QString& );

private:
  QSqlDatabase* db;
  QString       lastErr;
};

/**
  Outputs comma separated values.
*/
class SqlOutputCSV: public SqlOutputText  {
public:
  SqlOutputCSV( const KURL&, QSqlDatabase* = 0 );
  ~SqlOutputCSV();
  QString showQuery( const QString& );
  QString showTables();
};

#endif
