Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

hk_connection.h

00001 // ****************************************************************************
00002 // copyright (c) 2000-2004 Horst Knorr <hk_classes@knoda.org>  
00003 // This file is part of the hk_classes library.
00004 // This file may be distributed and/or modified under the terms of the
00005 // GNU Library Public License version 2 as published by the Free Software
00006 // Foundation and appearing in the file COPYING included in the
00007 // packaging of this file.
00008 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00009 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00010 // ****************************************************************************
00011 #ifndef HK_CONNECTION
00012 #define HK_CONNECTION
00013 #include "hk_class.h"
00014 #include <list>
00015 #include <vector>
00016 #include <algorithm>
00017 using namespace std;
00018 class hk_drivermanager;
00019 class hk_connectionprivate;
00020 
00021 class hk_database;
00031 class hk_connection:public hk_class
00032 {
00033     friend class hk_database;
00034     friend class hk_drivermanager;
00035     public:
00040         virtual     ~hk_connection();
00044         void    set_host(const hk_string& h);
00045         hk_string   host(void);
00049         void    set_user(const hk_string& u);
00050         hk_string   user(void);
00054         void    set_password(const hk_string& p);
00055         hk_string   password(void);
00059         void        set_tcp_port(unsigned int t);
00060         unsigned int    tcp_port(void);
00061         void set_defaultdatabase(const hk_string&);
00062         hk_string defaultdatabase(void) const;
00066         virtual unsigned int    default_tcp_port(void) const;
00072         bool    connect(enum_interaction c=interactive);
00077         bool    disconnect(void);
00081         bool    is_connected(void);
00091         vector<hk_string>* dblist(void);
00098         hk_database* new_database(const hk_string& name="");
00099 
00100         bool rename_database(const hk_string& originalname, const hk_string& new_name);
00104         enum support_enum
00105         {
00106             SUPPORTS_AUTOINCCOLUMN=1,
00107             SUPPORTS_BOOLCOLUMN=2,
00108             SUPPORTS_DATECOLUMN=3,
00109             SUPPORTS_TIMECOLUMN=4,
00110             SUPPORTS_DATETIMECOLUMN=5,
00111             SUPPORTS_BINARYCOLUMN=6,
00112             SUPPORTS_MEMOCOLUMN=7,
00113             SUPPORTS_TIMESTAMPCOLUMN=8,
00114 
00115             SUPPORTS_SQL=100,
00116             SUPPORTS_TRANSACTIONS=101,
00117             SUPPORTS_REFERENTIALINTEGRITY=102,
00118             SUPPORTS_NEW_DATABASE=103,
00119             SUPPORTS_DELETE_DATABASE=104,
00120             SUPPORTS_NEW_TABLE=105,
00121             SUPPORTS_ALTER_TABLE=106,
00122             SUPPORTS_DELETE_TABLE=107,
00123             SUPPORTS_CREATE_INDEX=108,
00124             SUPPORTS_DELETE_INDEX=109,
00125             SUPPORTS_CHANGE_PASSWORD=110,
00126             SUPPORTS_RENAME_DATABASE=111,
00127             SUPPORTS_RENAME_TABLE=112,
00128             SUPPORTS_VIEWS=113,
00129             SUPPORTS_NEW_VIEW=114,
00130             SUPPORTS_ALTER_VIEW=115,
00131             SUPPORTS_DELETE_VIEW=116,
00132             
00133             SUPPORTS_LOCAL_FILEFORMAT=200
00134         };
00135 
00139         virtual bool server_supports(support_enum) const{return false;}
00143         enum need_enum
00144         {
00145 
00146             NEEDS_NOTHING=0,
00147             NEEDS_HOST=1,
00148             NEEDS_USERNAME=2,
00149             NEEDS_PASSWORD=3,
00150             NEEDS_SQLDELIMITER=4,
00151             NEEDS_PORT=5,
00152             NEEDS_DATABASENAME=6,
00153             NEEDS_BOOLEANEMULATION=7,//e.g. Mysql  doesn't have natively a boolean type, so tinyint is used
00154             NEEDS_NULL_TERMINATED_SQL=8 //e.g. Postgres needs null terminated strings in PQExec
00155         };
00159         virtual bool server_needs(need_enum) const {return false;}
00165         static  void    set_passworddialog(password_dialogtype*);
00169 virtual        bool    create_database(const hk_string& dbase);
00175 virtual        bool    delete_database(const hk_string& dbase);
00179         bool    database_exists(const hk_string& databasename);
00186         bool set_newpassword(const hk_string& newpassword);
00192         void show_newpassworddialog(void);
00197         static void set_newpassworddialog(newpassword_dialogtype*);
00198 /*
00199  *shows a password dialog
00200  *@return false if it has been cancelled else true
00201  */
00202         bool show_passworddialog(void);
00207         virtual hk_string drivername(void) const;
00213         void set_booleanemulation(bool emulate);
00214         bool booleanemulation(void) const;
00215         hk_drivermanager* drivermanager(void);
00223         bool copy_database(hk_database* fromdatabase,bool schema_and_data,bool copy_local_files,progress_dialogtype* progressdialog=NULL);
00224         hk_string last_servermessage(void){return p_lastservermessage;}
00225         hk_string databasepath(void);
00226 
00227     protected:
00228         hk_connection(hk_drivermanager* c);
00229         bool    p_connected;
00230         virtual bool    driver_specific_connect(void){return false;}
00231         virtual bool    driver_specific_disconnect(void){return false;}
00232         virtual bool    driver_specific_rename_database(const hk_string& oldname,const hk_string& newname){return false;}
00233         virtual  vector<hk_string>* driver_specific_dblist(void){return NULL;}
00234         virtual hk_database* driver_specific_new_database(void){return NULL;}
00235         virtual bool    driver_specific_new_password(const hk_string&){return false;}
00236         virtual bool    driver_specific_delete_database(const hk_string& dbase);
00237 
00238         void    db_remove(hk_database* d);
00239         hk_string sqldelimiter(void) ;
00240         void inform_databases_connect(void);
00241         void inform_databases_disconnect(void);
00242         vector<hk_string> p_databaselist;
00246         virtual void savedata(ostream& s);
00250         virtual void loaddata(const hk_string& definition);
00251 
00252         void set_last_servermessage(const hk_string& m);
00253         hk_database* database(void) const {return p_database;}
00254     private:
00255         void load_configuration(void);
00256         void save_configuration(void);
00257         bool copy_local_files(hk_database* fromdb,hk_database* todb,objecttype f,progress_dialogtype* progressdialog);
00258         hk_string ask_dbname(void);
00259         void make_databasedir(const hk_string& dbname);
00260         void set_classespath(hk_string& p);
00261         void delete_databasedirectory(const hk_string& db);
00262         void delete_directory(const hk_string& d);
00263 
00264         hk_database* p_database;
00265         unsigned int p_debug_counter;
00266         static  password_dialogtype* p_passworddialog;
00267         static  newpassword_dialogtype* p_newpassworddialog;
00268         hk_drivermanager* p_drivermanager;
00269         hk_string   p_lastservermessage;
00270       hk_connectionprivate* p_private;
00271 } ;
00272 #endif

Generated on Tue Mar 22 19:28:07 2005 for Databaseconnectionclasses by  doxygen 1.4.1