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

hk_classes/hk_classes/hk_connection.h

Go to the documentation of this file.
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             SUPPORTS_SQL_SUBSELECTS=185,
00153 
00154             SUPPORTS_LOCAL_FILEFORMAT=200,
00155             SUPPORTS_NONALPHANUM_FIELDNAMES=201, // if not set field name can only have [a-zA-Z0-9]
00156             SUPPORTS_NONASCII_FIELDNAMES=202, //unicode characters etc
00157             SUPPORTS_SPACE_FIELDNAMES=203 // means  a space character can be part
00158         };
00159 
00163         virtual bool server_supports(support_enum) const{return false;}
00167         enum need_enum
00168         {
00169 
00170             NEEDS_LOGIN=0,
00171             NEEDS_HOST=1,
00172             NEEDS_USERNAME=2,
00173             NEEDS_PASSWORD=3,
00174             NEEDS_SQLDELIMITER=4,
00175             NEEDS_PORT=5,
00176             NEEDS_DATABASENAME=6,
00177             NEEDS_BOOLEANEMULATION=7,//e.g. Mysql  doesn't have natively a boolean type, so tinyint is used
00178             NEEDS_NULL_TERMINATED_SQL=8, //e.g. Postgres needs null terminated strings in PQExec
00179             NEEDS_TABLE_ALIAS_AS=9, // set if the server needs 'AS' between the table name and its alias name in a FROM clause
00180             NEEDS_MANUAL_CHARSET=10 // per database  see hk_database::set_databasecharset
00181         };
00185         virtual bool server_needs(need_enum) const {return false;}
00191         static  void    set_passworddialog(password_dialogtype*);
00195 virtual        bool    create_database(const hk_string& dbase);
00201 virtual        bool    delete_database(const hk_string& dbase);
00205         bool    database_exists(const hk_string& databasename);
00212         bool set_newpassword(const hk_string& newpassword);
00218         void show_newpassworddialog(void);
00223         static void set_newpassworddialog(newpassword_dialogtype*);
00224 /*
00225  *shows a password dialog
00226  *@return false if it has been cancelled else true
00227  */
00228         bool show_passworddialog(void);
00233         virtual hk_string drivername(void) const;
00239         void set_booleanemulation(bool emulate);
00240         bool booleanemulation(void) const;
00241         hk_drivermanager* drivermanager(void);
00249         bool copy_database(hk_database* fromdatabase,bool schema_and_data,bool copy_local_files,progress_dialogtype* progressdialog=NULL);
00250         hk_string last_servermessage(void){return p_lastservermessage;}
00251         hk_string databasepath(void);
00255 static    hk_string check_capabilities(hk_connection* from,hk_connection* to);
00256 
00260 virtual hk_string mimetype(void) const {return "";}
00261 virtual unsigned int maxfieldnamesize(void) const {return (unsigned int)-1;}
00262 
00266 virtual long int maxcharsize(void) const {return 255;}
00267 
00268 
00269 
00270     protected:
00271         hk_connection(hk_drivermanager* c);
00272         bool    p_connected;
00273         virtual bool    driver_specific_connect(void){return false;}
00274         virtual bool    driver_specific_disconnect(void){return false;}
00275         virtual bool    driver_specific_rename_database(const hk_string& oldname,const hk_string& newname){return false;}
00276         virtual  vector<hk_string>* driver_specific_dblist(void){return NULL;}
00277         virtual hk_database* driver_specific_new_database(void){return NULL;}
00278         virtual bool    driver_specific_new_password(const hk_string&){return false;}
00279         virtual bool    driver_specific_delete_database(const hk_string& dbase);
00280 
00281         void    db_remove(hk_database* d);
00282         hk_string sqldelimiter(void) ;
00283         void inform_databases_connect(void);
00284         void inform_databases_disconnect(void);
00285         vector<hk_string> p_databaselist;
00289         virtual void savedata(ostream& s);
00293         virtual void loaddata(const hk_string& definition);
00294 
00295         void set_last_servermessage(const hk_string& m);
00296         hk_database* database(void) const {return p_database;}
00297         static bool internal_copy_check(hk_connection* from, hk_connection* to,support_enum);
00298         void delete_databasedirectory(const hk_string& db);
00299         void delete_directory(const hk_string& d);
00300     private:
00301         void load_configuration(void);
00302         void save_configuration(void);
00303         bool copy_local_files(hk_database* fromdb,hk_database* todb,objecttype f,progress_dialogtype* progressdialog);
00304         hk_string ask_dbname(void);
00305         void make_databasedir(const hk_string& dbname);
00306         void set_classespath(hk_string& p);
00307 
00308         hk_database* p_database;
00309         unsigned int p_debug_counter;
00310         static  password_dialogtype* p_passworddialog;
00311         static  newpassword_dialogtype* p_newpassworddialog;
00312         hk_drivermanager* p_drivermanager;
00313         hk_string   p_lastservermessage;
00314       hk_connectionprivate* p_private;
00315 } ;
00316 #endif

Generated on Thu Mar 9 18:40:40 2006 for hk_classes by  doxygen 1.4.1