Databaseconnectionclasses  0.5.3
hk_database.h
1 // ****************************************************************************
2 // copyright (c) 2000-2005 Horst Knorr <hk_classes@knoda.org>
3 // This file is part of the hk_classes library.
4 // This file may be distributed and/or modified under the terms of the
5 // GNU Library Public License version 2 as published by the Free Software
6 // Foundation and appearing in the file COPYING included in the
7 // packaging of this file.
8 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
9 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10 // ****************************************************************************
11 #ifndef HK_DATABASE
12 #define HK_DATABASE
13 #include <hk_class.h>
14 #include <list>
15 #include <vector>
16 #include <algorithm>
17 #include "hk_presentation.h"
18 #include "hk_url.h"
19 using namespace std;
20 
21 class hk_connection;
22 class hk_datasource;
23 class hk_data;
24 class hk_dbvisible;
25 class hk_actionquery;
26 class hk_form;
27 class hk_report;
28 class hk_dsmodevisible;
29 class hk_databaseprivate;
30 class hk_dsquery;
31 class hk_dstable;
32 
33 typedef hk_form* newform_type(hk_database*,hk_class*);
34 typedef hk_report* newreport_type(hk_database*,hk_class*);
35 typedef hk_dstable* newtable_type(hk_class*);
36 typedef hk_dsquery* newquery_type(hk_class*);
37 
48 class hk_database:public hk_class
49 {
50  friend class hk_datasource;
51  friend class hk_actionquery;
52  friend class hk_connection;
53  friend class hk_dbvisible;
54  friend class hk_presentation;
55  public:
56  virtual ~hk_database();
57  enum enum_storage{st_overwrite,st_storechanges};
58 
62 virtual bool set_name(const hk_string& n);
63  hk_string name(void);
64 
75  vector<hk_string>* tablelist(bool with_systemtable=false);
76 
77  vector<hk_string>* viewlist();
78  vector<hk_string>* tableviewlist(bool with_systemtable=false);
79 
80 
84  vector<hk_string>* querylist(void);
88  vector<hk_string>* formlist(void);
92  vector<hk_string>* reportlist(void);
93 
97  vector<hk_string>* modulelist(void);
102  hk_datasource* new_table(const hk_string& name="",hk_presentation* p=NULL);
108  hk_datasource* new_resultquery(hk_presentation* p=NULL);
114  hk_actionquery* new_actionquery(void);
115 
116 
117  hk_datasource* new_view(const hk_string& name="",hk_presentation* p=NULL);
118 
127  hk_datasource* load_datasource(const hk_string& name,datasourcetype dt=dt_table,hk_presentation* p=NULL);
128 
133 virtual bool delete_table(const hk_string& table,enum_interaction x=interactive);
134 virtual bool delete_view(const hk_string& view, enum_interaction x=interactive);
138  bool table_exists(const hk_string& tablename);
139  bool view_exists(const hk_string& viewname);
140  bool query_exists(const hk_string& queryname);
141  bool form_exists(const hk_string& formname);
142  bool report_exists(const hk_string& reportname);
143 
147  hk_connection* connection(void)const{return p_connection;}
156  ofstream* savestream(const hk_string&name,filetype type,bool ask_before_overwrite=true );
157  ofstream* savestream(const hk_string&name,filetype type,bool ask_before_overwrite,bool with_header,bool ask_for_new_name=false );
158 
159  ofstream* savestream(enum_storage storage,const hk_string&name,filetype type,bool ask_before_overwrite,bool with_header,bool ask_for_new_name);
160  STRINGSTREAM* savestringstream(filetype type);
161 
162  STRINGSTREAM* savestringstream(filetype type,bool with_header);
163 
164 
165 
172  bool delete_file(const hk_string& name,filetype type,enum_interaction x=interactive);
180  hk_presentation* existing_presentation(const hk_string& name, hk_presentation::enum_presentationtype t);
181  hk_form* existing_form(const hk_string name);
182  hk_report* existing_report(const hk_string name);
183 
190  void save(const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite=true,bool ask_for_new_name=false );
191 
192  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 );
199  hk_string load(const hk_string& name,filetype type);
200  xmlNodePtr xmlload(const hk_string& name,filetype type);
205  hk_string database_path(void);
206  hk_string fileendings(filetype e);
207  hk_string fileendings(objecttype e);
220  bool copy_table(hk_datasource* fromdatasource,bool schema_and_data,bool replacetable, bool ask,progress_dialogtype* progressdialog=NULL);
221  bool copy_view(hk_datasource* fromdatasource,progress_dialogtype* progressdialog=NULL,const hk_string& newname="");
222 
223 hk_form* new_formvisible(void);
224 hk_form* new_dialogformvisible(void);
225 hk_report* new_reportvisible(void);
226 hk_dstable* new_tablevisible(void);
227 hk_dsquery* new_queryvisible(void);
228 static void set_new_formvisiblefunction(newform_type*);
229 static void set_new_dialogformvisiblefunction(newform_type*);
230 static void set_new_reportvisiblefunction(newreport_type*);
231 static void set_new_tablevisiblefunction(newtable_type*);
232 static void set_new_queryvisiblefunction(newquery_type*);
233 void set_usewidgetparent(hk_class*);
240 bool rename_table(const hk_string& originalname, const hk_string& newname,enum_interaction x=interactive);
248 bool rename_file(const hk_string& originalname, const hk_string& newname,filetype type,enum_interaction x=interactive);
253 void disable(void);
254 
255 bool store_connectionfile(const hk_url& url, bool store_password=false);
256 
257 
258 enum enum_storagemode {central,local};
259 void set_storagemode(filetype, enum_storagemode load,enum_storagemode store);
260 enum_storagemode storagemode(filetype);
261 enum_storagemode loadmode(filetype);
262 bool create_centralstoragetable(void);
263 bool has_centralstoragetable(void);
264 hk_string load_local(const hk_string& name,filetype type);
265 hk_string load_central(const hk_string& name,filetype type);
266 xmlNodePtr xmlload_local(const hk_string& name,filetype type);
267 xmlNodePtr xmlload_central(const hk_string& name,filetype type);
268 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);
269 void save_local(const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite,bool ask_for_new_name);
270 void save_central(const hk_string& statement,const hk_string& name,filetype type,bool ask_before_overwrite,bool ask_for_new_name);
271 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);
272 bool delete_localfile(const hk_string& name,filetype type,enum_interaction x=interactive);
273 bool delete_centralfile(const hk_string& name,filetype type,enum_interaction x=interactive);
274 vector<hk_string>* filelist(filetype type);
275 vector<hk_string>* local_filelist(filetype type);
276 vector<hk_string>* central_filelist(filetype type);
277 
278 void save_configuration(void);
279 list <hk_presentation*>* presentationlist() const;
280 
281 void set_databasecharset(const hk_string& charset);
282 hk_string databasecharset(void) const;
283  void set_automatic_data_update(bool u);
284  bool is_automatic_data_update(void);
285 
286  protected:
288  bool select_db( const hk_string& newname);
289  void inform_datasources_before_closing(void);
293  virtual void driver_specific_tablelist(void){}
294  virtual void driver_specific_viewlist(void){}
295  virtual hk_datasource* driver_specific_new_table(hk_presentation* p);
296  virtual hk_datasource* driver_specific_new_view(hk_presentation* p);
297  virtual hk_datasource* driver_specific_new_resultquery(hk_presentation* p);
298  virtual hk_actionquery* driver_specific_new_actionquery(void){return NULL;}
299  virtual bool driver_specific_rename_table(const hk_string& /*oldname*/,const hk_string& /*newname*/){return false;}
300  virtual bool driver_specific_select_db(void){return false;}
301  virtual void driver_specific_set_name(void){}
302  hk_connection* p_connection;
303  void ds_remove(hk_data* ds);
304  virtual void connection_connected(void);
305  virtual void connection_disconnected(void);
306 
307  vector<hk_string> p_tablelist;
308  vector<hk_string> p_viewlist;
309  vector<hk_string> p_tableviewlist;
310  void dbvisible_add(hk_dbvisible* v);
311  void dbvisible_remove(hk_dbvisible* v);
312  void clear_visiblelist(void);
313  virtual void before_source_vanishes(void);
314  void presentation_add(hk_presentation* p);
315  void presentation_remove(hk_presentation* p);
316  void load_configuration(void);
317  virtual void savedata(ostream& s);
318  virtual void loaddata(xmlNodePtr definition);
319  hk_url p_url;
320  void inform_datasources_filelist_changes(listtype type);
321  private:
322  void clear_presentationlist();
323  bool in_presentationload(void);
324  void mark_datasources_as_not_handled(void);
325  void mark_visible_objects_as_not_handled(void);
326  hk_string savemessage(filetype t,enum_storage s, hk_string name);
327  hk_databaseprivate* p_private;
328  static newform_type *p_newformfunction;
329  static newform_type *p_newdialogformfunction;
330  static newreport_type *p_newreportfunction;
331  static newtable_type *p_newtablefunction;
332  static newquery_type *p_newqueryfunction;
333  void save_storage(ostream&,filetype);
334  void load_storage(xmlNodePtr,filetype);
335 
336 
337 } ;
338 #endif
represents a particular database on the SQL Server
Definition: hk_database.h:48
basic class for all other defined classes.
Definition: hk_class.h:52
void set_name(const hk_string &n)
Definition: hk_presentation.cpp:684
Definition: hk_dstable.h:15
Definition: hk_dsquery.h:17
connects to the SQL Server
Definition: hk_connection.h:31
base class for forms
Definition: hk_form.h:43
hk_connection * connection(void) const
Definition: hk_database.h:147
enum_interaction
Definition: hk_class.h:60
Definition: hk_url.h:17
virtual void loaddata(xmlNodePtr definition)
Definition: hk_presentation.cpp:306
void before_source_vanishes(void)
Definition: hk_presentation.cpp:452
Definition: hk_dsmodevisible.h:17
virtual void driver_specific_tablelist(void)
Definition: hk_database.h:293
virtual void savedata(ostream &s)
Definition: hk_presentation.cpp:277
base class for database depending only widgets
Definition: hk_dbvisible.h:25
represents a resultquery or a table of a database.
Definition: hk_datasource.h:45
Definition: hk_database.cpp:39
base class for multidatasource based classes like forms and reports
Definition: hk_presentation.h:40
basic class to create reports
Definition: hk_report.h:52
Base class for all kind of queries.
Definition: hk_data.h:26
Action query (i.e. ALTER TABLE) with no result.
Definition: hk_actionquery.h:29