00001
00002
00003 #ifndef _LIBGDAMM_CONNECTION_H
00004 #define _LIBGDAMM_CONNECTION_H
00005
00006
00007 #include <glibmm.h>
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <libgdamm/transactionstatus.h>
00032 #include <libgdamm/connectionevent.h>
00033 #include <libgdamm/command.h>
00034 #include <libgdamm/datamodel.h>
00035 #include <libgdamm/parameterlist.h>
00036 #include <libgdamm/datamodelindex.h>
00037 #include <libgdamm/dict.h>
00038
00039
00040
00041
00042 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00043 typedef struct _GdaConnection GdaConnection;
00044 typedef struct _GdaConnectionClass GdaConnectionClass;
00045 #endif
00046
00047
00048 namespace Gnome
00049 {
00050
00051 namespace Gda
00052 { class Connection_Class; }
00053
00054 }
00055 namespace Gnome
00056 {
00057
00058 namespace Gda
00059 {
00060
00061 class ServerProvider;
00062 typedef GdaServerProviderInfo ServerProviderInfo;
00063
00066 class GeneralError : public Glib::Error
00067 {
00068 public:
00069 enum Code
00070 {
00071 GENERAL_OBJECT_NAME_ERROR,
00072 GENERAL_INCORRECT_VALUE_ERROR,
00073 GENERAL_OPERATION_ERROR
00074 };
00075
00076 GeneralError(Code error_code, const Glib::ustring& error_message);
00077 explicit GeneralError(GError* gobject);
00078 Code code() const;
00079
00080 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00081 private:
00082
00083 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00084 static void throw_func(GError* gobject);
00085 #else
00086
00087 static std::auto_ptr<Glib::Error> throw_func(GError* gobject);
00088 #endif //GLIBMM_EXCEPTIONS_ENABLED
00089
00090 friend void wrap_init();
00091 #endif
00092 };
00093
00094 }
00095
00096 }
00097
00098 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00099 namespace Glib
00100 {
00101
00102 template <>
00103 class Value<Gnome::Gda::GeneralError::Code> : public Glib::Value_Enum<Gnome::Gda::GeneralError::Code>
00104 {
00105 public:
00106 static GType value_type() G_GNUC_CONST;
00107 };
00108
00109 }
00110 #endif
00111
00112
00113 namespace Gnome
00114 {
00115
00116 namespace Gda
00117 {
00118
00119
00122 class ConnectionError : public Glib::Error
00123 {
00124 public:
00125 enum Code
00126 {
00127 CONNECTION_CONN_OPEN_ERROR,
00128 CONNECTION_DO_QUERY_ERROR,
00129 CONNECTION_NONEXIST_DSN_ERROR,
00130 CONNECTION_NO_CNC_SPEC_ERROR,
00131 CONNECTION_NO_PROVIDER_SPEC_ERROR,
00132 CONNECTION_OPEN_ERROR,
00133 CONNECTION_EXECUTE_COMMAND_ERROR
00134 };
00135
00136 ConnectionError(Code error_code, const Glib::ustring& error_message);
00137 explicit ConnectionError(GError* gobject);
00138 Code code() const;
00139
00140 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00141 private:
00142
00143 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00144 static void throw_func(GError* gobject);
00145 #else
00146
00147 static std::auto_ptr<Glib::Error> throw_func(GError* gobject);
00148 #endif //GLIBMM_EXCEPTIONS_ENABLED
00149
00150 friend void wrap_init();
00151 #endif
00152 };
00153
00154 }
00155
00156 }
00157
00158 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00159 namespace Glib
00160 {
00161
00162 template <>
00163 class Value<Gnome::Gda::ConnectionError::Code> : public Glib::Value_Enum<Gnome::Gda::ConnectionError::Code>
00164 {
00165 public:
00166 static GType value_type() G_GNUC_CONST;
00167 };
00168
00169 }
00170 #endif
00171
00172
00173 namespace Gnome
00174 {
00175
00176 namespace Gda
00177 {
00178
00179
00180 class Client;
00181
00187 enum ConnectionFeature
00188 {
00189 CONNECTION_FEATURE_AGGREGATES,
00190 CONNECTION_FEATURE_BLOBS,
00191 CONNECTION_FEATURE_INDEXES,
00192 CONNECTION_FEATURE_INHERITANCE,
00193 CONNECTION_FEATURE_NAMESPACES,
00194 CONNECTION_FEATURE_PROCEDURES,
00195 CONNECTION_FEATURE_SEQUENCES,
00196 CONNECTION_FEATURE_SQL,
00197 CONNECTION_FEATURE_TRANSACTIONS,
00198 CONNECTION_FEATURE_SAVEPOINTS,
00199 CONNECTION_FEATURE_SAVEPOINTS_REMOVE,
00200 CONNECTION_FEATURE_TRIGGERS,
00201 CONNECTION_FEATURE_UPDATABLE_CURSOR,
00202 CONNECTION_FEATURE_USERS,
00203 CONNECTION_FEATURE_VIEWS,
00204 CONNECTION_FEATURE_XML_QUERIES
00205 };
00206
00207 }
00208
00209 }
00210
00211
00212 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00213 namespace Glib
00214 {
00215
00216 template <>
00217 class Value<Gnome::Gda::ConnectionFeature> : public Glib::Value_Enum<Gnome::Gda::ConnectionFeature>
00218 {
00219 public:
00220 static GType value_type() G_GNUC_CONST;
00221 };
00222
00223 }
00224 #endif
00225
00226
00227 namespace Gnome
00228 {
00229
00230 namespace Gda
00231 {
00232
00236 enum ConnectionSchema
00237 {
00238 CONNECTION_SCHEMA_AGGREGATES,
00239 CONNECTION_SCHEMA_DATABASES,
00240 CONNECTION_SCHEMA_FIELDS,
00241 CONNECTION_SCHEMA_INDEXES,
00242 CONNECTION_SCHEMA_LANGUAGES,
00243 CONNECTION_SCHEMA_NAMESPACES,
00244 CONNECTION_SCHEMA_PARENT_TABLES,
00245 CONNECTION_SCHEMA_PROCEDURES,
00246 CONNECTION_SCHEMA_SEQUENCES,
00247 CONNECTION_SCHEMA_TABLES,
00248 CONNECTION_SCHEMA_TRIGGERS,
00249 CONNECTION_SCHEMA_TYPES,
00250 CONNECTION_SCHEMA_USERS,
00251 CONNECTION_SCHEMA_VIEWS,
00252 CONNECTION_SCHEMA_CONSTRAINTS,
00253 CONNECTION_SCHEMA_TABLE_CONTENTS
00254 };
00255
00256 }
00257
00258 }
00259
00260
00261 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00262 namespace Glib
00263 {
00264
00265 template <>
00266 class Value<Gnome::Gda::ConnectionSchema> : public Glib::Value_Enum<Gnome::Gda::ConnectionSchema>
00267 {
00268 public:
00269 static GType value_type() G_GNUC_CONST;
00270 };
00271
00272 }
00273 #endif
00274
00275
00276 namespace Gnome
00277 {
00278
00279 namespace Gda
00280 {
00281
00293 enum ConnectionOptions
00294 {
00295 CONNECTION_OPTIONS_NONE = 0,
00296 CONNECTION_OPTIONS_READ_ONLY = 1 << 0
00297 };
00298
00300 inline ConnectionOptions operator|(ConnectionOptions lhs, ConnectionOptions rhs)
00301 { return static_cast<ConnectionOptions>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
00302
00304 inline ConnectionOptions operator&(ConnectionOptions lhs, ConnectionOptions rhs)
00305 { return static_cast<ConnectionOptions>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
00306
00308 inline ConnectionOptions operator^(ConnectionOptions lhs, ConnectionOptions rhs)
00309 { return static_cast<ConnectionOptions>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
00310
00312 inline ConnectionOptions operator~(ConnectionOptions flags)
00313 { return static_cast<ConnectionOptions>(~static_cast<unsigned>(flags)); }
00314
00316 inline ConnectionOptions& operator|=(ConnectionOptions& lhs, ConnectionOptions rhs)
00317 { return (lhs = static_cast<ConnectionOptions>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
00318
00320 inline ConnectionOptions& operator&=(ConnectionOptions& lhs, ConnectionOptions rhs)
00321 { return (lhs = static_cast<ConnectionOptions>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
00322
00324 inline ConnectionOptions& operator^=(ConnectionOptions& lhs, ConnectionOptions rhs)
00325 { return (lhs = static_cast<ConnectionOptions>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
00326
00327 }
00328
00329 }
00330
00331
00332 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00333 namespace Glib
00334 {
00335
00336 template <>
00337 class Value<Gnome::Gda::ConnectionOptions> : public Glib::Value_Flags<Gnome::Gda::ConnectionOptions>
00338 {
00339 public:
00340 static GType value_type() G_GNUC_CONST;
00341 };
00342
00343 }
00344 #endif
00345
00346
00347 namespace Gnome
00348 {
00349
00350 namespace Gda
00351 {
00352
00353
00362 class Connection : public Glib::Object
00363 {
00364
00365 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00366
00367 public:
00368 typedef Connection CppObjectType;
00369 typedef Connection_Class CppClassType;
00370 typedef GdaConnection BaseObjectType;
00371 typedef GdaConnectionClass BaseClassType;
00372
00373 private: friend class Connection_Class;
00374 static CppClassType connection_class_;
00375
00376 private:
00377
00378 Connection(const Connection&);
00379 Connection& operator=(const Connection&);
00380
00381 protected:
00382 explicit Connection(const Glib::ConstructParams& construct_params);
00383 explicit Connection(GdaConnection* castitem);
00384
00385 #endif
00386
00387 public:
00388 virtual ~Connection();
00389
00390 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00391 static GType get_type() G_GNUC_CONST;
00392 static GType get_base_type() G_GNUC_CONST;
00393 #endif
00394
00396 GdaConnection* gobj() { return reinterpret_cast<GdaConnection*>(gobject_); }
00397
00399 const GdaConnection* gobj() const { return reinterpret_cast<GdaConnection*>(gobject_); }
00400
00402 GdaConnection* gobj_copy();
00403
00404 private:
00405
00406 protected:
00407
00408 Connection();
00409
00410
00411 public:
00412
00413 static Glib::RefPtr<Connection> create();
00414
00415
00420 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00421 bool open();
00422 #else
00423 bool open(std::auto_ptr<Glib::Error>& error);
00424 #endif //GLIBMM_EXCEPTIONS_ENABLED
00425
00426
00429 void close();
00430
00431
00435 bool is_opened() const;
00436
00437
00443 Glib::RefPtr<Client> get_client();
00444
00450 Glib::RefPtr<const Client> get_client() const;
00451
00452
00456 ConnectionOptions get_options() const;
00457
00461 Glib::ustring get_server_version() const;
00462
00463
00468 Glib::ustring get_database() const;
00469
00474 Glib::ustring get_dsn() const;
00475
00484 bool set_dsn(const Glib::ustring& dsn);
00485
00493 Glib::ustring get_cnc_string() const;
00494
00495
00499 Glib::ustring get_provider() const;
00500
00504 Glib::RefPtr<ServerProvider> get_provider_obj();
00505
00509 Glib::RefPtr<const ServerProvider> get_provider_obj() const;
00510
00511
00512
00513
00517 const ServerProviderInfo* get_infos() const;
00518
00519
00523 Glib::ustring get_username() const;
00524
00529 bool set_username(const Glib::ustring& username);
00530
00534 Glib::ustring get_password() const;
00535
00540 bool set_password(const Glib::ustring& password);
00541
00542
00556 void add_event(const Glib::RefPtr<ConnectionEvent>& error);
00557
00566 Glib::RefPtr<ConnectionEvent> add_event_string(const Glib::ustring& error);
00567
00568
00569
00580 void add_events_list(GList *error_list);
00581
00585 void clear_events_list();
00586
00587
00593 bool change_database(const Glib::ustring& name);
00594
00595
00596
00597
00598
00599
00600
00601
00602
00620 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00621 Glib::RefPtr<DataModel> execute_select_command(const Command& cmd, const Glib::RefPtr<ParameterList>& params);
00622 #else
00623 Glib::RefPtr<DataModel> execute_select_command(const Command& cmd, const Glib::RefPtr<ParameterList>& params, std::auto_ptr<Glib::Error>& error);
00624 #endif //GLIBMM_EXCEPTIONS_ENABLED
00625
00626 Glib::RefPtr<DataModel> execute_select_command(const Command& cmd);
00627 Glib::RefPtr<DataModel> execute_select_command(const Glib::ustring& cmd);
00628
00629
00646 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00647 int execute_non_select_command(const Command& cmd, const Glib::RefPtr<ParameterList>& params);
00648 #else
00649 int execute_non_select_command(const Command& cmd, const Glib::RefPtr<ParameterList>& params, std::auto_ptr<Glib::Error>& error);
00650 #endif //GLIBMM_EXCEPTIONS_ENABLED
00651
00652 int execute_non_select_command(const Command& cmd);
00653 int execute_non_select_command(const Glib::ustring& cmd);
00654
00655
00656
00663 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00664 Glib::RefPtr<const TransactionStatus> get_transaction_status() const;
00665 #else
00666 Glib::RefPtr<const TransactionStatus> get_transaction_status(std::auto_ptr<Glib::Error>& error) const;
00667 #endif //GLIBMM_EXCEPTIONS_ENABLED
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00697 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00698 bool begin_transaction(const Glib::ustring& name, TransactionIsolation level);
00699 #else
00700 bool begin_transaction(const Glib::ustring& name, TransactionIsolation level, std::auto_ptr<Glib::Error>& error);
00701 #endif //GLIBMM_EXCEPTIONS_ENABLED
00702
00703
00711 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00712 bool commit_transaction(const Glib::ustring& name);
00713 #else
00714 bool commit_transaction(const Glib::ustring& name, std::auto_ptr<Glib::Error>& error);
00715 #endif //GLIBMM_EXCEPTIONS_ENABLED
00716
00717
00726 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00727 bool rollback_transaction(const Glib::ustring& name);
00728 #else
00729 bool rollback_transaction(const Glib::ustring& name, std::auto_ptr<Glib::Error>& error);
00730 #endif //GLIBMM_EXCEPTIONS_ENABLED
00731
00732
00738 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00739 bool add_savepoint(const Glib::ustring& name);
00740 #else
00741 bool add_savepoint(const Glib::ustring& name, std::auto_ptr<Glib::Error>& error);
00742 #endif //GLIBMM_EXCEPTIONS_ENABLED
00743
00744
00750 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00751 bool rollback_savepoint(const Glib::ustring& name);
00752 #else
00753 bool rollback_savepoint(const Glib::ustring& name, std::auto_ptr<Glib::Error>& error);
00754 #endif //GLIBMM_EXCEPTIONS_ENABLED
00755
00756
00762 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00763 bool delete_savepoint(const Glib::ustring& name);
00764 #else
00765 bool delete_savepoint(const Glib::ustring& name, std::auto_ptr<Glib::Error>& error);
00766 #endif //GLIBMM_EXCEPTIONS_ENABLED
00767
00768
00769
00770
00771
00772
00773
00778 Glib::ListHandle< Glib::RefPtr<ConnectionEvent> > get_events();
00779
00784 Glib::ListHandle< Glib::RefPtr<const ConnectionEvent> > get_events() const;
00785
00786
00791 Glib::ustring value_to_sql_string(const Value& from) const;;
00792
00793
00798 bool supports_feature(ConnectionFeature feature) const;
00799
00800
00818 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00819 Glib::RefPtr<DataModel> get_schema(ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params);
00820 #else
00821 Glib::RefPtr<DataModel> get_schema(ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params, std::auto_ptr<Glib::Error>& error);
00822 #endif //GLIBMM_EXCEPTIONS_ENABLED
00823
00824
00842 #ifdef GLIBMM_EXCEPTIONS_ENABLED
00843 Glib::RefPtr<const DataModel> get_schema(ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params) const;
00844 #else
00845 Glib::RefPtr<const DataModel> get_schema(ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params, std::auto_ptr<Glib::Error>& error) const;
00846 #endif //GLIBMM_EXCEPTIONS_ENABLED
00847
00848
00862 Glib::RefPtr<DataModel> get_schema(ConnectionSchema schema);
00863
00877 Glib::RefPtr<const DataModel> get_schema(ConnectionSchema schema) const;
00878
00879
00888 Glib::ustring get_last_insert_id(const Glib::RefPtr<DataModel>& recset) const;
00889
00890
00896 Glib::SignalProxy1< void,const Glib::RefPtr<ConnectionEvent>& > signal_error();
00897
00898
00904 Glib::SignalProxy0< void > signal_conn_opened();
00905
00906
00912 Glib::SignalProxy0< void > signal_conn_to_close();
00913
00914
00920 Glib::SignalProxy0< void > signal_conn_closed();
00921
00922
00928 Glib::SignalProxy0< void > signal_dsn_changed();
00929
00930
00936 Glib::SignalProxy0< void > signal_transaction_status_changed();
00937
00938
00939 public:
00940
00941 public:
00942
00943 #ifdef GLIBMM_VFUNCS_ENABLED
00944 #endif //GLIBMM_VFUNCS_ENABLED
00945
00946 protected:
00947
00948 #ifdef GLIBMM_VFUNCS_ENABLED
00949 #endif //GLIBMM_VFUNCS_ENABLED
00950
00951
00952 #ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
00953 virtual void on_error(const Glib::RefPtr<ConnectionEvent>& error);
00954 virtual void on_conn_opened();
00955 virtual void on_conn_to_close();
00956 virtual void on_conn_closed();
00957 virtual void on_dsn_changed();
00958 virtual void on_transaction_status_changed();
00959 #endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
00960
00961
00962 };
00963
00964 }
00965 }
00966
00967
00968 namespace Glib
00969 {
00975 Glib::RefPtr<Gnome::Gda::Connection> wrap(GdaConnection* object, bool take_copy = false);
00976 }
00977
00978
00979 #endif
00980