Source: connection.h


Annotated List
Files
Globals
Hierarchy
Index
#ifndef CONNECTION_H
#define CONNECTION_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <qstring.h>
#include <qlist.h>

#include "object.h"

namespace KDB {

class Database;


/**
 * Manages the connection state to a SQL engine.
 *
 * Basically stores all authentication tokens and
 * opens/closes connection as needed.
 *
 * It is also a collection of database objects, allowing
 * @li traversal of all databases (@ref iterator and @ref databases )
 * @li retrieval by name (@ref find )
 * @li creation of new databases (@ref createDatabase )
 *
 * @short Connection to a server
 */

class Connection : public Object {

    Q_OBJECT

public:

    typedef QListIterator<Database> iterator;

public:

    Connection(const char * name);
    
    virtual ~Connection();

    /**
     * connect to the host. if username and password are missing,
     * pops up a dialog to ask them. if the connection is open, nothing
     * is actually done
     */
    void open();

    /**
     * disconnects from the host. all databases are closed
     */
    virtual void close() = 0;

    /**
     * returns true if a successfull connection has been estabilished
     */
    bool isConnected();

    /**
     * sets the user for this connection. the change will not take
     * place until a disconnect/connect is made
     */
    void setUser(const QString &name);

    /**
     * sets the password for this connection. the change will not take
     * place until a disconnect/connect is made. passing QString::null
     * will force the connection to ask for the password next time
     * @ref open is called
     */
    void setPassword(const QString &pwd);

    /**
     * returns the host name for this connection
     */
    QString host();

    /**
     * returns a complete description of the connection
     */
    QString prettyPrint();

    /**
     * open a database by name
     */
    Database * openDatabase(const QString &name);

    /**
     * return a database by name.
     */
    Database * find(const QString &name);

    /**
     * creates a new database in the current connection
     */
    virtual Database * createDatabase(const QString &name) = 0;

    /**
     * return a list of all available databases
     */
    QList<Database> databases();

    /**
     * return an iterator that points to the first database
     */
    iterator begin();
    
protected:

    /**
     * Connect to the Host. reimplemented in plugins
     */
    virtual bool _connect(const QString &user, const QString &pwd) = 0;
    
protected:
    bool m_connected;
    QString m_host;
    QList<Database> m_databases;

private:
    QString m_user;
    QString m_password;
    QString m_plugin;

};

}

#endif



Generated by: pradu@server.rete.casa on Fri Jul 28 15:15:55 2000, using kdoc 2.0a36.