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

hk_connection.h

00001 // ****************************************************************************
00002 // copyright (c) 2000-2005 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_TEXTCOLUMN=9,
00116             SUPPORTS_INTEGERCOLUMN=10,
00117             SUPPORTS_SMALLINTEGERCOLUMN=11,
00118             SUPPORTS_FLOATINGCOLUMN=12,
00119             SUPPORTS_SMALLFLOATINGCOLUMN=13,
00120 
00121             SUPPORTS_PROPRIETARYCOLUMN=19,//driver specific datatype that can not be mapped to a hk_classes type
00122 
00123             SUPPORTS_SQL=100,
00124             SUPPORTS_TRANSACTIONS=101,
00125             SUPPORTS_REFERENTIALINTEGRITY=102,
00126             SUPPORTS_NEW_DATABASE=103,
00127             SUPPORTS_DELETE_DATABASE=104,
00128             SUPPORTS_NEW_TABLE=105,
00129             SUPPORTS_ALTER_TABLE=106,
00130             SUPPORTS_DELETE_TABLE=107,
00131             SUPPORTS_CREATE_INDEX=108,
00132             SUPPORTS_DELETE_INDEX=109,
00133             SUPPORTS_CHANGE_PASSWORD=110,
00134             SUPPORTS_RENAME_DATABASE=111,
00135             SUPPORTS_RENAME_TABLE=112,
00136             SUPPORTS_VIEWS=113,
00137             SUPPORTS_NEW_VIEW=114,
00138             SUPPORTS_ALTER_VIEW=115,
00139             SUPPORTS_DELETE_VIEW=116,
00140             SUPPORTS_ADD_COLUMN=117,
00141             SUPPORTS_DELETE_COLUMN=118,
00142             SUPPORTS_CHANGE_COLUMNTYPE=119,
00143             SUPPORTS_CHANGE_COLUMNNAME=120,
00144             SUPPORTS_ALTER_PRIMARY_KEY=121,
00145             SUPPORTS_ALTER_NOT_NULL=122,
00146 
00147             SUPPORTS_SQL_GROUP_BY=180,
00148             SUPPORTS_SQL_ORDER_BY=181,
00149             SUPPORTS_SQL_HAVING=182,
00150             SUPPORTS_SQL_WHERE=183,
00151             SUPPORTS_SQL_ALIAS=184,
00152 
00153             SUPPORTS_LOCAL_FILEFORMAT=200,
00154             SUPPORTS_NONALPHANUM_FIELDNAMES=201, // if not set field name can only have [a-zA-Z0-9]
00155             SUPPORTS_NONASCII_FIELDNAMES=202, //unicode characters etc
00156             SUPPORTS_SPACE_FIELDNAMES=203 // means  a space character can be part
00157         };
00158 
00162         virtual bool server_supports(support_enum) const{return false;}
00166         enum need_enum
00167         {
00168 
00169             NEEDS_NOTHING=0,
00170             NEEDS_HOST=1,
00171             NEEDS_USERNAME=2,
00172             NEEDS_PASSWORD=3,
00173             NEEDS_SQLDELIMITER=4,
00174             NEEDS_PORT=5,
00175             NEEDS_DATABASENAME=6,
00176             NEEDS_BOOLEANEMULATION=7,//e.g. Mysql  doesn't have natively a boolean type, so tinyint is used
00177             NEEDS_NULL_TERMINATED_SQL=8, //e.g. Postgres needs null terminated strings in PQExec
00178             NEEDS_TABLE_ALIAS_AS=9 // set if the server needs 'AS' between the table name and its alias name in a FROM clause
00179         };
00183         virtual bool server_needs(need_enum) const {return false;}
00189         static  void    set_passworddialog(password_dialogtype*);
00193 virtual        bool    create_database(const hk_string& dbase);
00199 virtual        bool    delete_database(const hk_string& dbase);
00203         bool    database_exists(const hk_string& databasename);
00210         bool set_newpassword(const hk_string& newpassword);
00216         void show_newpassworddialog(void);
00221         static void set_newpassworddialog(newpassword_dialogtype*);
00222 /*
00223  *shows a password dialog
00224  *@return false if it has been cancelled else true
00225  */
00226         bool show_passworddialog(void);
00231         virtual hk_string drivername(void) const;
00237         void set_booleanemulation(bool emulate);
00238         bool booleanemulation(void) const;
00239         hk_drivermanager* drivermanager(void);
00247         bool copy_database(hk_database* fromdatabase,bool schema_and_data,bool copy_local_files,progress_dialogtype* progressdialog=NULL);
00248         hk_string last_servermessage(void){return p_lastservermessage;}
00249         hk_string databasepath(void);
00253 static    hk_string check_capabilities(hk_connection* from,hk_connection* to);
00254 
00258 virtual hk_string mimetype(void) const {return "";}
00259 virtual unsigned int maxfieldnamesize(void) const {return (unsigned int)-1;}
00260 
00264 virtual long int maxcharsize(void) const {return 255;}
00265 
00266 
00267 
00268     protected:
00269         hk_connection(hk_drivermanager* c);
00270         bool    p_connected;
00271         virtual bool    driver_specific_connect(void){return false;}
00272         virtual bool    driver_specific_disconnect(void){return false;}
00273         virtual bool    driver_specific_rename_database(const hk_string& oldname,const hk_string& newname){return false;}
00274         virtual  vector<hk_string>* driver_specific_dblist(void){return NULL;}
00275         virtual hk_database* driver_specific_new_database(void){return NULL;}
00276         virtual bool    driver_specific_new_password(const hk_string&){return false;}
00277         virtual bool    driver_specific_delete_database(const hk_string& dbase);
00278 
00279         void    db_remove(hk_database* d);
00280         hk_string sqldelimiter(void) ;
00281         void inform_databases_connect(void);
00282         void inform_databases_disconnect(void);
00283         vector<hk_string> p_databaselist;
00287         virtual void savedata(ostream& s);
00291         virtual void loaddata(const hk_string& definition);
00292 
00293         void set_last_servermessage(const hk_string& m);
00294         hk_database* database(void) const {return p_database;}
00295         static bool internal_copy_check(hk_connection* from, hk_connection* to,support_enum);
00296         void delete_databasedirectory(const hk_string& db);
00297         void delete_directory(const hk_string& d);
00298     private:
00299         void load_configuration(void);
00300         void save_configuration(void);
00301         bool copy_local_files(hk_database* fromdb,hk_database* todb,objecttype f,progress_dialogtype* progressdialog);
00302         hk_string ask_dbname(void);
00303         void make_databasedir(const hk_string& dbname);
00304         void set_classespath(hk_string& p);
00305 
00306         hk_database* p_database;
00307         unsigned int p_debug_counter;
00308         static  password_dialogtype* p_passworddialog;
00309         static  newpassword_dialogtype* p_newpassworddialog;
00310         hk_drivermanager* p_drivermanager;
00311         hk_string   p_lastservermessage;
00312       hk_connectionprivate* p_private;
00313 } ;
00314 #endif

Generated on Tue Sep 13 02:13:09 2005 for Databaseconnectionclasses by  doxygen 1.4.4