| Midgard2 Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | Object Hierarchy | Signals | ||||
#include <midgard/midgard.h> #define GETTEXT_PACKAGE typedef MidgardConnectionClass; MidgardConnectionPrivate; typedef midgard_connection; MidgardConnection * midgard_connection_new (void); gboolean midgard_connection_open (MidgardConnection *self, const gchar *name, GError **error); gboolean midgard_connection_open_config (MidgardConnection *self, MidgardConfig *config); gboolean midgard_connection_set_loglevel (MidgardConnection *self, const gchar *level, GLogFunc log_func); guint midgard_connection_get_loglevel (MidgardConnection *self); void midgard_connection_set_loghandler (MidgardConnection *self, guint loghandler); guint midgard_connection_get_loghandler (MidgardConnection *self); gint midgard_connection_get_error (MidgardConnection *self); const gchar * midgard_connection_get_error_string (MidgardConnection *self); void midgard_connection_set_error (MidgardConnection *self, gint errcode); MidgardUser * midgard_connection_get_user (MidgardConnection *self); MidgardConnection * midgard_connection_copy (MidgardConnection *self); gboolean midgard_connection_reopen (MidgardConnection *self); gchar ** midgard_connection_list_auth_types (MidgardConnection *self, guint *n_types);
"auth-changed" : Run Last / No Recursion / No Hooks "connected" : Run Last / No Recursion / No Hooks "disconnected" : Run Last / No Recursion / No Hooks "error" : Run Last / No Recursion / No Hooks "lost-provider" : Run Last / No Recursion / No Hooks
MidgardConnection represents database connection, and runtime Midgard related environment variables. Logged in MidgardUser or midgard_error for example.
Use midgard_connection_new() to initialize new MidgardConnection object, and
midgard_connection_open() to open database connection.
There is also midgard_connection_open_config() for cases, if configuration file
is not in common path, and this file could be represented by MidgardConfig.
MidgardConnection * midgard_connection_new (void);
Initializes new instance of MidgardConnection object type.
MidgardConnectionClass has no properties registered as class members. Every internal data of MidgardConnection object is accessible with API functions, and is not settable or gettable as property's value. Particular methods should be implemented for language bindings.
MidgardConnection objects holds runtime ( or request ) non persistent data like authentication type, debug level, etc.
Persistent data like database name, blobs directory are associated with MidgardConfig object.
Returns : |
pointer to MidgardConnection object or NULL on failure.
|
gboolean midgard_connection_open (MidgardConnection *self, const gchar *name, GError **error);
Opens a connection to the database, which is defined in named configuration. The configuration file is read from the system configuration directory and is used as the configuration for the created connection. For example: `/etc` directory is taken into account if library is compiled with `/usr' prefix, `/usr/local/etc` if compiled with `/usr/local` prefix, etc.
Consider using midgard_connection_open_config(), if you need to open connection to
database which is configured in user's home directory.
If the named database configuration can not be read or the connection fails,
then FALSE is returned and an error message is written to the global midgard
error state.
It also initializes MidgardSchema object (which is encapsulated by implementation ) and register all MgdSchema, MgdObjectClass derived classes defined by user. This happens only when basic Midgard classes are not registered in GType system. This is recommended way to initialize MgdSchema types.
gboolean midgard_connection_open_config (MidgardConnection *self, MidgardConfig *config);
Opens a MidgardConnection with the given configuration.
Take a look at midgard_connection_open() wrt MidgardSchema.
If MidgardConnection is already associated with given config, method returns TRUE.
If associated with another one, FALSE is returned and MGD_ERR_INTERNAL error is set.
|
[in]newly initialized MidgardConnection object |
|
MidgardConfig object |
Returns : |
TRUE on success, FALSE otherwise
|
gboolean midgard_connection_set_loglevel (MidgardConnection *self, const gchar *level, GLogFunc log_func);
Sets log level of the given MidgardConnection. Overwrites internal MidgardConnection's log level defined in configuration file. By default MidgardConnection holds loglevel which is associated with ( and duplicated from ) MidgardConfig. MidgardConfig object's log level isn't changed by this function
This method is a shortcut which sets correctly loghandler,loglevel
and GLib's log function. Default log function will be used if NULL
is defined. Core's default function is midgard_error_default_log.
Available levels: error, warn, warning, info, message, debug. warn is default loglevel, SQL queries are logged with debug level. With info level, function names ( and classes' names ) are ( at least should be) logged in language bindings
guint midgard_connection_get_loglevel (MidgardConnection *self);
|
MidgardConnection instance |
Returns : |
unsigned integer flag specified by GLogLevelFlags. |
void midgard_connection_set_loghandler (MidgardConnection *self,
guint loghandler);
Sets internal loghandler id associated with G_LOG_DOMAIN and loglevel. Caller is responsible to remove loghandler using g_log_remove_handler when new loglevel for G_LOG_DOMAIN is set.
See also: midgard_connection_set_loglevel
|
MidgardConnection instance |
|
loghandler id |
guint midgard_connection_get_loghandler (MidgardConnection *self);
|
MidgardConnection instance |
Returns : |
unsigned integer value which is associated with G_LOG_DOMAIN and MidgardConnection's loglevel currently set. |
gint midgard_connection_get_error (MidgardConnection *self);
Error id may be one of set by midgard_error.
|
MidgardConnection instance |
Returns : |
Last error id set |
const gchar * midgard_connection_get_error_string (MidgardConnection *self);
Error string may be one set by midgard_error.
|
MidgardConnection instance |
Returns : |
last error string |
void midgard_connection_set_error (MidgardConnection *self,
gint errcode);
Valid errcode is one defined in MgdErrorGeneric.
|
MidgardConnection instance |
|
error code |
MidgardUser * midgard_connection_get_user (MidgardConnection *self);
NULL is explicitly returned if there's no midgard_user logged in for the given MidgardConnection. See also MidgardUser methods if you need midgard_person associated with user.
|
MidgardConnection instance |
Returns : |
A pointer to MidgardUser instance or NULL
|
MidgardConnection * midgard_connection_copy (MidgardConnection *self);
This function duplicates given MidgardConnection. It doesn't make deep copy. All persistant data are kept unchanged, but runtime related members are reset to default state. This function is helpful if application is forking and new processes might have different environment variables.
Call g_object_unref if returned object is no longer needed.
|
MidgardConnection instance |
Returns : |
Newly allocated and duplicated MidgardConnection |
gboolean midgard_connection_reopen (MidgardConnection *self);
This is MySQL optimized workaround for lost connection event.
gchar ** midgard_connection_list_auth_types (MidgardConnection *self, guint *n_types);
List available and registered authentication types.
Use g_free() to free returned array.
|
MidgardConnection instance |
|
a pointer to store number of returned types |
Returns : |
NULL terminated array with authentication types. |
"auth-changed" signalvoid user_function (midgard_connection *midgard_connection, gpointer user_data) : Run Last / No Recursion / No Hooks
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"connected" signalvoid user_function (midgard_connection *midgard_connection, gpointer user_data) : Run Last / No Recursion / No Hooks
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"disconnected" signalvoid user_function (midgard_connection *midgard_connection, gpointer user_data) : Run Last / No Recursion / No Hooks
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"error" signalvoid user_function (midgard_connection *midgard_connection, gpointer user_data) : Run Last / No Recursion / No Hooks
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"lost-provider" signalvoid user_function (midgard_connection *midgard_connection, gpointer user_data) : Run Last / No Recursion / No Hooks
|
the object which received the signal. |
|
user data set when the signal handler was connected. |