00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef HK_DATASOURCE
00012 #define HK_DATASOURCE
00013
00014 #include "hk_data.h"
00015 #include <list>
00016 #include <utility>
00017 #include <algorithm>
00018 #include "hk_column.h"
00019 using namespace std;
00020
00021 class hk_database;
00022 class hk_dsvisible;
00023 class hk_presentation;
00024 class hk_qbe;
00025 class hk_actionquery;
00026 class hk_datasourceprivate;
00045 class hk_datasource:public hk_data
00046 {
00047 friend class hk_column;
00048 friend class hk_dsvisible;
00049 friend class hk_database;
00050 friend class hk_presentation;
00051 public:
00052 virtual ~hk_datasource();
00059 virtual void set_name(const hk_string& n,bool registerchange=true);
00060 virtual hk_string name(void);
00061 enum enum_tablemodes {mode_normal,mode_createtable,mode_altertable,mode_disabled,mode_insertrow,mode_deleterow,mode_unknown};
00068 enum_tablemodes mode(void);
00074 void setmode_insertrow(void);
00079 void delete_actualrow(enum_interaction c=interactive);
00083 void setmode_normal(void);
00084
00089 void setmode_createtable(void);
00090
00096 void setmode_altertable(void);
00097
00102 hk_column* new_column(void);
00103
00109 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);
00114 bool delete_column(const hk_string& col);
00119 bool create_table_now(void);
00125 bool alter_table_now(void);
00126
00127
00128
00129 bool create_view_now(void);
00130 bool alter_view_now(void);
00131
00139 virtual bool goto_row(unsigned long r);
00140 bool while_goto_row(void) const;
00141
00147 bool goto_first(void);
00153 bool goto_last(void);
00159 bool goto_next(void);
00165 bool goto_previous(void);
00169 bool goto_random(void);
00173 unsigned long row_position(void);
00177 unsigned long max_rows(void);
00187 enum enum_accessmode {standard,batchread,batchwrite};
00188 bool set_accessmode(enum_accessmode);
00189 enum_accessmode accessmode(void) const;
00190
00198 bool enable(void);
00199 bool while_enabling(void) const;
00203 bool disable(void);
00204 bool while_disabling(void) const;
00210 bool set_enabled(bool e);
00214 bool is_enabled(void) const;
00219 bool is_readonly(void) const;
00223 void set_readonly(bool r);
00229 list<hk_column*>* columns(void);
00230 list<hk_string>* columnnames(void);
00235 hk_column* column_by_name(const hk_string& c);
00244 hk_column* column_by_name(const hk_string& c, int colnumber);
00250 int columnname_occurances(const hk_string& colname);
00254 int columnname_occurance(hk_column*);
00255
00266 bool set_sql(const hk_string& s,bool rawsql=false,bool registerchange=true);
00267 virtual bool set_query(hk_qbe*,bool registerchange=true);
00268 hk_string sql(void) const;
00269 bool is_rawsql(void);
00273 hk_string backendsql(void) const;
00274 typedef class
00275 {
00276 public:
00277 hk_string name;
00278 bool unique;
00279 list<hk_string> fields;
00280 } indexclass;
00284 list<indexclass>* indices(void);
00285 bool index_exists(const hk_string&);
00290 bool drop_index(const hk_string& i);
00299 bool create_index(const hk_string& name,bool unique, list<hk_string>& fields);
00304 bool alter_index(const hk_string& name,bool unique,list<hk_string>& fields);
00308 enum enum_dependingmodes {depending_nohandle,depending_standard,depending_change,depending_delete,depending_changedelete};
00322 enum_dependingmodes dependingmode(void);
00335 bool set_depending_on(hk_datasource* d,bool react_on_data_changes=false,enum_dependingmodes mode=depending_standard);
00336 hk_datasource* depending_on(void);
00340 bool depending_on_react_on_data_changes(void);
00344 list<hk_string>* depending_on_thisfields(void);
00348 list<hk_string>* depending_on_masterfields(void);
00356 bool set_depending_on_presentationdatasource(long d,bool react_on_data_changes=false,enum_dependingmodes mode=depending_standard,bool registerchange=true);
00357 long depending_on_presentationdatasource(void);
00365 void add_depending_fields(const hk_string& this_ds_field, const hk_string& master_ds_field,bool registerchange=true);
00369 void clear_depending_fields(bool registerchange=true);
00375 bool store_changed_data(enum_interaction c=interactive);
00376 void set_ignore_changed_data(void);
00377 bool ignore_changed_data(void) const;
00387 void set_filter(const hk_string& f,bool registerchange=true);
00388 hk_string filter(void);
00393 void set_temporaryfilter(const hk_string&f);
00394 hk_string temporaryfilter(void);
00395 void set_use_temporaryfilter(bool use);
00396 bool use_temporaryfilter(void);
00397
00398
00399
00400 void set_internalfilter(const hk_string&f);
00401 hk_string internalfilter(void);
00402 void set_use_internalfilter(bool use);
00403 bool use_internalfilter(void);
00404
00405
00411 void clear_filter(bool registerchange=true);
00420 void set_sorting(const hk_string& s,bool registerchange=true);
00421 hk_string sorting(void);
00422 void set_temporarysorting(const hk_string& s);
00423 hk_string temporarysorting(void);
00424 void set_use_temporarysorting(bool use);
00425 bool use_temporarysorting(void);
00426
00432 void clear_sorting(bool registerchange=true);
00440 void set_automatic_data_update(bool u);
00441 bool is_automatic_data_update(void);
00442
00443 void set_sqldelimiter(const hk_string&);
00447 void set_datetimeformat(const hk_string& datetime,const hk_string& date,const hk_string& time)
00448 {
00449 p_datetimeformat=datetime;
00450 p_dateformat=date;
00451 p_timeformat=time;
00452 }
00453
00454 hk_database* database(void);
00491 void savedata(ostream& s,bool saveall=true);
00495 void loaddata(const hk_string& definition,bool loadsql=true);
00500
00505
00511 long presentationnumber(void) const {return p_dscounter;}
00516 bool datasource_used(void) const;
00517 #ifdef HK_DEBUG
00518
00522 virtual void dump_data() ;
00523 #endif
00524
00527 bool ask_name(void);
00531 bool delete_rows(unsigned long from,unsigned long to,bool check_depending_datasources=true,bool ask=true);
00536 void transaction_begin(hk_string name="");
00541 void transaction_commit(hk_string name="");
00547 void transaction_rollback(hk_string name="");
00548
00553 void set_blockvisiblesignals(bool v);
00554 bool blockvisiblesignals(void);
00559 void set_blockserversignals(bool);
00560 bool blockserversignals(void);
00565 void set_blockdatasourcesignals(bool);
00566 bool blockdatasourcesignals(void);
00570 void save_datasourcedefinition(ostream& s);
00574 bool load_datasourcedefinition(const hk_string& definition,bool use_xmltablename=true ,bool ask=true);
00575 hk_presentation* presentation(void);
00579 void set_position(int x,int y, bool registerchange=true);
00583 void set_size(int width,int height, bool registerchange=true);
00584 int x(void) const;
00585 int y(void) const;
00586 int width(void) const;
00587 int height(void) const;
00588 void set_designsize(int w,int h,bool registerchange=true);
00589 int designwidth() const;
00590 int designheight() const;
00591 void automatic_position_datasource(void);
00592
00593 list<hk_datasource*>* dependinglist(void);
00597 bool previous_enable_problems(void) const;
00598
00599 list <referentialclass>* referenceslist(void);
00603 bool add_reference(const referentialclass&);
00604 bool drop_reference(const hk_string&);
00605
00606
00607 hk_string fieldorigin(const hk_string&);
00608 hk_string totalfieldorigin(const hk_string&);
00609 void reset_changed_data(void);
00610 bool has_changed(void) const;
00614 hk_string systemcolumnname(const hk_string& n);
00615
00616 static void set_enablefunction(voidfunction*, long counter);
00617
00618 bool depending_on_datasource_deleterow_ok(void);
00619 bool depending_on_datasource_before_delete_row(void);
00620 bool depending_on_datasource_updaterow_ok(void);
00621 bool check_store_changed_data();
00622
00623
00624
00625
00626
00627
00628 protected:
00633 bool p_casesensitive;
00634 hk_datasource(hk_database* db,hk_presentation* p=NULL);
00635 void column_remove(hk_column* col);
00636 void visible_add(hk_dsvisible* v);
00637 void visible_remove(hk_dsvisible* v);
00638 virtual void driver_specific_transaction_begin(hk_string);
00639 virtual void driver_specific_transaction_commit(hk_string);
00640 virtual void driver_specific_transaction_rollback(hk_string);
00641 virtual unsigned long driver_specific_max_rows(void){return 0;}
00642 virtual bool driver_specific_set_accessmode(enum_accessmode){return true;}
00643 virtual bool driver_specific_batch_enable(void){return false;}
00644 virtual bool driver_specific_batch_disable(void){return false;}
00645 virtual bool driver_specific_batch_goto_next(void){return false;}
00646 virtual bool driver_specific_batch_goto_previous(void){return false;}
00651 virtual bool driver_specific_enable(void){return false;}
00652 virtual bool driver_specific_disable(void){return false;}
00659 virtual list<hk_column*>* driver_specific_columns(void){return NULL;}
00660 virtual bool driver_specific_goto_row(unsigned long r);
00661 virtual hk_column* driver_specific_new_column(void){return NULL;}
00662 virtual bool driver_specific_update_data(void){return true;}
00663 virtual bool driver_specific_delete_data_at(unsigned long){return true;}
00664 virtual bool driver_specific_insert_data(void){return true;}
00665 virtual bool driver_specific_create_table_now(void){return false;}
00666 virtual bool driver_specific_alter_table_now(void){return false;}
00667 virtual bool driver_specific_create_view_now(void);
00668 virtual bool driver_specific_alter_view_now(void);
00669
00670 virtual void driver_specific_before_drop_table(void){}
00671 virtual void filelist_changes(listtype t);
00672 virtual list<indexclass>* driver_specific_indices(void){return NULL;}
00673 virtual bool driver_specific_drop_index(const hk_string& i);
00674 virtual bool driver_specific_create_index(const hk_string& name,bool unique,list<hk_string>& fields);
00675 virtual void before_connection_disconnects(void);
00676 virtual void before_source_vanishes(void);
00680 virtual void driver_specific_after_copy_table(){}
00681 virtual bool driver_specific_load_view(){return false;}
00682 virtual void driver_specific_create_viewsql(){}
00683 virtual bool driver_specific_add_reference(const referentialclass &);
00684 virtual bool driver_specific_drop_reference(const hk_string& );
00685 virtual void driver_specific_referenceslist(void);
00686 void depending_ds_add(hk_datasource* d);
00687 void depending_ds_remove(hk_datasource* d);
00688 void depending_on_datasource_row_change(bool take_changed_data=false);
00689 void depending_on_datasource_data_has_changed(void);
00690 void depending_on_datasource_after_store_changed_data(void);
00691 void depending_on_datasource_insertmode(void);
00692 void depending_on_datasource_before_update_row(void);
00693 void depending_on_datasource_after_update_row(void);
00694 void reload_data(bool take_changed_data=false);
00695 void create_actual_row_where_statement(void);
00696 hk_string create_row_where_statement_at(unsigned long int position,bool withwhere=true);
00697 void create_new_sql_statement(bool take_changed_data=false);
00698 hk_string whole_datasource_where_statement(bool take_changed_data=false);
00699 void print_sql(void);
00700
00701 bool p_enabled;
00702 bool p_readonly;
00703 bool p_primary_key_used;
00704 bool p_ignore_changed_data;
00705 void clear_columnlist(void);
00706 void clear_modecolumnlists(void);
00707 void clear_visiblelist(void);
00708 void parse_sql(void);
00709 virtual bool update_row(enum_interaction c=interactive);
00710 virtual bool insert_row(enum_interaction c=interactive);
00711 virtual bool delete_row(enum_interaction c=interactive);
00712 unsigned long p_counter;
00713 hk_database* p_database;
00714 list<hk_column*>* p_columns;
00715 typedef class
00716 {
00717 public:
00718 hk_string name;
00719 hk_string newname;
00720 hk_column::enum_columntype type;
00721 long size;
00722 hk_string defaultvalue;
00723 bool primary;
00724 bool notnull;
00725 } class_altercolumns;
00726
00727 list<class_altercolumns> p_altercolumns;
00728 list<hk_string> p_deletecolumns;
00729 list<hk_column*> p_newcolumns;
00730 list<hk_string> depending_this_fields;
00731 list<hk_string> depending_master_fields;
00732
00733 typedef class fieldoriginclass
00734 {
00735 public:
00736 hk_string fieldname;
00737 hk_string alias;
00738 fieldoriginclass()
00739 {
00740 }
00741 bool operator=(const fieldoriginclass& o)
00742 {
00743 fieldname=o.fieldname;
00744 alias=o.alias;
00745 return true;
00746 }
00747 };
00748
00752 typedef class
00753 {
00754 public:
00755 hk_string
00756 select_part,
00757 from_part,
00758 where_part,
00759 groupby_part,
00760 having_part,
00761 orderby_part ;
00762 list <fieldoriginclass> fieldpart;
00763 list <pair<hk_string,hk_string> > tablepart;
00764 } struct_parsed_sql;
00765
00766
00767
00768 struct_parsed_sql* p_parsed_sql;
00769 void parse_fieldpart(void);
00770 void parse_tablepart(void);
00771 hk_string p_sql;
00772 hk_string p_viewsql;
00773 hk_string p_actual_row_where;
00774 bool p_automatic_data_update;
00775 hk_actionquery* p_actionquery;
00776 hk_string p_datetimeformat;
00777 hk_string p_dateformat;
00778 hk_string p_timeformat;
00779 hk_string p_sql_delimiter;
00780 hk_string p_true;
00781 hk_string p_false;
00782
00783 bool p_tablesql_set;
00784 void set_has_changed(void);
00785 void set_has_not_changed(void);
00786 hk_string delimit_identifier(const hk_string&);
00787 static voidfunction* p_enablefunction;
00788
00789 static long p_enablefunctioncounter;
00790 void inform_before_row_change(void);
00791 void inform_visible_objects_batch_goto_next(void);
00792 void inform_visible_objects_batch_goto_previous(void);
00793 void inform_visible_objects_before_store_changed_data(void);
00794 void inform_visible_objects_after_store_changed_data(void);
00795 void inform_visible_objects_row_change(void);
00796 void inform_visible_objects_row_add(void);
00797 void inform_visible_objects_row_delete(void);
00798 void inform_visible_objects_before_insert_row(void);
00799 void inform_before_enable(void);
00800 void inform_before_disable(void);
00801 void inform_visible_objects_ds_disable(void);
00802 void inform_visible_objects_ds_enable(void);
00803 void inform_depending_ds_goto_row(void);
00804 void inform_depending_ds_store_data(void);
00805 void inform_depending_ds_data_has_changed(void);
00806 void inform_depending_ds_after_store_changed_data(void);
00807 void inform_depending_ds_before_update_row(void);
00808 void inform_depending_ds_after_update_row(void);
00809 void inform_depending_ds_disable(void);
00810 void inform_depending_ds_enable(void);
00811 void inform_depending_ds_insertmode(void);
00812 void inform_visible_objects_new_columns_created(void);
00813 void inform_visible_objects_before_columns_deleted(void);
00814 void inform_visible_objects_insertmode(void);
00815 void inform_when_table_structure_changes(void);
00816 void inform_when_indexlist_changes(void);
00817 void execute_visible_object_script_before_update(void);
00818 void execute_visible_object_script_after_update(void);
00819 void execute_visible_object_before_row_change(void);
00820 void execute_visible_object_after_row_change(void);
00821 void execute_visible_object_before_delete(void);
00822 void execute_visible_object_after_delete(void);
00823 void execute_visible_object_before_insert(void);
00824 void execute_visible_object_after_insert(void);
00825
00826
00827 list<hk_datasource*> p_dependinglist;
00828 enum_tablemodes p_mode;
00829 list<referentialclass> p_references;
00830 hk_string new_referencename(const referentialclass&);
00831 bool is_newreferencename(const hk_string&);
00832
00833 private:
00834 hk_string p_original_sql;
00835 unsigned long p_length;
00836 bool p_has_changed;
00837 list<hk_dsvisible*> p_visibles;
00838 hk_datasource* p_depending_on_datasource;
00839 bool p_depending_on_datasource_react_on_changed_data;
00840 void mark_visible_objects_as_not_handled(void);
00841 void set_columns_tableorigin(void);
00842 hk_string columntablepart(const hk_string&);
00843 hk_presentation* p_presentation;
00844
00845 long p_dscounter;
00846
00847 hk_datasourceprivate* p_private;
00848 }
00849
00850
00851 ;
00852 #endif