MgServer

MgServer — Manages the connection to a database server.

Synopsis




            MgServer;
enum        MgServerQueryType;
guint       mg_server_get_type              (void);
GObject*    mg_server_new                   (MgConf *conf);
gboolean    mg_server_set_datasource        (MgServer *srv,
                                             const gchar *datasource);
gchar*      mg_server_get_datasource        (MgServer *srv);
gboolean    mg_server_set_user_name         (MgServer *srv,
                                             const gchar *username);
gchar*      mg_server_get_user_name         (MgServer *srv);
gboolean    mg_server_set_user_password     (MgServer *srv,
                                             const gchar *password);
void        mg_server_reset                 (MgServer *srv);
GdaConnection* mg_server_get_gda_connection (MgServer *srv);
gboolean    mg_server_open_connect          (MgServer *srv,
                                             GError **error);
gboolean    mg_server_conn_is_opened        (MgServer *srv);
void        mg_server_close_connect         (MgServer *srv);
void        mg_server_close_connect_no_warn (MgServer *srv);
MgConf*     mg_server_get_conf              (MgServer *srv);
MgServerOpMode mg_server_get_sql_op_mode    (MgServer *srv,
                                             const gchar *query);
MgResultSet* mg_server_do_query             (MgServer *srv,
                                             const gchar *query,
                                             MgServerQueryType type,
                                             GError **error);
gboolean    mg_server_update_dbms_data      (MgServer *srv,
                                             GError **error);
void        mg_server_stop_update_dbms_data (MgServer *srv);
MgDataHandler* mg_server_get_handler_by_name
                                            (MgServer *srv,
                                             const gchar *name);
MgDataHandler* mg_server_get_handler_by_type
                                            (MgServer *srv,
                                             MgServerDataType *type);
MgDataHandler* mg_server_get_handler_by_gda (MgServer *srv,
                                             GdaValueType gda_type);
GSList*     mg_server_get_plugin_handlers   (MgServer *srv);
MgUser*     mg_server_get_user_by_name      (MgServer *srv,
                                             const gchar *username);
GSList*     mg_server_get_data_types        (MgServer *srv);
MgServerDataType* mg_server_get_data_type_by_name
                                            (MgServer *srv,
                                             const gchar *typename);
MgServerDataType* mg_server_get_data_type_by_xml_id
                                            (MgServer *srv,
                                             const gchar *xml_id);
GSList*     mg_server_get_functions         (MgServer *srv);
GSList*     mg_server_get_functions_by_name (MgServer *srv,
                                             const gchar *funcname);
MgServerFunction* mg_server_get_function_by_name_arg
                                            (MgServer *srv,
                                             const gchar *funcname,
                                             const GSList *argtypes);
MgServerFunction* mg_server_get_function_by_dbms_id
                                            (MgServer *srv,
                                             const gchar *dbms_id);
MgServerFunction* mg_server_get_function_by_xml_id
                                            (MgServer *srv,
                                             const gchar *xml_id);
GSList*     mg_server_get_aggregates        (MgServer *srv);
GSList*     mg_server_get_aggregates_by_name
                                            (MgServer *srv,
                                             const gchar *aggname);
MgServerAggregate* mg_server_get_aggregate_by_name_arg
                                            (MgServer *srv,
                                             const gchar *aggname,
                                             MgServerDataType *argtype);
MgServerAggregate* mg_server_get_aggregate_by_dbms_id
                                            (MgServer *srv,
                                             const gchar *dbms_id);
MgServerAggregate* mg_server_get_aggregate_by_xml_id
                                            (MgServer *srv,
                                             const gchar *xml_id);
MgDataHandler* mg_server_get_object_handler (MgServer *srv,
                                             GObject *object);
void        mg_server_set_object_handler    (MgServer *srv,
                                             GObject *object,
                                             MgDataHandler *handler);
void        mg_server_unset_object_handler  (MgServer *srv,
                                             GObject *object);
gboolean    mg_server_object_has_handler    (MgServer *srv,
                                             GObject *object);
void        mg_server_set_object_func_handler
                                            (MgServer *srv,
                                             MgDataHandler* (*func) (MgServer *, GObject *));
gchar*      mg_server_stringify_value       (MgServer *srv,
                                             const GdaValue *value);
gchar*      mg_server_escape_chars          (MgServer *srv,
                                             const gchar *string);
GdaDataModel* mg_server_get_gda_schema      (MgServer *srv,
                                             GdaConnectionSchema schema,
                                             GdaParameterList *params);
void        mg_server_dump                  (MgServer *srv,
                                             gint offset);

Object Hierarchy


  GObject
   +----GdaClient
         +----MgServer

Implemented Interfaces

MgServer implements MgXmlStorage.

Properties


  "with-functions"       gboolean              : Read / Write

Signals


"conn-closed"
            void        user_function      (MgServer *mgserver,
                                            gpointer  user_data)      : Run first
"conn-opened"
            void        user_function      (MgServer *mgserver,
                                            gpointer  user_data)      : Run first
"conn-to-close"
            void        user_function      (MgServer *mgserver,
                                            gpointer  user_data)      : Run first
"data-aggregate-added"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-aggregate-removed"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-aggregate-updated"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-function-added"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-function-removed"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-function-updated"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-type-added"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-type-removed"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-type-updated"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first
"data-update-finished"
            void        user_function      (MgServer *mgserver,
                                            gpointer  user_data)      : Run first
"data-update-started"
            void        user_function      (MgServer *mgserver,
                                            gpointer  user_data)      : Run first
"object-handler-updated"
            void        user_function      (MgServer *mgserver,
                                            gpointer  user_data)      : Run first
"update-progress"
            void        user_function      (MgServer *mgserver,
                                            gpointer  arg1,
                                            guint     arg2,
                                            guint     arg3,
                                            gpointer  user_data)      : Run first

Description

This object is the "access point" to the DBMS. It manages lists of the DBMS's attributes (such as the available data types, function, ...) and is responsible for opening and closing the connection to the DBMS. Also any query sent to the DBMS is done through this object.

This object is also responsible for the conversion of data types (data types defined within the database and data types known to the Libgda library), and for providing the MgDataHandler objects to manipulate data of each data type.

It implements the MgXmlStorage interface.

Details

MgServer

typedef struct _MgServer MgServer;


enum MgServerQueryType

typedef enum {
	MG_SERVER_QUERY_SQL,
	MG_SERVER_QUERY_XML
} MgServerQueryType;

Used to specify which type of query is sent to the DBMS. See the libgda documentation about what XML queries are.


mg_server_get_type ()

guint       mg_server_get_type              (void);

Returns :

mg_server_new ()

GObject*    mg_server_new                   (MgConf *conf);

Creates a new MgServer object

conf : a MgConf object
Returns : the new object

mg_server_set_datasource ()

gboolean    mg_server_set_datasource        (MgServer *srv,
                                             const gchar *datasource);

Sets the data source of the server. If the connection is already opened, then no action is performed at all and FALSE is returned.

srv : a MgServer object
datasource : a gda datasource
Returns : TRUE on success

mg_server_get_datasource ()

gchar*      mg_server_get_datasource        (MgServer *srv);

Get the data source of the server.

srv : a MgServer object
Returns : a new string with the datasource, or NULL

mg_server_set_user_name ()

gboolean    mg_server_set_user_name         (MgServer *srv,
                                             const gchar *username);

Sets the user name for the connection to the server. If the connection is already opened, then no action is performed at all and FALSE is returned.

srv : a MgServer object
username :
Returns : TRUE on success

mg_server_get_user_name ()

gchar*      mg_server_get_user_name         (MgServer *srv);

Get the user name for the connection to the server.

srv : a MgServer object
Returns : a new string with the user name, or NULL

mg_server_set_user_password ()

gboolean    mg_server_set_user_password     (MgServer *srv,
                                             const gchar *password);

Sets the user password for the connection to the server. If the connection is already opened, then no action is performed at all and FALSE is returned.

srv : a MgServer object
password :
Returns : TRUE on success

mg_server_reset ()

void        mg_server_reset                 (MgServer *srv);

Reset the MgServer as it was when created; that is: close the connection if opened, and get rid of any data type, function and aggregate it has.

srv : a MgServer object

mg_server_get_gda_connection ()

GdaConnection* mg_server_get_gda_connection (MgServer *srv);

Get the GdaConnection object used by srv, if the connection is opened.

srv : a MgServer object
Returns : the GdaConnection, or NULL

mg_server_open_connect ()

gboolean    mg_server_open_connect          (MgServer *srv,
                                             GError **error);

Opens the connection to the DBMS.

srv : a MgServer object
error : location to store error, or NULL
Returns : TRUE if success and FALSE otherwise (and error is positionned)

mg_server_conn_is_opened ()

gboolean    mg_server_conn_is_opened        (MgServer *srv);

Checks wether the connection to the DBMS is opened or not

srv : a MgServer object
Returns : TRUE if the connection is opened

mg_server_close_connect ()

void        mg_server_close_connect         (MgServer *srv);

Closes the connection to the DBMS. First the "conn_to_close" signal is emitted. This function should preferably be called instead of the mg_server_close_connect_no_warn() function.

srv : a MgServer object

mg_server_close_connect_no_warn ()

void        mg_server_close_connect_no_warn (MgServer *srv);

Closes the connection to the DBMS. Warning: "conn_to_close" signal is NOT emitted.

srv : a MgServer object

mg_server_get_conf ()

MgConf*     mg_server_get_conf              (MgServer *srv);

Fetch the MgConf object to which the MgServer belongs.

srv : a MgServer object
Returns : the MgConf object

mg_server_get_sql_op_mode ()

MgServerOpMode mg_server_get_sql_op_mode    (MgServer *srv,
                                             const gchar *query);

Get the operation type (= mode) which is performed by the query given as argument. The query MUST contain only one statement, not several separated by ';'

srv : a MgServer object
query : an SQL query
Returns : the query type (mode).

mg_server_do_query ()

MgResultSet* mg_server_do_query             (MgServer *srv,
                                             const gchar *query,
                                             MgServerQueryType type,
                                             GError **error);

Sends a query to the DBMS to which the connection is established. If the query is a SELECT one, then a new MgResultSet is returned (it's up to the caller to unref that object); otherwise NULL is returned. The error variable contains the error code if an error occurred.

srv : a MgServer object
query : the query to be executed
type : the query type (SQL or XML)
error : location to store error, or NULL
Returns : a new MgResultSet object or NULL

mg_server_update_dbms_data ()

gboolean    mg_server_update_dbms_data      (MgServer *srv,
                                             GError **error);

Synchronise the list of data types, functions, etc the MgServer object has with what is in the DBMS the connection is opened to. The connection to the DBMS MUST be opened.

srv : a MgServer object
error : location to store error, or NULL
Returns : TRUE if no error

mg_server_stop_update_dbms_data ()

void        mg_server_stop_update_dbms_data (MgServer *srv);

When the server updates its internal lists of DBMS objects, a call to this function will stop that update process. It has no effect when the server is not updating its DBMS data.

srv : a MgServer object

mg_server_get_handler_by_name ()

MgDataHandler* mg_server_get_handler_by_name
                                            (MgServer *srv,
                                             const gchar *name);

Get the MgDataHandler from its name.

srv : a MgServer object
name :
Returns : the MgDataHandler object

mg_server_get_handler_by_type ()

MgDataHandler* mg_server_get_handler_by_type
                                            (MgServer *srv,
                                             MgServerDataType *type);

Get the MgDataHandler for a data type

srv : a MgServer object
type :
Returns : the MgDataHandler object

mg_server_get_handler_by_gda ()

MgDataHandler* mg_server_get_handler_by_gda (MgServer *srv,
                                             GdaValueType gda_type);

Get the MgDataHandler for a gda type: the first DataHandler which can handle the requested type is returned. If no good handler can be found, then a default one will be provided. This function never returns NULL.

srv : a MgServer object
gda_type :
Returns : the MgDataHandler object

mg_server_get_plugin_handlers ()

GSList*     mg_server_get_plugin_handlers   (MgServer *srv);

Get a list of all the MgDataHandler plugins used by the MgServer.

srv : a MgServer object
Returns : an allocated list of plugins

mg_server_get_user_by_name ()

MgUser*     mg_server_get_user_by_name      (MgServer *srv,
                                             const gchar *username);

Find a MgUser from its name.

srv : a MgServer object
username :
Returns : a pointer to the requested object, or NULL if the object cannot be found.

mg_server_get_data_types ()

GSList*     mg_server_get_data_types        (MgServer *srv);

Get the list of data types;

srv : a MgServer object
Returns : the list (the caller must free the list after usage)

mg_server_get_data_type_by_name ()

MgServerDataType* mg_server_get_data_type_by_name
                                            (MgServer *srv,
                                             const gchar *typename);

Find a data type from its DBMS name

srv : a MgServer object
typename :
Returns : the data type or NULL if it cannot be found

mg_server_get_data_type_by_xml_id ()

MgServerDataType* mg_server_get_data_type_by_xml_id
                                            (MgServer *srv,
                                             const gchar *xml_id);

To find a MgServerDataType using its XML id.

srv : a MgServer object
xml_id : the XML identifier of the data type to be found
Returns : the data type or NULL if it cannot be found

mg_server_get_functions ()

GSList*     mg_server_get_functions         (MgServer *srv);

To get the complete list of functions

srv : a MgServer object
Returns : the allocated list of functions

mg_server_get_functions_by_name ()

GSList*     mg_server_get_functions_by_name (MgServer *srv,
                                             const gchar *funcname);

To get the list of DBMS functions which match the given name.

srv : a MgServer object
funcname : name of the function
Returns : the allocated list of functions

mg_server_get_function_by_name_arg ()

MgServerFunction* mg_server_get_function_by_name_arg
                                            (MgServer *srv,
                                             const gchar *funcname,
                                             const GSList *argtypes);

To find a DBMS functions which is uniquely identified by its name and the type(s) of its argument(s).

srv : a MgServer object
funcname : name of the function
argtypes : a list of MgServerDataType objects
Returns : The function or NULL if not found

mg_server_get_function_by_dbms_id ()

MgServerFunction* mg_server_get_function_by_dbms_id
                                            (MgServer *srv,
                                             const gchar *dbms_id);

To find a DBMS functions which is uniquely identified by its DBMS identifier

srv : a MgServer object
dbms_id :
Returns : The function or NULL if not found

mg_server_get_function_by_xml_id ()

MgServerFunction* mg_server_get_function_by_xml_id
                                            (MgServer *srv,
                                             const gchar *xml_id);

To find a DBMS functions which is uniquely identified by its XML identifier

srv : a MgServer object
xml_id :
Returns : The function or NULL if not found

mg_server_get_aggregates ()

GSList*     mg_server_get_aggregates        (MgServer *srv);

To get the complete list of aggregates

srv : a MgServer object
Returns : the allocated list of aggregates

mg_server_get_aggregates_by_name ()

GSList*     mg_server_get_aggregates_by_name
                                            (MgServer *srv,
                                             const gchar *aggname);

To get the list of DBMS aggregates which match the given name.

srv : a MgServer object
aggname : the name of the aggregate
Returns : the allocated list of aggregates

mg_server_get_aggregate_by_name_arg ()

MgServerAggregate* mg_server_get_aggregate_by_name_arg
                                            (MgServer *srv,
                                             const gchar *aggname,
                                             MgServerDataType *argtype);

To find a DBMS functions which is uniquely identified by its name and the type of its argument.

srv : a MgServer object
aggname : the name of the aggregate
argtype : the type of argument or NULL
Returns : The aggregate or NULL if not found

mg_server_get_aggregate_by_dbms_id ()

MgServerAggregate* mg_server_get_aggregate_by_dbms_id
                                            (MgServer *srv,
                                             const gchar *dbms_id);

To find a DBMS functions which is uniquely identified by its name and the type of its argument.

srv : a MgServer object
dbms_id :
Returns : The aggregate or NULL if not found

mg_server_get_aggregate_by_xml_id ()

MgServerAggregate* mg_server_get_aggregate_by_xml_id
                                            (MgServer *srv,
                                             const gchar *xml_id);

To find a DBMS aggregates which is uniquely identified by its XML identifier

srv : a MgServer object
xml_id :
Returns : The aggregate or NULL if not found

mg_server_get_object_handler ()

MgDataHandler* mg_server_get_object_handler (MgServer *srv,
                                             GObject *object);

Get the right MgDataHandler object reference to manage data which is "linked" to the object. The object will usually be a MgServerDataType, a MgServerFunction, or a MgServerAggregate.

The returned MgDataHandler depends on the loaded plugins and on the user preferences regarding how these plugins are to be used. If the user has not set any preference for the object, then some default rules are used: <ul> <li> for MgServerDataType, the MgDataHandler corresponding to the gda type of the MgServerDataType is returned</li></ul> -> for MgServerFunction, the MgDataHandler corresponding to the MgServerDataType returned by the function is returned -> ...

srv : a MgServer object
object : a GObject object
Returns : the MgDataHandler associated to the given object, NEVER returns NULL.

mg_server_set_object_handler ()

void        mg_server_set_object_handler    (MgServer *srv,
                                             GObject *object,
                                             MgDataHandler *handler);

This function is the opposite of the mg_server_get_object_handler() function: it "attaches" a MgDataHandler object to any given object, and a subsequent call to mg_server_get_object_handler(object) will return the MgDataHandler object.

srv : a MgServer object
object : a GObject
handler :

mg_server_unset_object_handler ()

void        mg_server_unset_object_handler  (MgServer *srv,
                                             GObject *object);

Shortcut to mg_server_set_object_handler() with NULL as "handler" argument.

srv : a MgServer object
object : a GObject

mg_server_object_has_handler ()

gboolean    mg_server_object_has_handler    (MgServer *srv,
                                             GObject *object);

Tells if a MgDataHandler object has been assigned to the object given as argument, or if the MgDataHandler which would be returned by the mg_server_get_object_handler() function is a default one.

srv : a MgServer object
object : a GObject
Returns : TRUE if a MgDataHandler object has been assigned to the object.

mg_server_set_object_func_handler ()

void        mg_server_set_object_func_handler
                                            (MgServer *srv,
                                             MgDataHandler* (*func) (MgServer *, GObject *));

This function provides a way for the MgServer function to apply rules to find an appropriate MgDataHandler for an object.

srv : a MgServer object
func : a function

mg_server_stringify_value ()

gchar*      mg_server_stringify_value       (MgServer *srv,
                                             const GdaValue *value);

Renders a value as a string, and ensures the string is UTF-8 encoded.

srv : a MgServer object
value : a value to be stringified
Returns : the new string

mg_server_escape_chars ()

gchar*      mg_server_escape_chars          (MgServer *srv,
                                             const gchar *string);

Escapes the special caracters from a string. The new string can then safely be sent to the DBMS.

srv : a MgServer object
string :
Returns : the escaped string

mg_server_get_gda_schema ()

GdaDataModel* mg_server_get_gda_schema      (MgServer *srv,
                                             GdaConnectionSchema schema,
                                             GdaParameterList *params);

Get a direct access to the libgda's function call to get a DBMS schema. It should not directely be used since libmergeant hides any necessary call to it.

srv : a MgServer object
schema : the requested schema
params : some parameters for the requested schema, or NULL
Returns : the data model, or NULL if an error occurred

mg_server_dump ()

void        mg_server_dump                  (MgServer *srv,
                                             gint offset);

Writes a textual description of the object to STDOUT. This function only exists if libmergeant is compiled with the "--enable-debug" option.

srv : a MgServer object
offset : the offset (in caracters) at which the dump will start

Property Details

The "with-functions" property

  "with-functions"       gboolean              : Read / Write

Default value: FALSE

Signal Details

The "conn-closed" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
user_data : user data set when the signal handler was connected.

The "conn-opened" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
user_data : user data set when the signal handler was connected.

The "conn-to-close" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
user_data : user data set when the signal handler was connected.

The "data-aggregate-added" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-aggregate-removed" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-aggregate-updated" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-function-added" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-function-removed" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-function-updated" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-type-added" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-type-removed" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-type-updated" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.

The "data-update-finished" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
user_data : user data set when the signal handler was connected.

The "data-update-started" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
user_data : user data set when the signal handler was connected.

The "object-handler-updated" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
user_data : user data set when the signal handler was connected.

The "update-progress" signal

void        user_function                  (MgServer *mgserver,
                                            gpointer  arg1,
                                            guint     arg2,
                                            guint     arg3,
                                            gpointer  user_data)      : Run first

mgserver : the object which received the signal.
arg1 :
arg2 :
arg3 :
user_data : user data set when the signal handler was connected.