Databaseconnectionclasses  0.5.3
hk_connection.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_CONNECTION
12 #define HK_CONNECTION
13 #include "hk_class.h"
14 #include <list>
15 #include <vector>
16 #include <algorithm>
17 using namespace std;
18 class hk_drivermanager;
20 
21 class hk_database;
31 class hk_connection:public hk_class
32 {
33  friend class hk_database;
34  friend class hk_drivermanager;
35  public:
40  virtual ~hk_connection();
44  void set_host(const hk_string& h);
45  hk_string host(void);
49  void set_user(const hk_string& u);
50  hk_string user(void);
54  void set_password(const hk_string& p);
55  hk_string password(void);
59  void set_tcp_port(unsigned int t);
60  unsigned int tcp_port(void);
61  void set_defaultdatabase(const hk_string&);
62  hk_string defaultdatabase(void) const;
66  virtual unsigned int default_tcp_port(void) const;
72  bool connect(enum_interaction c=interactive);
77  bool disconnect(void);
81  bool is_connected(void);
91  vector<hk_string>* dblist(void);
98  hk_database* new_database(const hk_string& name="");
99 
100  bool rename_database(const hk_string& originalname, const hk_string& new_name);
105  {
106  SUPPORTS_AUTOINCCOLUMN=1,
107  SUPPORTS_BOOLCOLUMN=2,
108  SUPPORTS_DATECOLUMN=3,
109  SUPPORTS_TIMECOLUMN=4,
110  SUPPORTS_DATETIMECOLUMN=5,
111  SUPPORTS_BINARYCOLUMN=6,
112  SUPPORTS_MEMOCOLUMN=7,
113  SUPPORTS_TIMESTAMPCOLUMN=8,
114 
115  SUPPORTS_TEXTCOLUMN=9,
116  SUPPORTS_INTEGERCOLUMN=10,
117  SUPPORTS_SMALLINTEGERCOLUMN=11,
118  SUPPORTS_FLOATINGCOLUMN=12,
119  SUPPORTS_SMALLFLOATINGCOLUMN=13,
120 
121  SUPPORTS_PROPRIETARYCOLUMN=19,//driver specific datatype that can not be mapped to a hk_classes type
122 
123  SUPPORTS_SQL=100,
124  SUPPORTS_TRANSACTIONS=101,
125  SUPPORTS_REFERENTIALINTEGRITY=102,
126  SUPPORTS_NEW_DATABASE=103,
127  SUPPORTS_DELETE_DATABASE=104,
128  SUPPORTS_NEW_TABLE=105,
129  SUPPORTS_ALTER_TABLE=106,
130  SUPPORTS_DELETE_TABLE=107,
131  SUPPORTS_CREATE_INDEX=108,
132  SUPPORTS_DELETE_INDEX=109,
133  SUPPORTS_CHANGE_PASSWORD=110,
134  SUPPORTS_RENAME_DATABASE=111,
135  SUPPORTS_RENAME_TABLE=112,
136  SUPPORTS_VIEWS=113,
137  SUPPORTS_NEW_VIEW=114,
138  SUPPORTS_ALTER_VIEW=115,
139  SUPPORTS_DELETE_VIEW=116,
140  SUPPORTS_ADD_COLUMN=117,
141  SUPPORTS_DELETE_COLUMN=118,
142  SUPPORTS_CHANGE_COLUMNTYPE=119,
143  SUPPORTS_CHANGE_COLUMNNAME=120,
144  SUPPORTS_ALTER_PRIMARY_KEY=121,
145  SUPPORTS_ALTER_NOT_NULL=122,
146 
147  SUPPORTS_SQL_GROUP_BY=180,
148  SUPPORTS_SQL_ORDER_BY=181,
149  SUPPORTS_SQL_HAVING=182,
150  SUPPORTS_SQL_WHERE=183,
151  SUPPORTS_SQL_ALIAS=184,
152  SUPPORTS_SQL_SUBSELECTS=185,
153  SUPPORTS_SQL_JOINS=186, // means at least INNER JOIN and LEFT (OUTER) JOIN
154  SUPPORTS_SQL_UNION=187,
155 
156  SUPPORTS_LOCAL_FILEFORMAT=200,
157  SUPPORTS_NONALPHANUM_FIELDNAMES=201, // if not set field name can only have [a-zA-Z0-9]
158  SUPPORTS_NONASCII_FIELDNAMES=202, //unicode characters etc
159  SUPPORTS_SPACE_FIELDNAMES=203 // means a space character can be part
160  };
161 
165  virtual bool server_supports(support_enum) const{return false;}
170  {
171 
172  NEEDS_LOGIN=0,
173  NEEDS_HOST=1,
174  NEEDS_USERNAME=2,
175  NEEDS_PASSWORD=3,
176  NEEDS_SQLDELIMITER=4,
177  NEEDS_PORT=5,
178  NEEDS_DATABASENAME=6,
179  NEEDS_BOOLEANEMULATION=7,//e.g. Mysql doesn't have natively a boolean type, so tinyint is used
180  NEEDS_NULL_TERMINATED_SQL=8, //e.g. Postgres needs null terminated strings in PQExec
181  NEEDS_TABLE_ALIAS_AS=9, // set if the server needs 'AS' between the table name and its alias name in a FROM clause
182  NEEDS_MANUAL_CHARSET=10, // per database see hk_database::set_databasecharset
183  NEEDS_DIRECTORY_AS_DATABASE=11 //local database formats like paradox, dbase etc needs a directory as a database which contains one file per table
184  };
188  virtual bool server_needs(need_enum) const {return false;}
194  static void set_passworddialog(password_dialogtype*);
198 virtual bool create_database(const hk_string& dbase);
204 virtual bool delete_database(const hk_string& dbase,enum_interaction c=interactive);
208  bool database_exists(const hk_string& databasename);
215  bool set_newpassword(const hk_string& newpassword);
221  void show_newpassworddialog(void);
226  static void set_newpassworddialog(newpassword_dialogtype*);
227 /*
228  *shows a password dialog
229  *@return false if it has been cancelled else true
230  */
231  bool show_passworddialog(void);
236  virtual hk_string drivername(void) const;
242  void set_booleanemulation(bool emulate);
243  bool booleanemulation(void) const;
244  hk_drivermanager* drivermanager(void);
252  bool copy_database(hk_database* fromdatabase,bool schema_and_data,bool copy_local_files,progress_dialogtype* progressdialog=NULL);
253  hk_string last_servermessage(void){return p_lastservermessage;}
254  hk_string databasepath(void);
258 static hk_string check_capabilities(hk_connection* from,hk_connection* to);
259 
263 virtual hk_string mimetype(void) const {return "";}
264 virtual unsigned int maxfieldnamesize(void) const {return (unsigned int)-1;}
265 
269 virtual long int maxcharsize(void) const {return 255;}
270 
271 virtual hk_string left_join_statement(void) {return " LEFT JOIN ";}
272 virtual hk_string inner_join_statement(void) {return " INNER JOIN ";}
273 
274 bool is_sqlstatement(const hk_string&);
275 
276  protected:
278  bool p_connected;
279  virtual bool driver_specific_connect(void){return false;}
280  virtual bool driver_specific_disconnect(void){return false;}
281  virtual bool driver_specific_rename_database(const hk_string& /*oldname*/,const hk_string& /*newname*/){return false;}
282  virtual vector<hk_string>* driver_specific_dblist(void){return NULL;}
283  virtual hk_database* driver_specific_new_database(void){return NULL;}
284  virtual bool driver_specific_new_password(const hk_string&){return false;}
285  virtual bool driver_specific_delete_database(const hk_string& dbase);
286 
287  void db_remove(hk_database* d);
288  hk_string sqldelimiter(void) ;
289  void inform_databases_connect(void);
290  void inform_databases_disconnect(void);
291  vector<hk_string> p_databaselist;
292  list<hk_string> p_sqlstatements;
296  virtual void savedata(ostream& s);
300  virtual void loaddata(xmlNodePtr definition);
301 
302  void set_last_servermessage(const hk_string& m);
303  hk_database* database(void) const {return p_database;}
304  static bool internal_copy_check(hk_connection* from, hk_connection* to,support_enum);
305  void delete_databasedirectory(const hk_string& db);
306  void delete_directory(const hk_string& d);
307  private:
308  void load_configuration(void);
309  void save_configuration(void);
310  bool copy_local_files(hk_database* fromdb,hk_database* todb,objecttype f,progress_dialogtype* progressdialog);
311  hk_string ask_dbname(void);
312  void make_databasedir(const hk_string& dbname);
313  void set_classespath(hk_string& p);
314 
315  hk_database* p_database;
316  unsigned int p_debug_counter;
317  static password_dialogtype* p_passworddialog;
318  static newpassword_dialogtype* p_newpassworddialog;
319  hk_drivermanager* p_drivermanager;
320  hk_string p_lastservermessage;
321  hk_connectionprivate* p_private;
322 } ;
323 #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
connects to the SQL Server
Definition: hk_connection.h:31
need_enum
Definition: hk_connection.h:169
enum_interaction
Definition: hk_class.h:60
virtual void savedata(ostream &s)
Definition: hk_class.cpp:251
virtual bool server_needs(need_enum) const
Definition: hk_connection.h:188
virtual void loaddata(xmlNodePtr definition)
Definition: hk_class.cpp:262
virtual bool server_supports(support_enum) const
Definition: hk_connection.h:165
Definition: hk_connection.cpp:61
support_enum
Definition: hk_connection.h:104
virtual hk_string mimetype(void) const
Definition: hk_connection.h:263
Database Driver administration.
Definition: hk_drivermanager.h:38
virtual long int maxcharsize(void) const
Definition: hk_connection.h:269