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

hk_datasource.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_DATASOURCE
00012 #define HK_DATASOURCE
00013 //#include <hk_definitions.h>
00014 #include "hk_data.h"
00015 #include <list>
00016 #include <algorithm>
00017 #include "hk_column.h"
00018 using namespace std;
00019 
00020 class hk_database;
00021 class hk_dsvisible;
00022 class hk_presentation;
00023 class hk_qbe;
00024 class hk_actionquery;
00025 class hk_datasourceprivate;
00044 class hk_datasource:public hk_data
00045 {
00046     friend class hk_column;
00047     friend class hk_dsvisible;
00048     friend class hk_database;
00049     friend class hk_presentation;
00050     public:
00051         virtual     ~hk_datasource();
00058         virtual void    set_name(const hk_string& n,bool registerchange=true);
00059         virtual hk_string name(void);
00060         enum enum_tablemodes {mode_normal,mode_createtable,mode_altertable,mode_disabled,mode_insertrow,mode_deleterow,mode_unknown};
00067         enum_tablemodes mode(void);
00073         void    setmode_insertrow(void);
00078         void    delete_actualrow(enum_interaction c=interactive);
00082         void    setmode_normal(void);
00083 
00088         void    setmode_createtable(void);
00089 
00095         void setmode_altertable(void);
00096 
00101         hk_column* new_column(void);
00102 
00108         bool alter_column(const hk_string& col, const hk_string* name=NULL,hk_column::enum_columntype* newtype=NULL,long* size=NULL,const hk_string* defaultvalue=NULL,const bool* primary=NULL,const bool* notnull=NULL);
00113         bool delete_column(const hk_string& col);
00118         bool create_table_now(void);
00124         bool alter_table_now(void);
00125         
00126         
00127         
00128         bool create_view_now(void);
00129         bool alter_view_now(void);
00130 
00138         virtual bool    goto_row(unsigned long r);
00144         bool    goto_first(void);
00150         bool    goto_last(void);
00156         bool    goto_next(void);
00162         bool    goto_previous(void);
00166         bool    goto_random(void);
00170         unsigned long row_position(void);
00174         unsigned long max_rows(void);
00184         enum enum_accessmode {standard,batchread,batchwrite};
00185         bool set_accessmode(enum_accessmode);
00186         enum_accessmode accessmode(void) const;
00187 
00195         bool    enable(void);
00199         bool    disable(void);
00205         bool    set_enabled(bool e);
00209         bool    is_enabled(void) const;
00214         bool    is_readonly(void) const;
00218         void    set_readonly(bool r);
00224         list<hk_column*>* columns(void);
00229         hk_column* column_by_name(const hk_string& c);
00238         hk_column* column_by_name(const hk_string& c, int colnumber);
00244         int columnname_occurances(const hk_string& colname);
00248         int columnname_occurance(hk_column*);
00249 
00260         bool    set_sql(const hk_string& s,bool rawsql=false,bool registerchange=true);
00261 virtual bool    set_query(hk_qbe*,bool registerchange=true);
00262         hk_string   sql(void) const;
00263         bool    is_rawsql(void);
00264         typedef class
00265         {
00266             public:
00267                 hk_string  name;
00268                 bool    unique;
00269                 list<hk_string> fields;
00270         } indexclass;
00274         list<indexclass>* indices(void);
00275         bool index_exists(const hk_string&);
00280         bool    drop_index(const hk_string& i);
00289         bool    create_index(const hk_string& name,bool unique, list<hk_string>& fields);
00294         bool    alter_index(const hk_string& name,bool unique,list<hk_string>& fields);
00298         enum enum_dependingmodes {depending_nohandle,depending_standard,depending_change,depending_delete,depending_changedelete};
00312         enum_dependingmodes dependingmode(void);
00325         bool    set_depending_on(hk_datasource* d,bool react_on_data_changes=false,enum_dependingmodes mode=depending_standard);
00326         hk_datasource* depending_on(void);
00330         bool depending_on_react_on_data_changes(void);
00334         list<hk_string>* depending_on_thisfields(void);
00338         list<hk_string>* depending_on_masterfields(void);
00346         bool   set_depending_on_presentationdatasource(long d,bool react_on_data_changes=false,enum_dependingmodes mode=depending_standard,bool registerchange=true);
00347         long    depending_on_presentationdatasource(void);
00355         void    add_depending_fields(const hk_string& this_ds_field, const hk_string& master_ds_field,bool registerchange=true);
00359         void    clear_depending_fields(bool registerchange=true);
00365         bool    store_changed_data(enum_interaction c=interactive);
00366         void    set_ignore_changed_data(void);
00367         bool   ignore_changed_data(void) const;
00377         void    set_filter(const hk_string& f,bool registerchange=true);
00378         hk_string filter(void);
00383         void set_temporaryfilter(const hk_string&f);
00384         hk_string temporaryfilter(void);
00385         void set_use_temporaryfilter(bool use);
00386         bool use_temporaryfilter(void);
00387 /*
00388 *hk_classes internal use only, don't use the function set_internalfilter
00389 */
00390         void set_internalfilter(const hk_string&f);
00391         hk_string internalfilter(void);
00392         void set_use_internalfilter(bool use);
00393         bool use_internalfilter(void);
00394 
00395 
00401         void    clear_filter(bool registerchange=true);
00410         void    set_sorting(const hk_string& s,bool registerchange=true);
00411         hk_string sorting(void);
00412         void set_temporarysorting(const hk_string& s);
00413         hk_string temporarysorting(void);
00414         void set_use_temporarysorting(bool use);
00415         bool use_temporarysorting(void);
00416 
00422         void    clear_sorting(bool registerchange=true);
00430         void    set_automatic_data_update(bool u);
00431         bool    is_automatic_data_update(void);
00432         void    set_sqldelimiter(const hk_string&);
00436         void    set_datetimeformat(const hk_string& datetime,const hk_string& date,const hk_string& time)
00437         {
00438             p_datetimeformat=datetime;
00439             p_dateformat=date;
00440             p_timeformat=time;
00441         }
00442 
00443         hk_database* database(void);
00480         void  savedata(ostream& s,bool saveall=true);
00484         void  loaddata(const hk_string& definition,bool loadsql=true);
00489 //      bool    savequerytofile(void);
00494 //      bool    loadqueryfromfile(void);
00500         long  presentationnumber(void) const {return p_dscounter;}
00505         bool  datasource_used(void) const;
00506 #ifdef HK_DEBUG
00507 
00511         virtual        void   dump_data() ;
00512 #endif
00513 
00516         bool ask_name(void);
00520         bool delete_rows(unsigned long from,unsigned long to,bool check_depending_datasources=true,bool ask=true);
00525         void transaction_begin(hk_string name="");
00530         void transaction_commit(hk_string name="");
00536         void transaction_rollback(hk_string name="");
00537 
00542         void set_blockvisiblesignals(bool v);
00543         bool blockvisiblesignals(void);
00548         void set_blockserversignals(bool);
00549         bool blockserversignals(void);
00554         void set_blockdatasourcesignals(bool);
00555         bool blockdatasourcesignals(void);
00559         void save_datasourcedefinition(ostream& s);
00563         bool load_datasourcedefinition(const hk_string& definition,bool use_xmltablename=true ,bool ask=true);
00564 hk_presentation* presentation(void);
00568  void set_position(int x,int y, bool registerchange=true);
00572  void set_size(int width,int height, bool registerchange=true);
00573  int x(void) const;
00574  int y(void) const;
00575  int width(void) const;
00576  int height(void) const;
00577  void set_designsize(int w,int h,bool registerchange=true);
00578  int designwidth() const;
00579  int designheight() const;
00580  void   automatic_position_datasource(void);
00581 
00582 list<hk_datasource*>* dependinglist(void);
00586   bool previous_enable_problems(void) const;
00587 
00588 list <referentialclass>* referenceslist(void);
00589 
00590 bool  add_reference(const referentialclass&);
00591 bool  drop_reference(const hk_string&);
00592 
00593 
00594 hk_string fieldorigin(const hk_string&);    
00595 void    reset_changed_data(void);
00596 bool has_changed(void) const;    
00597     
00598     protected:
00603         bool p_casesensitive;
00604         hk_datasource(hk_database* db,hk_presentation* p=NULL);
00605         void    column_remove(hk_column* col);
00606         void    visible_add(hk_dsvisible* v);
00607         void    visible_remove(hk_dsvisible* v);
00608         virtual void driver_specific_transaction_begin(hk_string);
00609         virtual void driver_specific_transaction_commit(hk_string);
00610         virtual void driver_specific_transaction_rollback(hk_string);
00611         virtual unsigned long driver_specific_max_rows(void){return 0;}
00612         virtual bool driver_specific_set_accessmode(enum_accessmode){return true;}
00613         virtual bool driver_specific_batch_enable(void){return false;}
00614         virtual bool driver_specific_batch_disable(void){return false;}
00615         virtual bool driver_specific_batch_goto_next(void){return false;}
00616         virtual bool driver_specific_batch_goto_previous(void){return false;}
00621         virtual bool    driver_specific_enable(void){return false;}
00622         virtual bool    driver_specific_disable(void){return false;}
00629         virtual list<hk_column*>* driver_specific_columns(void){return NULL;}
00630         virtual bool    driver_specific_goto_row(unsigned long r);
00631         virtual hk_column* driver_specific_new_column(void){return NULL;}
00632         virtual bool    driver_specific_update_data(void){return true;}
00633         virtual bool    driver_specific_delete_data_at(unsigned long){return true;}
00634         virtual bool    driver_specific_insert_data(void){return true;}
00635         virtual bool    driver_specific_create_table_now(void){return false;}
00636         virtual bool    driver_specific_alter_table_now(void){return false;}
00637         virtual bool    driver_specific_create_view_now(void);
00638         virtual bool    driver_specific_alter_view_now(void);
00639         
00640         virtual void    driver_specific_before_drop_table(void){}
00641         virtual void    filelist_changes(listtype t);
00642         virtual list<indexclass>* driver_specific_indices(void){return NULL;}
00643         virtual bool    driver_specific_drop_index(const hk_string& i);
00644         virtual bool    driver_specific_create_index(const hk_string& name,bool unique,list<hk_string>& fields);
00645         virtual void before_connection_disconnects(void);
00646         virtual void before_source_vanishes(void);
00650         virtual void driver_specific_after_copy_table(){}
00651         virtual bool driver_specific_load_view(){return false;}
00652         virtual void driver_specific_create_viewsql(){}// used for ds_view 
00653         virtual bool driver_specific_add_reference(const referentialclass &);
00654         virtual bool driver_specific_drop_reference(const hk_string& );
00655         virtual void driver_specific_referenceslist(void);
00656         void    depending_ds_add(hk_datasource* d);
00657         void    depending_ds_remove(hk_datasource* d);
00658         void    depending_on_datasource_row_change(bool take_changed_data=false);
00659         void    depending_on_datasource_data_has_changed(void);
00660         void    depending_on_datasource_after_store_changed_data(void);
00661         void    depending_on_datasource_insertmode(void);
00662         bool   depending_on_datasource_deleterow_ok(void);
00663         bool   depending_on_datasource_before_delete_row(void);
00664         bool   depending_on_datasource_updaterow_ok(void);
00665         void   depending_on_datasource_before_update_row(void);
00666         void   depending_on_datasource_after_update_row(void);
00667         void    reload_data(bool take_changed_data=false);
00668         void    create_actual_row_where_statement(void);
00669         hk_string create_row_where_statement_at(unsigned long int position,bool withwhere=true);
00670         void    create_new_sql_statement(bool take_changed_data=false);
00671         hk_string whole_datasource_where_statement(bool take_changed_data=false);
00672         void print_sql(void);
00673 
00674         bool    p_enabled;
00675         bool    p_readonly;
00676         bool    p_primary_key_used;
00677         bool    p_ignore_changed_data;
00678         void    clear_columnlist(void);
00679         void    clear_modecolumnlists(void);
00680         void    clear_visiblelist(void);
00681         void    parse_sql(void);
00682         virtual bool    update_row(enum_interaction c=interactive);
00683         virtual bool    insert_row(enum_interaction c=interactive);
00684         virtual bool    delete_row(enum_interaction c=interactive);
00685         unsigned long   p_counter;                // actual row number
00686         hk_database*    p_database;
00687         list<hk_column*>*      p_columns;
00688         typedef class
00689         {
00690             public:
00691                 hk_string name;
00692                 hk_string newname;
00693                 hk_column::enum_columntype type;
00694                 long size;
00695                 hk_string defaultvalue;
00696                 bool primary;
00697                 bool notnull;
00698         } class_altercolumns;
00699         list<class_altercolumns>       p_altercolumns;
00700         list<hk_string>       p_deletecolumns;
00701         list<hk_column*>       p_newcolumns;
00702         list<hk_string> depending_this_fields;
00703         list<hk_string> depending_master_fields;
00704 
00705        typedef class fieldoriginclass
00706        {
00707          public:
00708          hk_string fieldname;
00709          hk_string alias;
00710          fieldoriginclass()
00711           {
00712           }
00713          bool operator=(const fieldoriginclass& o)
00714            {
00715              fieldname=o.fieldname;
00716              alias=o.alias;
00717              return true;
00718            }
00719        };
00720 
00724         typedef class
00725         {
00726             public:
00727                 hk_string
00728                     select_part,
00729                     from_part,
00730                     where_part,
00731                     groupby_part,
00732                     having_part,
00733                     orderby_part ;
00734                     list <fieldoriginclass> fieldpart;
00735         } struct_parsed_sql;
00736         struct_parsed_sql* p_parsed_sql;
00737         void parse_fieldpart(void);
00738         hk_string   p_sql;
00739         hk_string   p_viewsql;
00740         hk_string  p_actual_row_where;
00741         bool    p_automatic_data_update;
00742         hk_actionquery* p_actionquery;
00743         hk_string p_datetimeformat;
00744         hk_string p_dateformat;
00745         hk_string p_timeformat;
00746         hk_string   p_sql_delimiter;
00747         hk_string       p_true;
00748         hk_string       p_false;
00749 
00750         bool    p_tablesql_set;
00751         void set_has_changed(void);
00752         void set_has_not_changed(void);
00753         hk_string delimit_identifier(const hk_string&);
00754      
00755     private:
00756 
00757         enum_tablemodes p_mode;
00758         hk_string   p_original_sql;
00759         unsigned long p_length;
00760         bool    p_has_changed;
00761         list<hk_dsvisible*> p_visibles;
00762         list<hk_datasource*> p_dependinglist;
00763         hk_datasource*  p_depending_on_datasource;
00764         bool    p_depending_on_datasource_react_on_changed_data;
00765         void    inform_before_row_change(void);
00766         void    inform_visible_objects_before_store_changed_data(void);
00767         void    inform_visible_objects_after_store_changed_data(void);
00768         void    inform_visible_objects_row_change(void);
00769         void    inform_visible_objects_row_add(void);
00770         void    inform_visible_objects_row_delete(void);
00771         void    inform_visible_objects_before_insert_row(void);
00772         void    inform_before_enable(void);
00773         void    inform_before_disable(void);
00774         void    inform_visible_objects_ds_disable(void);
00775         void    inform_visible_objects_ds_enable(void);
00776         void    inform_depending_ds_goto_row(void);
00777         void    inform_depending_ds_store_data(void);
00778         void    inform_depending_ds_data_has_changed(void);
00779         void    inform_depending_ds_after_store_changed_data(void);
00780         void    inform_depending_ds_disable(void);
00781         void    inform_depending_ds_enable(void);
00782         void    inform_depending_ds_insertmode(void);
00783         void    inform_visible_objects_new_columns_created(void);
00784         void    inform_visible_objects_before_columns_deleted(void);
00785         void    inform_visible_objects_insertmode(void);
00786         void    inform_when_table_structure_changes(void);
00787         void    inform_when_indexlist_changes(void);
00788         void    mark_visible_objects_as_not_handled(void);
00789         void execute_visible_object_script_before_update(void);
00790         void execute_visible_object_script_after_update(void);
00791         void execute_visible_object_before_row_change(void);
00792         void execute_visible_object_after_row_change(void);
00793         void execute_visible_object_before_delete(void);
00794         void execute_visible_object_after_delete(void);
00795         void execute_visible_object_before_insert(void);
00796         void execute_visible_object_after_insert(void);
00797         hk_presentation* p_presentation;
00798 // unique number given from a hk_presentation object
00799         long    p_dscounter;
00800 
00801         hk_datasourceprivate* p_private;
00802 }
00803 
00804 
00805 ;
00806 #endif

Generated on Tue Mar 22 20:01:12 2005 for Databaseconnectionclasses by  doxygen 1.4.1