hk_database.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_DATABASE
00012 #define HK_DATABASE
00013 #include <hk_class.h>
00014 #include <list>
00015 #include <vector>
00016 #include <algorithm>
00017 #include "hk_presentation.h"
00018 #include "hk_url.h"
00019 using namespace std;
00020 
00021 class hk_connection;
00022 class hk_datasource;
00023 class hk_data;
00024 class hk_dbvisible;
00025 class hk_actionquery;
00026 class hk_form;
00027 class hk_report;
00028 class hk_dsmodevisible;
00029 class hk_databaseprivate;
00030 class hk_dsquery;
00031 class hk_dstable;
00032 
00033 typedef hk_form* newform_type(hk_database*,hk_class*);
00034 typedef hk_report* newreport_type(hk_database*,hk_class*);
00035 typedef hk_dstable* newtable_type(hk_class*);
00036 typedef hk_dsquery* newquery_type(hk_class*);
00037 
00048 class hk_database:public hk_class
00049 {
00050     friend class hk_datasource;
00051     friend class hk_actionquery;
00052     friend class hk_connection;
00053     friend class hk_dbvisible;
00054     friend class hk_presentation;
00055     public:
00056         virtual     ~hk_database();
00057         enum enum_storage{st_overwrite,st_storechanges};
00058 
00062 virtual bool    set_name(const hk_string& n);
00063         hk_string   name(void);
00064 
00075         vector<hk_string>* tablelist(bool with_systemtable=false);
00076 
00077         vector<hk_string>* viewlist();
00078         vector<hk_string>* tableviewlist(bool with_systemtable=false);
00079 
00080 
00084         vector<hk_string>* querylist(void);
00088         vector<hk_string>* formlist(void);
00092         vector<hk_string>* reportlist(void);
00093 
00097         vector<hk_string>* modulelist(void);
00102         hk_datasource* new_table(const hk_string& name="",hk_presentation* p=NULL);
00108         hk_datasource* new_resultquery(hk_presentation* p=NULL);
00114         hk_actionquery*   new_actionquery(void);
00115 
00116 
00117         hk_datasource* new_view(const hk_string& name="",hk_presentation* p=NULL);
00118 
00127         hk_datasource*  load_datasource(const hk_string& name,datasourcetype dt=dt_table,hk_presentation* p=NULL);
00128 
00133 virtual bool    delete_table(const hk_string& table,enum_interaction x=interactive);
00134 virtual bool    delete_view(const hk_string& view, enum_interaction x=interactive);
00138         bool    table_exists(const hk_string& tablename);
00139         bool    view_exists(const hk_string& viewname);
00140         bool    query_exists(const hk_string& queryname);
00141         bool    form_exists(const hk_string& formname);
00142         bool    report_exists(const hk_string& reportname);
00143 
00147         hk_connection*  connection(void)const{return p_connection;}
00156         ofstream* savestream(const hk_string&name,filetype type,bool ask_before_overwrite=true );
00157         ofstream* savestream(const hk_string&name,filetype type,bool ask_before_overwrite,bool with_header,bool ask_for_new_name=false );
00158         
00159         ofstream* savestream(enum_storage storage,const hk_string&name,filetype type,bool ask_before_overwrite,bool with_header,bool ask_for_new_name);
00160     STRINGSTREAM* savestringstream(filetype type);
00161 
00162     STRINGSTREAM* savestringstream(filetype type,bool with_header);
00163 
00164 
00165 
00172         bool  delete_file(const hk_string& name,filetype type,enum_interaction x=interactive);
00180         hk_presentation* existing_presentation(const hk_string& name, hk_presentation::enum_presentationtype t);
00181         hk_form* existing_form(const hk_string name);
00182         hk_report* existing_report(const hk_string name);
00183 
00190         void save(const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite=true,bool ask_for_new_name=false );
00191         
00192         void save(enum_storage storage,const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite=true,bool ask_for_new_name=false );
00199         hk_string load(const hk_string& name,filetype type);
00200         xmlNodePtr xmlload(const hk_string& name,filetype type);
00205         hk_string database_path(void);
00206         hk_string fileendings(filetype e);
00207         hk_string fileendings(objecttype e);
00220         bool copy_table(hk_datasource* fromdatasource,bool schema_and_data,bool replacetable, bool ask,progress_dialogtype* progressdialog=NULL);
00221         bool copy_view(hk_datasource* fromdatasource,progress_dialogtype* progressdialog=NULL,const hk_string& newname="");
00222 
00223 hk_form* new_formvisible(void);
00224 hk_form* new_dialogformvisible(void);
00225 hk_report* new_reportvisible(void);
00226 hk_dstable* new_tablevisible(void);
00227 hk_dsquery* new_queryvisible(void);
00228 static void     set_new_formvisiblefunction(newform_type*);
00229 static void     set_new_dialogformvisiblefunction(newform_type*);
00230 static void     set_new_reportvisiblefunction(newreport_type*);
00231 static void     set_new_tablevisiblefunction(newtable_type*);
00232 static void     set_new_queryvisiblefunction(newquery_type*);
00233 void set_usewidgetparent(hk_class*);
00240 bool rename_table(const hk_string& originalname, const hk_string& newname,enum_interaction x=interactive);
00248 bool rename_file(const hk_string& originalname, const hk_string& newname,filetype type,enum_interaction x=interactive);
00253 void disable(void);
00254 
00255 bool store_connectionfile(const hk_url& url, bool store_password=false);
00256 
00257 
00258 enum enum_storagemode {central,local};
00259 void set_storagemode(filetype, enum_storagemode load,enum_storagemode store);
00260 enum_storagemode storagemode(filetype);
00261 enum_storagemode loadmode(filetype);
00262 bool create_centralstoragetable(void);
00263 bool has_centralstoragetable(void);
00264 hk_string load_local(const hk_string& name,filetype type);
00265 hk_string load_central(const hk_string& name,filetype type);
00266 xmlNodePtr xmlload_local(const hk_string& name,filetype type);
00267 xmlNodePtr xmlload_central(const hk_string& name,filetype type);
00268 void save_local(enum_storage storage,const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite,bool ask_for_new_name);
00269 void save_local(const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite,bool ask_for_new_name);
00270 void save_central(const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite,bool ask_for_new_name);
00271 void save_central(enum_storage storage,const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite,bool ask_for_new_name);
00272 bool  delete_localfile(const hk_string& name,filetype type,enum_interaction x=interactive);
00273 bool  delete_centralfile(const hk_string& name,filetype type,enum_interaction x=interactive);
00274 vector<hk_string>* filelist(filetype type);
00275 vector<hk_string>* local_filelist(filetype type);
00276 vector<hk_string>* central_filelist(filetype type);
00277 
00278 void save_configuration(void);
00279 list <hk_presentation*>* presentationlist() const;
00280 
00281 void set_databasecharset(const hk_string& charset);
00282 hk_string databasecharset(void) const;
00283         void    set_automatic_data_update(bool u);
00284         bool    is_automatic_data_update(void);
00285 
00286     protected:
00287         hk_database(hk_connection* c);
00288         bool    select_db( const hk_string& newname);
00289         void inform_datasources_before_closing(void);
00293         virtual  void driver_specific_tablelist(void){}
00294         virtual  void driver_specific_viewlist(void){}
00295         virtual hk_datasource* driver_specific_new_table(hk_presentation* p);
00296         virtual hk_datasource* driver_specific_new_view(hk_presentation* p);
00297         virtual hk_datasource* driver_specific_new_resultquery(hk_presentation* p);
00298         virtual hk_actionquery*   driver_specific_new_actionquery(void){return NULL;}
00299         virtual bool    driver_specific_rename_table(const hk_string& /*oldname*/,const hk_string& /*newname*/){return false;}
00300         virtual bool driver_specific_select_db(void){return false;}
00301         virtual void driver_specific_set_name(void){}
00302         hk_connection* p_connection;
00303         void    ds_remove(hk_data* ds);
00304         virtual void connection_connected(void);
00305         virtual void connection_disconnected(void);
00306 
00307         vector<hk_string> p_tablelist;
00308         vector<hk_string> p_viewlist;
00309         vector<hk_string> p_tableviewlist;
00310         void    dbvisible_add(hk_dbvisible* v);
00311         void    dbvisible_remove(hk_dbvisible* v);
00312         void    clear_visiblelist(void);
00313         virtual void before_source_vanishes(void);
00314         void    presentation_add(hk_presentation* p);
00315         void    presentation_remove(hk_presentation* p);
00316         void load_configuration(void);
00317         virtual void savedata(ostream& s);
00318         virtual void loaddata(xmlNodePtr definition);
00319         hk_url p_url;
00320         void inform_datasources_filelist_changes(listtype type);
00321     private:
00322         void clear_presentationlist();
00323         bool in_presentationload(void);
00324         void mark_datasources_as_not_handled(void);
00325         void mark_visible_objects_as_not_handled(void);
00326         hk_string savemessage(filetype t,enum_storage s, hk_string name);
00327         hk_databaseprivate* p_private;
00328         static newform_type *p_newformfunction;
00329         static newform_type *p_newdialogformfunction;
00330         static newreport_type *p_newreportfunction;
00331         static newtable_type *p_newtablefunction;
00332         static newquery_type *p_newqueryfunction;
00333         void save_storage(ostream&,filetype);
00334         void load_storage(xmlNodePtr,filetype);
00335 
00336 
00337 } ;
00338 #endif

Generated on Tue Nov 28 02:48:08 2006 for Databaseconnectionclasses by  doxygen 1.5.0