Databaseconnectionclasses  0.5.3
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
hk_connection Class Reference

connects to the SQL Server More...

#include <hk_connection.h>

Inheritance diagram for hk_connection:
Inheritance graph
[legend]
Collaboration diagram for hk_connection:
Collaboration graph
[legend]

Public Types

enum  support_enum {
  SUPPORTS_AUTOINCCOLUMN =1, SUPPORTS_BOOLCOLUMN =2, SUPPORTS_DATECOLUMN =3, SUPPORTS_TIMECOLUMN =4,
  SUPPORTS_DATETIMECOLUMN =5, SUPPORTS_BINARYCOLUMN =6, SUPPORTS_MEMOCOLUMN =7, SUPPORTS_TIMESTAMPCOLUMN =8,
  SUPPORTS_TEXTCOLUMN =9, SUPPORTS_INTEGERCOLUMN =10, SUPPORTS_SMALLINTEGERCOLUMN =11, SUPPORTS_FLOATINGCOLUMN =12,
  SUPPORTS_SMALLFLOATINGCOLUMN =13, SUPPORTS_PROPRIETARYCOLUMN =19, SUPPORTS_SQL =100, SUPPORTS_TRANSACTIONS =101,
  SUPPORTS_REFERENTIALINTEGRITY =102, SUPPORTS_NEW_DATABASE =103, SUPPORTS_DELETE_DATABASE =104, SUPPORTS_NEW_TABLE =105,
  SUPPORTS_ALTER_TABLE =106, SUPPORTS_DELETE_TABLE =107, SUPPORTS_CREATE_INDEX =108, SUPPORTS_DELETE_INDEX =109,
  SUPPORTS_CHANGE_PASSWORD =110, SUPPORTS_RENAME_DATABASE =111, SUPPORTS_RENAME_TABLE =112, SUPPORTS_VIEWS =113,
  SUPPORTS_NEW_VIEW =114, SUPPORTS_ALTER_VIEW =115, SUPPORTS_DELETE_VIEW =116, SUPPORTS_ADD_COLUMN =117,
  SUPPORTS_DELETE_COLUMN =118, SUPPORTS_CHANGE_COLUMNTYPE =119, SUPPORTS_CHANGE_COLUMNNAME =120, SUPPORTS_ALTER_PRIMARY_KEY =121,
  SUPPORTS_ALTER_NOT_NULL =122, SUPPORTS_SQL_GROUP_BY =180, SUPPORTS_SQL_ORDER_BY =181, SUPPORTS_SQL_HAVING =182,
  SUPPORTS_SQL_WHERE =183, SUPPORTS_SQL_ALIAS =184, SUPPORTS_SQL_SUBSELECTS =185, SUPPORTS_SQL_JOINS =186,
  SUPPORTS_SQL_UNION =187, SUPPORTS_LOCAL_FILEFORMAT =200, SUPPORTS_NONALPHANUM_FIELDNAMES =201, SUPPORTS_NONASCII_FIELDNAMES =202,
  SUPPORTS_SPACE_FIELDNAMES =203
}
 
enum  need_enum {
  NEEDS_LOGIN =0, NEEDS_HOST =1, NEEDS_USERNAME =2, NEEDS_PASSWORD =3,
  NEEDS_SQLDELIMITER =4, NEEDS_PORT =5, NEEDS_DATABASENAME =6, NEEDS_BOOLEANEMULATION =7,
  NEEDS_NULL_TERMINATED_SQL =8, NEEDS_TABLE_ALIAS_AS =9, NEEDS_MANUAL_CHARSET =10, NEEDS_DIRECTORY_AS_DATABASE =11
}
 
- Public Types inherited from hk_class
enum  enum_interaction { noninteractive, interactive }
 
enum  enum_measuresystem { cm, inch }
 
enum  enum_tagtype { normaltag, mastertag }
 

Public Member Functions

virtual ~hk_connection ()
 
void set_host (const hk_string &h)
 
hk_string host (void)
 
void set_user (const hk_string &u)
 
hk_string user (void)
 
void set_password (const hk_string &p)
 
hk_string password (void)
 
void set_tcp_port (unsigned int t)
 
unsigned int tcp_port (void)
 
void set_defaultdatabase (const hk_string &)
 
hk_string defaultdatabase (void) const
 
virtual unsigned int default_tcp_port (void) const
 
bool connect (enum_interaction c=interactive)
 
bool disconnect (void)
 
bool is_connected (void)
 
vector< hk_string > * dblist (void)
 
hk_databasenew_database (const hk_string &name="")
 
bool rename_database (const hk_string &originalname, const hk_string &new_name)
 
virtual bool server_supports (support_enum) const
 
virtual bool server_needs (need_enum) const
 
virtual bool create_database (const hk_string &dbase)
 
virtual bool delete_database (const hk_string &dbase, enum_interaction c=interactive)
 
bool database_exists (const hk_string &databasename)
 
bool set_newpassword (const hk_string &newpassword)
 
void show_newpassworddialog (void)
 
bool show_passworddialog (void)
 
virtual hk_string drivername (void) const
 
void set_booleanemulation (bool emulate)
 
bool booleanemulation (void) const
 
hk_drivermanagerdrivermanager (void)
 
bool copy_database (hk_database *fromdatabase, bool schema_and_data, bool copy_local_files, progress_dialogtype *progressdialog=NULL)
 
hk_string last_servermessage (void)
 
hk_string databasepath (void)
 
virtual hk_string mimetype (void) const
 
virtual unsigned int maxfieldnamesize (void) const
 
virtual long int maxcharsize (void) const
 
virtual hk_string left_join_statement (void)
 
virtual hk_string inner_join_statement (void)
 
bool is_sqlstatement (const hk_string &)
 
- Public Member Functions inherited from hk_class
void hkclassname (const hk_string &n)
 
hk_string hkclassname (void) const
 
void hkdebug (const hk_string &d) const
 
void hkdebug (const hk_string &d, const hk_string &e) const
 
void hkdebug (const hk_string &d, int i) const
 
void hkdebug (const hk_string &d, double i) const
 
void wanna_debug (bool d)
 
bool wanna_debug (void) const
 
bool generaldebug (void)
 

Static Public Member Functions

static void set_passworddialog (password_dialogtype *)
 
static void set_newpassworddialog (newpassword_dialogtype *)
 
static hk_string check_capabilities (hk_connection *from, hk_connection *to)
 
- Static Public Member Functions inherited from hk_class
static void set_generaldebug (bool d)
 
static hk_string hk_translate (const hk_string &t)
 
static void show_warningmessage (const hk_string &m)
 
static void set_warningmessage (messagewindowtype *m)
 
static bool show_yesnodialog (const hk_string &m, bool default_value)
 
static void set_yesnodialog (yesno_dialogtype *d)
 
static hk_string show_stringvaluedialog (const hk_string &t)
 
static void set_stringvaluedialog (stringvalue_dialogtype *t)
 
static void set_translatefunction (translatefunctiontype *t)
 
static void set_filedialog (file_dialogtype *f)
 
static hk_string show_filedialog (const hk_string &f="", enum_operationmode m=file_open)
 
static void set_directorydialog (stringvalue_dialogtype *f)
 
static hk_string show_directorydialog (const hk_string &f="")
 
static void set_showpedantic (bool s)
 
static bool showpedantic (void)
 
static void set_measuresystem (enum_measuresystem)
 
static enum_measuresystem measuresystem (void)
 
static xmlNodePtr get_tagvalue (xmlNodePtr where, const hk_string &tag, hk_string &value, int position=1, enum_tagtype tagtype=normaltag)
 
static xmlNodePtr get_tagvalue (xmlNodePtr where, const hk_string &tag, unsigned long &value, int position=1)
 
static xmlNodePtr get_tagvalue (xmlNodePtr where, const hk_string &tag, unsigned int &value, int position=1)
 
static xmlNodePtr get_tagvalue (xmlNodePtr where, const hk_string &tag, long &value, int position=1)
 
static xmlNodePtr get_tagvalue (xmlNodePtr where, const hk_string &tag, int &value, int position=1)
 
static xmlNodePtr get_tagvalue (xmlNodePtr where, const hk_string &tag, bool &value, int position=1)
 
static xmlNodePtr get_tagvalue (xmlNodePtr &where, const hk_string &tag)
 
static void set_tagvalue (ostream &stream, const hk_string &tag, const hk_string &value)
 
static void set_tagvalue (ostream &stream, const hk_string &tag, unsigned long value)
 
static void set_tagvalue (ostream &stream, const hk_string &tag, unsigned int value)
 
static void set_tagvalue (ostream &stream, const hk_string &tag, long value)
 
static void set_tagvalue (ostream &stream, const hk_string &tag, int value)
 
static void set_tagvalue (ostream &stream, const hk_string &tag, bool value)
 
static void start_mastertag (ostream &stream, const hk_string &tag)
 
static void end_mastertag (ostream &stream, const hk_string &tag)
 
static void set_defaultdatetimeformat (const hk_string &timeformat, const hk_string &dateformat, const hk_string &datetimeformat)
 
static hk_string defaultdateformat (void)
 
static hk_string defaulttimeformat (void)
 
static hk_string defaultdatetimeformat (void)
 
static void save_preferences (void)
 
static bool runtime_only (void)
 
static void set_locale (const hk_string &locale)
 
static hk_string locale (void)
 
static void set_defaultdriver (const hk_string &d)
 
static hk_string defaultdriver (void)
 
static void set_default_automatic_data_update (bool)
 
static bool default_automatic_data_update (void)
 

Protected Member Functions

 hk_connection (hk_drivermanager *c)
 
virtual bool driver_specific_connect (void)
 
virtual bool driver_specific_disconnect (void)
 
virtual bool driver_specific_rename_database (const hk_string &, const hk_string &)
 
virtual vector< hk_string > * driver_specific_dblist (void)
 
virtual hk_databasedriver_specific_new_database (void)
 
virtual bool driver_specific_new_password (const hk_string &)
 
virtual bool driver_specific_delete_database (const hk_string &dbase)
 
void db_remove (hk_database *d)
 
hk_string sqldelimiter (void)
 
void inform_databases_connect (void)
 
void inform_databases_disconnect (void)
 
virtual void savedata (ostream &s)
 
virtual void loaddata (xmlNodePtr definition)
 
void set_last_servermessage (const hk_string &m)
 
hk_databasedatabase (void) const
 
void delete_databasedirectory (const hk_string &db)
 
void delete_directory (const hk_string &d)
 
- Protected Member Functions inherited from hk_class
hk_interpreternew_interpreter (const hk_string &interpreter, hk_presentation *)
 

Static Protected Member Functions

static bool internal_copy_check (hk_connection *from, hk_connection *to, support_enum)
 

Protected Attributes

bool p_connected
 
vector< hk_string > p_databaselist
 
list< hk_string > p_sqlstatements
 

Friends

class hk_database
 
class hk_drivermanager
 

Additional Inherited Members

- Static Protected Attributes inherited from hk_class
static hk_string p_defaulttimeformat ="h:m:s"
 
static hk_string p_defaultdateformat ="D.M.Y"
 
static hk_string p_defaultdatetimeformat ="D.M.Y h:m:s"
 
static bool p_runtime_only =false
 

Detailed Description

connects to the SQL Server

Version
Revision:
1.66
Author
Horst Knorr (hk_cl.nosp@m.asse.nosp@m.s@kno.nosp@m.da.o.nosp@m.rg)

connects to the SQL Server. Set set_host,set_user, set_password , set_tcp_port if necessary and then call connect.

Member Enumeration Documentation

see also serversupports. Defines what abilities and fieldtypes a database driver supports

Constructor & Destructor Documentation

hk_connection::~hk_connection ( )
virtual

When the connection will be destroyed, the database created with new_database() and all its children will be destroyed

References disconnect(), and hk_class::hkdebug().

Member Function Documentation

hk_string hk_connection::check_capabilities ( hk_connection from,
hk_connection to 
)
static

returns messages of possible problems when copying tables between two different backends

References drivername(), hk_class::hk_translate(), and server_supports().

Referenced by copy_database().

bool hk_connection::connect ( enum_interaction  c = interactive)

tries to connect to the SQL Server. If some information is missing (i.e. password) a dialog will ask for these values. You can set a GUI dependend dialog with set_passworddialog

Returns
true if connecting was successful, else false.

References hk_class::hk_translate(), hk_class::hkdebug(), is_connected(), and hk_class::show_warningmessage().

Referenced by hk_mysqldatabase::driver_specific_tablelist(), hk_datasource::enable(), and show_newpassworddialog().

bool hk_connection::copy_database ( hk_database fromdatabase,
bool  schema_and_data,
bool  copy_local_files,
progress_dialogtype *  progressdialog = NULL 
)

copies whole databases

Parameters
fromdatabasethe database that should be copied
schema_and_dataif true both the table schemas will be created and the data will be copied, if false only the table will be created
copy_local_filesif true queries,forms and reports will be also copied
progressdialogif set this function will be regularly called to show the progress

References hk_datasource::add_reference(), check_capabilities(), hk_database::connection(), hk_database::copy_table(), create_database(), database_exists(), hk_database::new_table(), hk_class::runtime_only(), server_supports(), hk_database::set_name(), hk_database::table_exists(), and hk_database::tablelist().

bool hk_connection::create_database ( const hk_string &  dbase)
virtual
bool hk_connection::database_exists ( const hk_string &  databasename)
vector< hk_string > * hk_connection::dblist ( void  )

if connected it returns a hk_stringlist of all existing databases on the SQL Server. The list will be created new every time you call this function. So be careful. Never use i.e. for_each(dblist()->begin(),dblist()->end(),anyfunction) Use instead: list<hk_string>* mylist=dblist(); for_each(mylist->begin(),mylist->end(),anyfunction)

Referenced by database_exists().

unsigned int hk_connection::default_tcp_port ( void  ) const
virtual

returns the default tcp port of the the database driver;

Reimplemented in hk_mysqlconnection.

bool hk_connection::delete_database ( const hk_string &  dbase,
enum_interaction  c = interactive 
)
virtual

tries to delete a database.

Parameters
dbasename of an existing database
Returns
true if successful else flase

References hk_class::hk_translate(), is_connected(), new_database(), hk_class::show_warningmessage(), and hk_class::show_yesnodialog().

bool hk_connection::disconnect ( void  )

disconnects from the SQL Server

Returns
true if successful.

Referenced by ~hk_connection().

hk_string hk_connection::drivername ( void  ) const
virtual

returns the name of the driver (e.g Mysql,Postgres etc.)

Reimplemented in hk_mysqlconnection.

References hk_class::hk_translate().

Referenced by check_capabilities().

bool hk_connection::is_connected ( void  )
void hk_connection::loaddata ( xmlNodePtr  definition)
protectedvirtual

load the tags <HOST><USER><TCP-PORT><SQLDELIMITER> with the equivalent values

Reimplemented from hk_class.

References hk_class::get_tagvalue(), hk_class::hkdebug(), set_host(), set_tcp_port(), and set_user().

virtual long int hk_connection::maxcharsize ( void  ) const
inlinevirtual

returns the maximum length of the char() sql columntype

virtual hk_string hk_connection::mimetype ( void  ) const
inlinevirtual

returns the mimetype of a local database format, if it is not a local database format it returns an empty string

hk_database * hk_connection::new_database ( const hk_string &  name = "")

if you want to use a database on the SQL Server create a hk_database element with this class. For each connection you can define one database. If you define another one the old one will be destroyed.

References database_exists(), hk_class::hkdebug(), and hk_database::set_name().

Referenced by create_database(), and delete_database().

void hk_connection::savedata ( ostream &  s)
protectedvirtual

saves the tags <HOST><USER><TCP-PORT><SQLDELIMITER> with the equivalent values

Reimplemented from hk_class.

References hk_class::end_mastertag(), hk_class::set_tagvalue(), and hk_class::start_mastertag().

virtual bool hk_connection::server_needs ( need_enum  ) const
inlinevirtual

shows what information the database server needs (e.g. password).

Reimplemented in hk_mysqlconnection.

Referenced by database_exists(), hk_database::new_resultquery(), and hk_database::new_table().

virtual bool hk_connection::server_supports ( support_enum  ) const
inlinevirtual
void hk_connection::set_booleanemulation ( bool  emulate)

If the database does not have a native boolean type(like Mysql), but hk_classes should use one datatype to emulate, set this to true (default) else switch it off.

void hk_connection::set_host ( const hk_string &  h)

name of the host where the SQL Server is. Default is "localhost".

Referenced by loaddata().

bool hk_connection::set_newpassword ( const hk_string &  newpassword)

sets a new password at the SQL server.

Parameters
newpasswordthe new password
Returns
true if successful else flase

References hk_class::hk_translate(), hk_class::hkdebug(), set_password(), and hk_class::show_warningmessage().

Referenced by show_newpassworddialog().

void hk_connection::set_newpassworddialog ( newpassword_dialogtype *  d)
static

It is possible to define a newpassworddialog, which will be shown when set_newpassword is called

void hk_connection::set_password ( const hk_string &  p)

password for the SQL Server

Referenced by set_newpassword().

void hk_connection::set_passworddialog ( password_dialogtype *  d)
static

the passworddialog will be called from connect if necessary. You can define a GUI dependend dialog and set it with this function. What exactly is asked in the dialog is database driver dependend (i.e. the Mysql driver needs user, password, host and tcp_port)

void hk_connection::set_tcp_port ( unsigned int  t)

TCP Port number of the SQL Server. Default is 3306.

Referenced by loaddata().

void hk_connection::set_user ( const hk_string &  u)

user name for the SQL Server.

Referenced by loaddata().

void hk_connection::show_newpassworddialog ( void  )

shows a password dialog and sets the new password by calling set_newpassword If no passworddialog is set with set_newpassworddialog the necessary information will be queried at the standard output

References connect(), hk_class::hk_translate(), hk_class::hkdebug(), is_connected(), set_newpassword(), and hk_class::show_warningmessage().


The documentation for this class was generated from the following files: