/***************************************************************************
                          sqloutputhtml.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 SQLOUTPUTHTML_H
#define SQLOUTPUTHTML_H

#include "sqloutputiface.h"

/**Basic HTML output class
  *@author Harald Fernengel
  */

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

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

  /** 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 */
  QString showStartPage();
  /** shows table structure and meta-data */
  QString showMetaData( const QString& );
  /** the mimetype of the returned data */
  QString mimeType() const { return QString::fromLatin1( "text/html" ); }
  /** the text of the last error that occured */
  QString lastError() const { return lastErr; }
  /** Shows special pages. Note that this is highly output format dependent, so
   *  not every outputformat might implement each special output. The second
   *  parameter stands for the desired table, QString::null means "no table".
   *  Additional parameters (function specific) can be passed on in the QStringList.
   */
  QString showSpecial( const QString&, const QString& = QString::null, const QStringList& = QStringList(),
		       int limit = -1, int limitOffset = -1 );


protected:
  virtual QString header( const QString& title );
  virtual QString showInsertForm( const QString& table );
  virtual QString showUpdateForm( const QString& table, const QStringList& pks );
  virtual QString showDeleteForm( const QString& table, const QStringList& pks );
  virtual QString footer();
  virtual QString showQuery( const QString& q, bool editable, const QSqlIndex& pk = QSqlIndex(), int limit = -1, int limitOffset = -1 );
  virtual QString showEditableTable( const QString& tableName, int limit = -1, int limitOffset = -1 );
  
private:
  QSqlDatabase*       db;
  KURL                url;
  QString             lastErr;

};

#endif
