Databaseconnectionclasses  0.5.3
hk_importcsv.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_IMPORTCSV
12 #define HK_IMPORTCSV
13 #include <iostream>
14 #include <fstream>
15 #include "hk_class.h"
16 #include "hk_datasource.h"
17 #include "hk_dsvisible.h"
18 #include "hk_column.h"
19 #include <vector>
20 
21 using namespace std;
22 
23 class hk_column;
24 
25 typedef class colstruct
26 {
27  public:
28  colstruct(void){col=NULL;}
29  hk_string colname;
30  hk_column* col;
31  int currentvalue;
32 } colstruct;
42 {
43  public:
44  hk_importcsv(void);
45  virtual ~hk_importcsv(void);
46 
47 
52  bool execute(enum_interaction i=interactive);
56  void set_filedefinition(const hk_string& textdelimiter="\"",const hk_string& betweenfields=",", const hk_string& rowdelimiter="\n",const hk_string& datetimeformat="",const hk_string& dateformat="",const hk_string& timeformat="", const hk_string& charset="",const hk_string& locale="");
60  void set_filename(const hk_string& filename);
65  void set_firstrow_contains_fieldnames(bool f=true);
71  void set_append_rows(bool f=false);
75  void set_create_new_table(bool n=true);
80  void add_columnname(const hk_string& col);
81  void clear_columnlist(void);
82  void set_detect_autoinc(bool);
83  bool detect_autoinc(void) const;
84  hk_string textdelimiter(void){return p_textdelimiter;}
85  hk_string betweenfield(void) {return p_betweenfields;}
86  hk_string rowdelimiter(void) {return p_rowdelimiter;}
87  hk_string datetimeformat(void) {return p_datetimeformat;}
88  hk_string dateformat(void) {return p_dateformat;}
89  hk_string timeformat(void) {return p_timeformat;}
90  hk_string filelocale(void) {return p_locale;}
91  hk_string filecharset(void){return p_charset;}
92  void set_overwrite_table(bool);
93  bool overwrite_table(void);
94  vector<hk_string>* create_valuelist( hk_string& row);
95  void get_line(ifstream&,hk_string&);
96 
97  protected:
98  void set_progressdialog(progress_dialogtype* progressdialog);
99  progress_dialogtype* progressdialog(void)const;
100  void set_columns(void);
101  void create_automatic_columns(void);
102  bool initialize_table(enum_interaction);
103  virtual bool before_columns_deleted(void);
108  virtual bool widget_specific_after_new_row(void);
109 
110  private:
111  void reset(void);
112  bool p_create_new_table;
113 /*
114  * 0= hk_string
115  * 1= float
116  * 2= Integer
117  * 3= boolean
118  * 4=datetime
119  * 5=date
120  * 6=time
121  */
122  hk_column::enum_columntype interpret_columntype(hk_string&f);
123  ifstream* p_filestream;
124  hk_string p_filename;
125  hk_string p_textdelimiter;
126  hk_string p_rowdelimiter;
127  hk_string p_betweenfields;
128  hk_string p_charset;
129  hk_string p_locale;
130  bool p_firstrow_contains_fieldnames;
131  vector<hk_string> p_valuelist;
132  vector<colstruct> p_columnlist;
133  bool p_datamode;
134  bool p_cancelimport;
135  bool p_overwrite;
136  bool p_detect_autoinc;
137  hk_datasource::enum_accessmode p_accessmode;
138  hk_string p_datetimeformat,p_dateformat,p_timeformat;
139  progress_dialogtype* p_progressdialog;
140 };
141 #endif
enum_accessmode
Definition: hk_datasource.h:187
enum_columntype
Definition: hk_column.h:93
base class for visible widgets without column data connection
Definition: hk_dsvisible.h:31
enum_interaction
Definition: hk_class.h:60
Definition: hk_importcsv.h:25
imports comma delimited textfiles
Definition: hk_importcsv.h:41
represents one column of a datasource.
Definition: hk_column.h:34