/***************************************************************************
                          sql.h  -  description
                             -------------------
    begin                : Sam Nov 24 16:38:12 CET 2001
    copyright            : (C) 2001 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 __sql_h__
#define __sql_h__

#include <qstring.h>
#include <qcstring.h>
#include <qmap.h>

#include <kurl.h>
#include <kio/global.h>
#include <kio/slavebase.h>

typedef QMap< QString, QString > QUrlQueryMap;

class QSqlDatabase;
class QSqlError;
class ConInfo;

class SqlProtocol : public QObject, public KIO::SlaveBase
{
  Q_OBJECT

public:

  SqlProtocol( const QCString &pool_socket, const QCString &app_socket );
  virtual ~SqlProtocol();
  void mimetype( const KURL& url );
  void stat( const KURL& url );
  void get( const KURL& url );
  void put( const KURL&, int, bool, bool );

  void listDir( const KURL &url );
  void special( const QByteArray& ba );

  static QUrlQueryMap queryToMap( const KURL& url );
  static QString mapToQuery( const QUrlQueryMap& map );

private:
  int deleteData( const QUrlQueryMap& map, const QString& tableName, QSqlDatabase* db, QSqlError* err = 0 );
  int updateData( const QUrlQueryMap& map, const QString& tableName, QSqlDatabase* db, QSqlError* err = 0 );
  int insertData( const QUrlQueryMap& map, const QString& tableName, QSqlDatabase* db, QSqlError* err = 0 );

  void redirect(const ConInfo& info);
};

#endif
