libgda r3148 - in trunk: . doc/C doc/C/tmpl libgda libgda/sql-parser libgda/sqlite tests/value-holders tools
- From: vivien svn gnome org
- To: svn-commits-list gnome org
- Subject: libgda r3148 - in trunk: . doc/C doc/C/tmpl libgda libgda/sql-parser libgda/sqlite tests/value-holders tools
- Date: Sun, 27 Apr 2008 19:52:39 +0100 (BST)
Author: vivien
Date: Sun Apr 27 18:52:38 2008
New Revision: 3148
URL: http://svn.gnome.org/viewvc/libgda?rev=3148&view=rev
Log:
2008-04-27 Vivien Malerba <malerba gnome-db org>
* libgda/gda-set.[ch]:
* libgda/sql-parser/gda-statement-struct-select.c:
* libgda/gda-data-model.c:
* libgda/gda-connection.c:
* tools/gda-sql.c: cosmetic changes
* tests/value-holders/check_holder.c! corrected test case
* libgda/gda-holder.c: fixed a bug in binding an object to another
* libgda/gda-meta-struct.h: reorganized the GdaMetaDbObject structure
* libgda/gda-config.[ch]: added gda_config_dsn_needs_authentication(),
and gda_config_get_dsn() now accepts username:password prepended to the DSN
* libgda/sqlite/gda-sqlite-meta.c: corrected the way tables are reported
* libgda/sqlite/gda-sqlite-provider.c: now render the FALSE keyword as 0 and
TRUE as 1 (this is how SQLite handles booleans)
* libgda/gda-meta-store.c:
* doc/C: docs. update
* libgda/gda-util.c: fixed a bug in the completion function when no proposal
exists
* libgda/gda-meta-struct.[ch]: added gda_meta_struct_complement_schema() and
gda_meta_struct_complement_default() which respectively fast-adds all the objects of a
schema or all the objects which can be named without the schema
prefix. Also added gda_meta_struct_complement_depend() which add to
the object all the database objects on which an object depends.
Modified:
trunk/ChangeLog
trunk/doc/C/howto.xml
trunk/doc/C/libgda-4.0-docs.sgml
trunk/doc/C/libgda-4.0-sections.txt
trunk/doc/C/tmpl/gda-config.sgml
trunk/doc/C/tmpl/gda-data-handler.sgml
trunk/doc/C/tmpl/gda-meta-struct.sgml
trunk/libgda/gda-config.c
trunk/libgda/gda-config.h
trunk/libgda/gda-connection.c
trunk/libgda/gda-data-model.c
trunk/libgda/gda-holder.c
trunk/libgda/gda-meta-store.c
trunk/libgda/gda-meta-struct.c
trunk/libgda/gda-meta-struct.h
trunk/libgda/gda-set.c
trunk/libgda/gda-set.h
trunk/libgda/gda-util.c
trunk/libgda/sql-parser/gda-statement-struct-select.c
trunk/libgda/sql-parser/gda-statement-struct.c
trunk/libgda/sqlite/gda-sqlite-meta.c
trunk/libgda/sqlite/gda-sqlite-provider.c
trunk/tests/value-holders/check_holder.c
trunk/tools/command-exec.c
trunk/tools/gda-sql.c
Modified: trunk/doc/C/howto.xml
==============================================================================
--- trunk/doc/C/howto.xml (original)
+++ trunk/doc/C/howto.xml Sun Apr 27 18:52:38 2008
@@ -306,7 +306,7 @@
gda_value_free (table_name);
if (dbo) {
/* the "customers" table has been found, its details are in dbo */
- GdaMetaTable *table = GDA_META_DB_OBJECT_GET_TABLE (dbo);
+ GdaMetaTable *table = GDA_META_TABLE (dbo);
GSList *list;
for (list = table->columns: list; list = list->next)
g_print ("Column: %s\n", ((GdaMetaTableColumn*) list->data)->column_name);
Modified: trunk/doc/C/libgda-4.0-docs.sgml
==============================================================================
--- trunk/doc/C/libgda-4.0-docs.sgml (original)
+++ trunk/doc/C/libgda-4.0-docs.sgml Sun Apr 27 18:52:38 2008
@@ -730,7 +730,7 @@
GdaMetaStore *store;
cnc = gda_connection_open_from_dsn (...);
-store = GDA_META_STORE (GDA_TYPE_META_STORE, "cnc", cnc, NULL);
+store = GDA_META_STORE (g_object_new (GDA_TYPE_META_STORE, "cnc", cnc, NULL));
g_object_set (G_OBJECT (cnc), "meta-store", store, NULL);
g_object_unref (store);
</programlisting>
Modified: trunk/doc/C/libgda-4.0-sections.txt
==============================================================================
--- trunk/doc/C/libgda-4.0-sections.txt (original)
+++ trunk/doc/C/libgda-4.0-sections.txt Sun Apr 27 18:52:38 2008
@@ -53,6 +53,7 @@
gda_config_get_dsn
gda_config_define_dsn
gda_config_remove_dsn
+gda_config_dsn_needs_authentication
gda_config_list_dsn
gda_config_get_nb_dsn
gda_config_get_dsn_index
@@ -1329,8 +1330,8 @@
GdaMetaDbObjectType
GdaMetaDbObject
GDA_META_DB_OBJECT
-GDA_META_DB_OBJECT_GET_TABLE
-GDA_META_DB_OBJECT_GET_VIEW
+GDA_META_TABLE
+GDA_META_VIEW
GdaMetaTable
GdaMetaView
GdaMetaTableColumn
@@ -1340,6 +1341,8 @@
GDA_META_STRUCT_ERROR
gda_meta_struct_new
gda_meta_struct_complement
+gda_meta_struct_complement_schema
+gda_meta_struct_complement_default
GdaMetaSortType
gda_meta_struct_sort_db_objects
gda_meta_struct_get_db_object
Modified: trunk/doc/C/tmpl/gda-config.sgml
==============================================================================
--- trunk/doc/C/tmpl/gda-config.sgml (original)
+++ trunk/doc/C/tmpl/gda-config.sgml Sun Apr 27 18:52:38 2008
@@ -139,6 +139,15 @@
@Returns:
+<!-- ##### FUNCTION gda_config_dsn_needs_authentication ##### -->
+<para>
+
+</para>
+
+ dsn_name:
+ Returns:
+
+
<!-- ##### FUNCTION gda_config_list_dsn ##### -->
<para>
Modified: trunk/doc/C/tmpl/gda-data-handler.sgml
==============================================================================
--- trunk/doc/C/tmpl/gda-data-handler.sgml (original)
+++ trunk/doc/C/tmpl/gda-data-handler.sgml Sun Apr 27 18:52:38 2008
@@ -6,22 +6,29 @@
<!-- ##### SECTION Long_Description ##### -->
<para>
-Because data types vary a lot from a DBMS to another, the #GdaDataHandler interface helps
-designing modules which can handle very specific pieces of data through plugins.
-Each object which imlements the #GdaDataHandler interface is expected to handle a subset of
-the possible libgda defined data types.
-</para>
-<para>
-The #GdaDataHandler object can convert a #GValue to and from both SQL and 'STR'. The SQL representation of a value is
-the actual string which would be used in an SQL statement (for example a string's SQL representation is surrounded by
-quotes such as 'that\'s a string'). The 'STR' representation is a human-readable representation of a value appropriate
-for the user's current locale. The 'STR' respresentation of a string is simply the original string without quotes but
-a numerical value or date, for instance, will be formatted according to the user's current locale.
-</para>
-<para>
-Only one object which implements this interface is needed for any given data type, and it mainly contains some
-methods to manage values (as #GValue structures). The #GnomeDbDataEntry interface is complementary to this one since
-it it implemented by widgets where the user can enter or modify some data.
+ Because data types vary a lot from a DBMS to another, the #GdaDataHandler interface helps
+ designing modules which can handle very specific pieces of data through plugins.
+ Each object which imlements the #GdaDataHandler interface is expected to handle a subset of
+ the possible libgda defined data types.
+</para>
+<para>
+ The #GdaDataHandler object can convert a #GValue to and from both SQL and 'STR'. The SQL representation of a value is
+ the actual string which would be used in an SQL statement (for example a string's SQL representation is surrounded by
+ quotes such as 'that\'s a string'). The 'STR' representation is a human-readable representation of a value appropriate
+ for the user's current locale. The 'STR' respresentation of a string is simply the original string without quotes but
+ a numerical value or date, for instance, will be formatted according to the user's current locale.
+</para>
+<para>
+ Only one object which implements this interface is needed for any given data type, and it mainly contains some
+ methods to manage values (as #GValue structures). The #GnomeDbDataEntry interface is complementary to this one since
+ it it implemented by widgets where the user can enter or modify some data.
+</para>
+<para>
+ #GdaDataHandler objects specific for each database provider and for each data type can be obtained using
+ <link linkend="gda-server-provider-get-data-handler-gtype">gda_server_provider_get_data_handler_gtype()</link> or
+ <link linkend="gda-server-provider-get-data-handler-dbms">gda_server_provider_get_data_handler_dbms()</link>, and
+ generic data handlers (for each type) can be obtained using
+ <link linkend="gda-get-default-handler">gda_get_default_handler()</link>.
</para>
<!-- ##### SECTION See_Also ##### -->
Modified: trunk/doc/C/tmpl/gda-meta-struct.sgml
==============================================================================
--- trunk/doc/C/tmpl/gda-meta-struct.sgml (original)
+++ trunk/doc/C/tmpl/gda-meta-struct.sgml Sun Apr 27 18:52:38 2008
@@ -33,7 +33,7 @@
g_print ("Table not found\n");
else {
GSList *list;
- for (list = GDA_META_DB_OBJECT_GET_TABLE (dbo)->columns; list; list = list->next) {
+ for (list = GDA_META_TABLE (dbo)->columns; list; list = list->next) {
GdaMetaTableColumn *tcol = GDA_META_TABLE_COLUMN (list->data);
g_print ("COLUMN: %s (%s)\n", tcol->column_name, tcol->column_type);
}
@@ -60,11 +60,11 @@
g_print ("Is a table\n");
else if (dbo->obj_type == GDA_META_DB_VIEW) {
g_print ("Is a view, definition is:\n");
- g_print ("%s\n", GDA_META_DB_OBJECT_GET_VIEW (dbo)->view_def);
+ g_print ("%s\n", GDA_META_VIEW (dbo)->view_def);
}
GSList *list;
- for (list = GDA_META_DB_OBJECT_GET_TABLE (dbo)->columns; list; list = list->next) {
+ for (list = GDA_META_TABLE (dbo)->columns; list; list = list->next) {
GdaMetaTableColumn *tcol = GDA_META_TABLE_COLUMN (list->data);
g_print ("COLUMN: %s (%s)\n", tcol->column_name, tcol->column_type);
}
@@ -123,6 +123,20 @@
@GDA_META_DB_TABLE:
@GDA_META_DB_VIEW:
+<!-- ##### STRUCT GdaMetaDbObject ##### -->
+<para>
+
+</para>
+
+ obj_type:
+ obj_catalog:
+ obj_schema:
+ obj_name:
+ obj_short_name:
+ obj_full_name:
+ obj_owner:
+ depend_list:
+
<!-- ##### MACRO GDA_META_DB_OBJECT ##### -->
<para>
@@ -131,7 +145,7 @@
@x:
-<!-- ##### MACRO GDA_META_DB_OBJECT_GET_TABLE ##### -->
+<!-- ##### MACRO GDA_META_TABLE ##### -->
<para>
</para>
@@ -139,7 +153,7 @@
@dbobj:
-<!-- ##### MACRO GDA_META_DB_OBJECT_GET_VIEW ##### -->
+<!-- ##### MACRO GDA_META_VIEW ##### -->
<para>
</para>
@@ -239,6 +253,30 @@
@Returns:
+<!-- ##### FUNCTION gda_meta_struct_complement_schema ##### -->
+<para>
+
+</para>
+
+ mstruct:
+ store:
+ catalog:
+ schema:
+ error:
+ Returns:
+
+
+<!-- ##### FUNCTION gda_meta_struct_complement_default ##### -->
+<para>
+
+</para>
+
+ mstruct:
+ store:
+ error:
+ Returns:
+
+
<!-- ##### ENUM GdaMetaSortType ##### -->
<para>
Modified: trunk/libgda/gda-config.c
==============================================================================
--- trunk/libgda/gda-config.c (original)
+++ trunk/libgda/gda-config.c Sun Apr 27 18:52:38 2008
@@ -272,7 +272,7 @@
xmlFree (value);
}
- if (username) {
+ if (username && *username) {
if (!info->auth_string) {
/* migrate username/password to auth_string */
gchar *s1;
@@ -287,9 +287,10 @@
info->auth_string = g_strdup_printf ("USERNAME=%s", s1);
g_free (s1);
}
- g_free (username);
- g_free (password);
}
+ g_free (username);
+ g_free (password);
+
/* signals */
if (is_new) {
@@ -692,7 +693,11 @@
* gda_config_get_dsn
* @dsn_name: the name of the DSN to look for
*
- * Get information about the DSN named @dsn_name
+ * Get information about the DSN named @dsn_name.
+ *
+ * @dsn_name's format is "[<username>[:<password>] ]<DSN>" (if <username>
+ * and optionaly <password> are provided, they are ignored). Also see the gda_dsn_split() utility
+ * function.
*
* Returns: a a pointer to read-only #GdaDataSourceInfo structure, or %NULL if not found
*/
@@ -703,16 +708,27 @@
g_return_val_if_fail (dsn_name, NULL);
+ gchar *user, *pass, *real_dsn;
+ gda_dsn_split (dsn_name, &real_dsn, &user, &pass);
+ g_free (user);
+ g_free (pass);
+ if (!real_dsn) {
+ g_warning (_("Malformed data source name '%s'"), dsn_name);
+ return NULL;
+ }
+
GDA_CONFIG_LOCK ();
if (!unique_instance)
gda_config_get ();
for (list = unique_instance->priv->dsn_list; list; list = list->next)
- if (!strcmp (((GdaDataSourceInfo*) list->data)->name, dsn_name)) {
+ if (!strcmp (((GdaDataSourceInfo*) list->data)->name, real_dsn)) {
GDA_CONFIG_UNLOCK ();
+ g_free (real_dsn);
return (GdaDataSourceInfo*) list->data;
}
GDA_CONFIG_UNLOCK ();
+ g_free (real_dsn);
return NULL;
}
@@ -855,6 +871,35 @@
}
/**
+ * gda_config_dsn_needs_auth
+ * @dsn_name: the name of a DSN, in the "[<username>[:<password>] ]<DSN>" format
+ *
+ * Tells if the data source identified as @dsn_name needs any authentication. If a <username>
+ * and optionaly a <password> are specified, they are ignored.
+ *
+ * Returns: TRUE if an authentication is needed
+ */
+gboolean
+gda_config_dsn_needs_authentication (const gchar *dsn_name)
+{
+ GdaDataSourceInfo *info;
+ GdaProviderInfo *pinfo;
+
+ info = gda_config_get_dsn (dsn_name);
+ if (!info)
+ return FALSE;
+ pinfo = gda_config_get_provider_info (info->provider);
+ if (!pinfo) {
+ g_warning (_("Provider '%s' not found"), info->provider);
+ return FALSE;
+ }
+ if (pinfo->auth_params && pinfo->auth_params->holders)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+/**
* gda_config_list_dsn
*
* Get a #GdaDataModel representing all the configured DSN, and keeping itself up to date with
Modified: trunk/libgda/gda-config.h
==============================================================================
--- trunk/libgda/gda-config.h (original)
+++ trunk/libgda/gda-config.h Sun Apr 27 18:52:38 2008
@@ -87,6 +87,7 @@
GdaDataSourceInfo *gda_config_get_dsn (const gchar *dsn_name);
gboolean gda_config_define_dsn (const GdaDataSourceInfo *info, GError **error);
gboolean gda_config_remove_dsn (const gchar *dsn_name, GError **error);
+gboolean gda_config_dsn_needs_authentication (const gchar *dsn_name);
GdaDataModel *gda_config_list_dsn (void);
gboolean gda_config_can_modify_system_config (void);
Modified: trunk/libgda/gda-connection.c
==============================================================================
--- trunk/libgda/gda-connection.c (original)
+++ trunk/libgda/gda-connection.c Sun Apr 27 18:52:38 2008
@@ -1882,6 +1882,7 @@
return str;
}
+#ifdef GDA_DEBUG_NO
static void
meta_context_dump (GdaMetaContext *context)
{
@@ -1890,6 +1891,7 @@
g_print ("GdaMetaContext for table %s: %s\n", context->table_name, str);
g_free (str);
}
+#endif
/*
*
@@ -3508,6 +3510,7 @@
GdaMetaStore *
gda_connection_get_meta_store (GdaConnection *cnc)
{
+ g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
if (cnc->priv->meta_store)
return cnc->priv->meta_store;
Modified: trunk/libgda/gda-data-model.c
==============================================================================
--- trunk/libgda/gda-data-model.c (original)
+++ trunk/libgda/gda-data-model.c Sun Apr 27 18:52:38 2008
@@ -40,9 +40,6 @@
#endif
#include "csv.h"
-#define PARENT_TYPE G_TYPE_OBJECT
-#define CLASS(model) (GDA_DATA_MODEL_CLASS (G_OBJECT_GET_CLASS (model)))
-
static void gda_data_model_class_init (gpointer g_class);
/* signals */
Modified: trunk/libgda/gda-holder.c
==============================================================================
--- trunk/libgda/gda-holder.c (original)
+++ trunk/libgda/gda-holder.c Sun Apr 27 18:52:38 2008
@@ -1187,9 +1187,8 @@
g_signal_connect (G_OBJECT (holder->priv->simple_bind), "changed",
G_CALLBACK (full_bind_changed_cb), holder);
- /* if alias_of has a different value than holder, then we set holder to the new value */
- if (gda_value_compare_ext (value1, value2))
- g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
+ /* if bind_to has a different value than holder, then we set holder to the new value */
+ gda_holder_set_value (holder, value2);
if (value1)
gda_value_free (value1);
}
Modified: trunk/libgda/gda-meta-store.c
==============================================================================
--- trunk/libgda/gda-meta-store.c (original)
+++ trunk/libgda/gda-meta-store.c Sun Apr 27 18:52:38 2008
@@ -1890,7 +1890,8 @@
* its contents.
*
* The returned connection can be used to access some other data than the one managed by @store
- * itself. Don not close the connection.
+ * itself. The returned object is not owned by the caller (if you need to keep it, then use g_object_ref()).
+ * Do not close the connection.
*
* Returns: a #GdaConnection, or %NULL
*/
@@ -3125,7 +3126,7 @@
if (dbo->obj_type != GDA_SERVER_OPERATION_CREATE_TABLE)
conflict = TRUE;
else {
- GdaMetaTable *mt = GDA_META_DB_OBJECT_GET_TABLE (eobj);
+ GdaMetaTable *mt = GDA_META_TABLE (eobj);
TableInfo *ti = TABLE_INFO (dbo);
if (g_slist_length (mt->columns) != g_slist_length (ti->columns))
conflict = TRUE;
@@ -3135,7 +3136,7 @@
if (dbo->obj_type != GDA_SERVER_OPERATION_CREATE_VIEW)
conflict = TRUE;
else {
- GdaMetaView *mv = GDA_META_DB_OBJECT_GET_VIEW (eobj);
+ GdaMetaView *mv = GDA_META_VIEW (eobj);
ViewInfo *vi = VIEW_INFO (dbo);
if (!mv->view_def ||
!vi->view_def ||
Modified: trunk/libgda/gda-meta-struct.c
==============================================================================
--- trunk/libgda/gda-meta-struct.c (original)
+++ trunk/libgda/gda-meta-struct.c Sun Apr 27 18:52:38 2008
@@ -273,6 +273,10 @@
g_assert_not_reached ();
}
+static GdaMetaDbObject * _meta_struct_complement (GdaMetaStruct *mstruct, GdaMetaStore *store, GdaMetaDbObjectType type,
+ const GValue *icatalog, const GValue *ischema, const GValue *iname,
+ const GValue *short_name, const GValue *full_name,
+ const GValue *owner, GError **error);
static gboolean determine_db_object_from_schema_and_name (GdaMetaStruct *mstruct, GdaMetaStore *store,
GdaMetaDbObjectType *int_out_type, GValue **out_catalog,
GValue **out_short_name, GValue **out_full_name,
@@ -394,16 +398,33 @@
}
}
type = real_type;
+ dbo = _meta_struct_complement (mstruct, store, type, icatalog, ischema, iname, short_name, full_name, owner, error);
+ gda_value_free (icatalog);
+ gda_value_free (ischema);
+ gda_value_free (iname);
+
+ if (short_name) gda_value_free (short_name);
+ if (full_name) gda_value_free (full_name);
+ if (owner) gda_value_free (owner);
+ return dbo;
+}
+
+static GdaMetaDbObject *
+_meta_struct_complement (GdaMetaStruct *mstruct, GdaMetaStore *store, GdaMetaDbObjectType type,
+ const GValue *icatalog, const GValue *ischema, const GValue *iname,
+ const GValue *short_name, const GValue *full_name, const GValue *owner, GError **error)
+{
/* at this point icatalog, ischema and iname are NOT NULL */
-
+ GdaMetaDbObject *dbo = NULL;
+
/* create new GdaMetaDbObject or get already existing one */
dbo = _meta_struct_get_db_object (mstruct, icatalog, ischema, iname);
if (!dbo) {
dbo = g_new0 (GdaMetaDbObject, 1);
dbo->obj_catalog = g_strdup (g_value_get_string (icatalog));
dbo->obj_schema = g_strdup (g_value_get_string (ischema));
- dbo->obj_name = g_strdup (g_value_get_string (name));
+ dbo->obj_name = g_strdup (g_value_get_string (iname));
if (short_name)
dbo->obj_short_name = g_strdup (g_value_get_string (short_name));
if (full_name)
@@ -411,12 +432,8 @@
if (owner)
dbo->obj_owner = g_strdup (g_value_get_string (owner));
}
- else if (dbo->obj_type == type) {
- if (icatalog) gda_value_free (icatalog);
- if (ischema) gda_value_free (ischema);
- gda_value_free (iname);
+ else if (dbo->obj_type == type)
return dbo; /* nothing to do */
- }
else if (dbo->obj_type != GDA_META_DB_UNKNOWN) {
/* DB Object already exists, return an error */
g_set_error (error, GDA_META_STRUCT_ERROR, GDA_META_STRUCT_DUPLICATE_OBJECT_ERROR,
@@ -458,7 +475,7 @@
if (!dbo->obj_owner)
dbo->obj_owner = g_strdup (g_value_get_string (gda_data_model_get_value_at (model, 4, 0)));
- mv = GDA_META_DB_OBJECT_GET_VIEW (dbo);
+ mv = GDA_META_VIEW (dbo);
mv->view_def = g_strdup (g_value_get_string (gda_data_model_get_value_at (model, 0, 0)));
mv->is_updatable = g_value_get_boolean (gda_data_model_get_value_at (model, 1, 0));
@@ -517,7 +534,7 @@
if (!dbo->obj_owner)
dbo->obj_owner = g_strdup (g_value_get_string (gda_data_model_get_value_at (model, 7, 0)));
- mt = GDA_META_DB_OBJECT_GET_TABLE (dbo);
+ mt = GDA_META_TABLE (dbo);
for (i = 0; i < nrows; i++) {
GdaMetaTableColumn *tcol;
const GValue *val;
@@ -616,6 +633,10 @@
g_value_get_string (fk_name));
g_hash_table_insert (mstruct->priv->index, str, tfk->depend_on);
}
+ else if (tfk->depend_on->obj_type == GDA_META_DB_TABLE) {
+ GdaMetaTable *dot = GDA_META_TABLE (tfk->depend_on);
+ dot->reverse_fk_list = g_slist_prepend (dot->reverse_fk_list, tfk);
+ }
dbo->depend_list = g_slist_append (dbo->depend_list, tfk->depend_on);
/* FIXME: compute @cols_nb, and all the @*_array members (ref_pk_cols_array must be
@@ -642,7 +663,8 @@
g_value_get_string (iname));
g_hash_table_insert (mstruct->priv->index, str, dbo);
}
- if (dbo && (mstruct->priv->features & GDA_META_STRUCT_FEATURE_FOREIGN_KEYS)) {
+ if (dbo && (dbo->obj_type == GDA_META_DB_TABLE) &&
+ (mstruct->priv->features & GDA_META_STRUCT_FEATURE_FOREIGN_KEYS)) {
/* compute GdaMetaTableForeignKey's @ref_pk_cols_array arrays and GdaMetaTable' @reverse_fk_list lists*/
GSList *list;
for (list = mstruct->db_objects; list; list = list->next) {
@@ -650,12 +672,17 @@
tmpdbo = GDA_META_DB_OBJECT (list->data);
if (tmpdbo->obj_type != GDA_META_DB_TABLE)
continue;
- GdaMetaTable *mt = GDA_META_DB_OBJECT_GET_TABLE (tmpdbo);
+
+ GdaMetaTable *mt = GDA_META_TABLE (tmpdbo);
GSList *klist;
for (klist = mt->fk_list; klist; klist = klist->next) {
GdaMetaTableForeignKey *tfk = GDA_META_TABLE_FOREIGN_KEY (klist->data);
- GdaMetaTable *ref_mt = GDA_META_DB_OBJECT_GET_TABLE (tfk->depend_on);
+ GdaMetaTable *ref_mt = GDA_META_TABLE (tfk->depend_on);
gint i;
+
+ if (tfk->depend_on != dbo)
+ continue;
+
for (i = 0; i < tfk->cols_nb; i++) {
gint col;
GdaMetaTableColumn *r_tcol;
@@ -680,27 +707,17 @@
}
tfk->ref_pk_cols_array[i] = col;
}
- ref_mt->reverse_fk_list = g_slist_append (ref_mt->reverse_fk_list, tmpdbo);
+
+ GDA_META_TABLE (dbo)->reverse_fk_list = g_slist_append (GDA_META_TABLE (dbo)->reverse_fk_list,
+ tfk);
}
}
}
- gda_value_free (icatalog);
- gda_value_free (ischema);
- gda_value_free (iname);
- if (short_name) gda_value_free (short_name);
- if (full_name) gda_value_free (full_name);
- if (owner) gda_value_free (owner);
return dbo;
onerror:
- gda_value_free (icatalog);
- gda_value_free (ischema);
- gda_value_free (iname);
if (dbo)
gda_meta_db_object_free (dbo);
- if (short_name) gda_value_free (short_name);
- if (full_name) gda_value_free (full_name);
- if (owner) gda_value_free (owner);
return NULL;
}
@@ -741,6 +758,237 @@
return str;
}
+
+/**
+ * gda_meta_struct_complement_schema
+ * @mstruct: a #GdaMetaStruct object
+ * @store: a #GdaMetaStore object
+ * @catalog: name of a catalog, or %NULL
+ * @schema: name of a schema, or %NULL
+ * @error: a place to store errors, or %NULL
+ *
+ * This method is similar to gda_meta_struct_complement() but creates #GdaMetaDbObject for all the
+ * database object which are in the @schema schema (and in the @catalog catalog).
+ * If @catalog is %NULL, then any catalog will be used, and
+ * if @schema is %NULL then any schema will be used (if @schema is %NULL then catalog must also be %NULL).
+ *
+ * Returns: TRUE if no error occurred
+ */
+gboolean
+gda_meta_struct_complement_schema (GdaMetaStruct *mstruct, GdaMetaStore *store, const GValue *catalog, const GValue *schema,
+ GError **error)
+{
+ GdaDataModel *tables_model = NULL, *views_model = NULL;
+ gint i, nrows;
+
+ /* schema and catalog are known */
+ const gchar *sql1 = "SELECT table_name "
+ "FROM _tables WHERE table_short_name, table_full_name, table_owner, table_catalog = ##cat::string AND table_schema = ##schema::string "
+ "AND table_type='BASE TABLE' "
+ "ORDER BY table_schema, table_name";
+ const gchar *sql2 = "SELECT table_short_name, table_full_name, table_owner, table_name "
+ "FROM _tables WHERE table_catalog = ##cat::string AND table_schema = ##schema::string "
+ "AND table_type='VIEW' "
+ "ORDER BY table_schema, table_name";
+
+ /* schema is known, catalog unknown */
+ const gchar *sql3 = "SELECT table_short_name, table_full_name, table_owner, table_name, table_catalog, table_schema "
+ "FROM _tables WHERE table_schema = ##schema::string AND table_type='BASE TABLE' "
+ "ORDER BY table_schema, table_name";
+ const gchar *sql4 = "SELECT table_short_name, table_full_name, table_owner, table_name, table_catalog, table_schema "
+ "FROM _tables WHERE table_schema = ##schema::string AND table_type='VIEW' "
+ "ORDER BY table_schema, table_name";
+
+ /* schema and catalog are unknown */
+ const gchar *sql5 = "SELECT table_short_name, table_full_name, table_owner, table_name, table_catalog, table_schema "
+ "FROM _tables WHERE table_type='BASE TABLE' "
+ "ORDER BY table_schema, table_name";
+ const gchar *sql6 = "SELECT table_short_name, table_full_name, table_owner, table_name, table_catalog, table_schema "
+ "FROM _tables WHERE table_type='VIEW' "
+ "ORDER BY table_schema, table_name";
+
+ g_return_val_if_fail (GDA_IS_META_STORE (store), FALSE);
+ g_return_val_if_fail (GDA_IS_META_STRUCT (mstruct), FALSE);
+ g_return_val_if_fail (!catalog || (catalog && schema), FALSE);
+ g_return_val_if_fail (!catalog || (G_VALUE_TYPE (catalog) == G_TYPE_STRING), FALSE);
+ g_return_val_if_fail (!schema || (G_VALUE_TYPE (schema) == G_TYPE_STRING), FALSE);
+
+ if (schema) {
+ if (catalog) {
+ tables_model = gda_meta_store_extract (store, sql1, error,
+ "cat", catalog, "schema", schema, NULL);
+ if (tables_model)
+ views_model = gda_meta_store_extract (store, sql2, error,
+ "cat", catalog, "schema", schema, NULL);
+ }
+ else {
+ tables_model = gda_meta_store_extract (store, sql3, error, "schema", schema, NULL);
+ if (tables_model)
+ views_model = gda_meta_store_extract (store, sql4, error, "schema", schema, NULL);
+ }
+ }
+ else {
+ tables_model = gda_meta_store_extract (store, sql5, error, NULL);
+ if (tables_model)
+ views_model = gda_meta_store_extract (store, sql6, error, NULL);
+ }
+
+ if (!tables_model || !views_model)
+ return FALSE;
+
+ /* tables */
+ nrows = gda_data_model_get_n_rows (tables_model);
+ for (i = 0; i < nrows; i++) {
+ if (!_meta_struct_complement (mstruct, store, GDA_META_DB_TABLE,
+ catalog ? catalog : gda_data_model_get_value_at (tables_model, 4, i),
+ schema ? schema : gda_data_model_get_value_at (tables_model, 5, i),
+ gda_data_model_get_value_at (tables_model, 3, i),
+ gda_data_model_get_value_at (tables_model, 0, i),
+ gda_data_model_get_value_at (tables_model, 1, i),
+ gda_data_model_get_value_at (tables_model, 2, i), error)) {
+ g_object_unref (tables_model);
+ g_object_unref (views_model);
+ return FALSE;
+ }
+ }
+ g_object_unref (tables_model);
+
+ /* tables */
+ nrows = gda_data_model_get_n_rows (views_model);
+ for (i = 0; i < nrows; i++) {
+ if (!_meta_struct_complement (mstruct, store, GDA_META_DB_VIEW,
+ catalog ? catalog : gda_data_model_get_value_at (views_model, 4, i),
+ schema ? schema : gda_data_model_get_value_at (views_model, 5, i),
+ gda_data_model_get_value_at (views_model, 3, i),
+ gda_data_model_get_value_at (views_model, 0, i),
+ gda_data_model_get_value_at (views_model, 1, i),
+ gda_data_model_get_value_at (views_model, 2, i), error)) {
+ g_object_unref (views_model);
+ return FALSE;
+ }
+ }
+ g_object_unref (views_model);
+
+ return TRUE;
+}
+
+/**
+ * gda_meta_struct_complement_default
+ * @mstruct: a #GdaMetaStruct object
+ * @store: a #GdaMetaStore object
+ * @error: a place to store errors, or %NULL
+ *
+ * This method is similar to gda_meta_struct_complement() but creates #GdaMetaDbObject for all the
+ * database object which are useable using only their short name (that is which do not need to be prefixed by
+ * the schema in which they are to be used).
+ *
+ * Returns: TRUE if no error occurred
+ */
+gboolean
+gda_meta_struct_complement_default (GdaMetaStruct *mstruct, GdaMetaStore *store, GError **error)
+{
+ GdaDataModel *model;
+ gint i, nrows;
+ const gchar *sql1 = "SELECT table_catalog, table_schema, table_name, table_short_name, table_full_name, table_owner "
+ "FROM _tables WHERE table_short_name = table_name AND table_type='BASE TABLE' "
+ "ORDER BY table_schema, table_name";
+ const gchar *sql2 = "SELECT table_catalog, table_schema, table_name, table_short_name, table_full_name, table_owner "
+ "FROM _tables WHERE table_short_name = table_name AND table_type='VIEW' "
+ "ORDER BY table_schema, table_name";
+
+ g_return_val_if_fail (GDA_IS_META_STORE (store), FALSE);
+ g_return_val_if_fail (GDA_IS_META_STRUCT (mstruct), FALSE);
+
+ /* tables */
+ model = gda_meta_store_extract (store, sql1, error, NULL);
+ if (!model)
+ return FALSE;
+ nrows = gda_data_model_get_n_rows (model);
+ for (i = 0; i < nrows; i++) {
+ if (!_meta_struct_complement (mstruct, store, GDA_META_DB_TABLE,
+ gda_data_model_get_value_at (model, 0, i),
+ gda_data_model_get_value_at (model, 1, i),
+ gda_data_model_get_value_at (model, 2, i),
+ gda_data_model_get_value_at (model, 3, i),
+ gda_data_model_get_value_at (model, 4, i),
+ gda_data_model_get_value_at (model, 5, i), error)) {
+ g_object_unref (model);
+ return FALSE;
+ }
+ }
+ g_object_unref (model);
+
+ /* views */
+ model = gda_meta_store_extract (store, sql2, error, NULL);
+ if (!model)
+ return FALSE;
+ nrows = gda_data_model_get_n_rows (model);
+ for (i = 0; i < nrows; i++) {
+ if (!_meta_struct_complement (mstruct, store, GDA_META_DB_VIEW,
+ gda_data_model_get_value_at (model, 0, i),
+ gda_data_model_get_value_at (model, 1, i),
+ gda_data_model_get_value_at (model, 2, i),
+ gda_data_model_get_value_at (model, 3, i),
+ gda_data_model_get_value_at (model, 4, i),
+ gda_data_model_get_value_at (model, 5, i), error)) {
+ g_object_unref (model);
+ return FALSE;
+ }
+ }
+ g_object_unref (model);
+ return TRUE;
+}
+
+/**
+ * gda_meta_struct_complement_depend
+ * @mstruct: a #GdaMetaStruct object
+ * @store: a #GdaMetaStore object
+ * @dbo: a #GdaMetaDbObject part of @mstruct
+ * @error: a place to store errors, or %NULL
+ *
+ * This method is similar to gda_meta_struct_complement() but creates #GdaMetaDbObject for all the dependencies
+ * of @dbo.
+ *
+ * Returns: TRUE if no error occurred
+ */
+gboolean
+gda_meta_struct_complement_depend (GdaMetaStruct *mstruct, GdaMetaStore *store, GdaMetaDbObject *dbo,
+ GError **error)
+{
+ GSList *list;
+
+ g_return_val_if_fail (GDA_IS_META_STORE (store), FALSE);
+ g_return_val_if_fail (GDA_IS_META_STRUCT (mstruct), FALSE);
+ g_return_val_if_fail (dbo, FALSE);
+ g_return_val_if_fail (g_slist_find (mstruct->db_objects, dbo), FALSE);
+
+ for (list = dbo->depend_list; list; list = list->next) {
+ GdaMetaDbObject *dep_dbo = GDA_META_DB_OBJECT (list->data);
+ if (dep_dbo->obj_type != GDA_META_DB_UNKNOWN)
+ continue;
+
+ GValue *cat = NULL, *schema = NULL, *name = NULL;
+ gboolean allok;
+ g_return_val_if_fail (dep_dbo->obj_name, FALSE);
+ if (dep_dbo->obj_catalog)
+ g_value_take_string ((cat = gda_value_new (G_TYPE_STRING)),
+ g_strdup_printf ("\"%s\"", dep_dbo->obj_catalog));
+ if (dep_dbo->obj_schema)
+ g_value_take_string ((schema = gda_value_new (G_TYPE_STRING)),
+ g_strdup_printf ("\"%s\"", dep_dbo->obj_schema));
+ g_value_take_string ((name = gda_value_new (G_TYPE_STRING)),
+ g_strdup_printf ("\"%s\"", dep_dbo->obj_name));
+ allok = gda_meta_struct_complement (mstruct, store, GDA_META_DB_UNKNOWN, cat, schema, name, error);
+ if (cat) gda_value_free (cat);
+ if (schema) gda_value_free (schema);
+ gda_value_free (name);
+ if (!allok)
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
/*
* Makes a list of all the GdaMetaDbObject structures listed in @objects
* which are not present in @ordered_list and for which no dependency is in @ordered_list
@@ -1023,7 +1271,7 @@
/* columns, only for tables */
if (dbo->obj_type == GDA_META_DB_TABLE) {
- GdaMetaTable *mt = GDA_META_DB_OBJECT_GET_TABLE (dbo);
+ GdaMetaTable *mt = GDA_META_TABLE (dbo);
GSList *depend_dbo_list = NULL;
if (info & GDA_META_GRAPH_COLUMNS) {
for (list = mt->columns; list; list = list->next) {
@@ -1064,7 +1312,7 @@
g_slist_free (depend_dbo_list);
}
else if (dbo->obj_type == GDA_META_DB_VIEW) {
- GdaMetaTable *mt = GDA_META_DB_OBJECT_GET_TABLE (dbo);
+ GdaMetaTable *mt = GDA_META_TABLE (dbo);
if (info & GDA_META_GRAPH_COLUMNS) {
for (list = mt->columns; list; list = list->next) {
GdaMetaTableColumn *tcol = GDA_META_TABLE_COLUMN (list->data);
@@ -1106,10 +1354,10 @@
case GDA_META_DB_UNKNOWN:
break;
case GDA_META_DB_TABLE:
- gda_meta_table_free_contents (GDA_META_DB_OBJECT_GET_TABLE (dbo));
+ gda_meta_table_free_contents (GDA_META_TABLE (dbo));
break;
case GDA_META_DB_VIEW:
- gda_meta_view_free_contents (GDA_META_DB_OBJECT_GET_VIEW (dbo));
+ gda_meta_view_free_contents (GDA_META_VIEW (dbo));
break;
default:
TO_IMPLEMENT;
Modified: trunk/libgda/gda-meta-struct.h
==============================================================================
--- trunk/libgda/gda-meta-struct.h (original)
+++ trunk/libgda/gda-meta-struct.h Sun Apr 27 18:52:38 2008
@@ -100,7 +100,7 @@
/* Foreign keys */
GSList *reverse_fk_list; /* list of GdaMetaTableForeignKey where @depend_on == this GdaMetaDbObject */
- GSList *fk_list; /* list of GdaMetaTableForeignKey where @gda_meta_table == this GdaMetaDbObject */
+ GSList *fk_list; /* list of GdaMetaTableForeignKey where @meta_table == this GdaMetaDbObject */
} GdaMetaTable;
/**
@@ -123,6 +123,10 @@
* before using in an SQL statement
*/
typedef struct {
+ union {
+ GdaMetaTable meta_table;
+ GdaMetaView meta_view;
+ } extra;
GdaMetaDbObjectType obj_type;
gchar *obj_catalog;
gchar *obj_schema;
@@ -131,16 +135,11 @@
gchar *obj_full_name;
gchar *obj_owner;
- union {
- GdaMetaTable meta_table;
- GdaMetaView meta_view;
- } extra;
-
GSList *depend_list; /* list of GdaMetaDbObject pointers on which this object depends */
} GdaMetaDbObject;
#define GDA_META_DB_OBJECT(x) ((GdaMetaDbObject*)(x))
-#define GDA_META_DB_OBJECT_GET_TABLE(dbobj) (&((dbobj)->extra.meta_table))
-#define GDA_META_DB_OBJECT_GET_VIEW(dbobj) (&((dbobj)->extra.meta_view))
+#define GDA_META_TABLE(dbobj) (&((dbobj)->extra.meta_table))
+#define GDA_META_VIEW(dbobj) (&((dbobj)->extra.meta_view))
typedef struct {
gchar *column_name;
@@ -165,22 +164,28 @@
#define GDA_META_TABLE_FOREIGN_KEY(x) ((GdaMetaTableForeignKey*)(x))
-GType gda_meta_struct_get_type (void) G_GNUC_CONST;
-GdaMetaStruct *gda_meta_struct_new (GdaMetaStructFeature features);
-GdaMetaDbObject *gda_meta_struct_complement (GdaMetaStruct *mstruct, GdaMetaStore *store, GdaMetaDbObjectType type,
- const GValue *catalog, const GValue *schema, const GValue *name,
- GError **error);
-gboolean gda_meta_struct_sort_db_objects (GdaMetaStruct *mstruct, GdaMetaSortType sort_type, GError **error);
-GdaMetaDbObject *gda_meta_struct_get_db_object (GdaMetaStruct *mstruct,
- const GValue *catalog, const GValue *schema, const GValue *name);
-GdaMetaTableColumn *gda_meta_struct_get_table_column (GdaMetaStruct *mstruct, GdaMetaTable *table,
- const GValue *col_name);
+GType gda_meta_struct_get_type (void) G_GNUC_CONST;
+GdaMetaStruct *gda_meta_struct_new (GdaMetaStructFeature features);
+GdaMetaDbObject *gda_meta_struct_complement (GdaMetaStruct *mstruct, GdaMetaStore *store, GdaMetaDbObjectType type,
+ const GValue *catalog, const GValue *schema, const GValue *name,
+ GError **error);
+gboolean gda_meta_struct_complement_schema (GdaMetaStruct *mstruct, GdaMetaStore *store,
+ const GValue *catalog, const GValue *schema, GError **error);
+gboolean gda_meta_struct_complement_default (GdaMetaStruct *mstruct, GdaMetaStore *store, GError **error);
+gboolean gda_meta_struct_complement_depend (GdaMetaStruct *mstruct, GdaMetaStore *store, GdaMetaDbObject *dbo,
+ GError **error);
+
+gboolean gda_meta_struct_sort_db_objects (GdaMetaStruct *mstruct, GdaMetaSortType sort_type, GError **error);
+GdaMetaDbObject *gda_meta_struct_get_db_object (GdaMetaStruct *mstruct,
+ const GValue *catalog, const GValue *schema, const GValue *name);
+GdaMetaTableColumn *gda_meta_struct_get_table_column (GdaMetaStruct *mstruct, GdaMetaTable *table,
+ const GValue *col_name);
typedef enum {
GDA_META_GRAPH_COLUMNS = 1 << 0
} GdaMetaGraphInfo;
-gchar *gda_meta_struct_dump_as_graph (GdaMetaStruct *mstruct, GdaMetaGraphInfo info, GError **error);
+gchar *gda_meta_struct_dump_as_graph (GdaMetaStruct *mstruct, GdaMetaGraphInfo info, GError **error);
G_END_DECLS
Modified: trunk/libgda/gda-set.c
==============================================================================
--- trunk/libgda/gda-set.c (original)
+++ trunk/libgda/gda-set.c Sun Apr 27 18:52:38 2008
@@ -843,7 +843,7 @@
/* holders' values, sources, constraints: TODO */
- xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
+ xmlDocDumpFormatMemory (doc, &xmlbuff, &buffersize, 1);
xmlFreeDoc(doc);
return (gchar *) xmlbuff;
Modified: trunk/libgda/gda-set.h
==============================================================================
--- trunk/libgda/gda-set.h (original)
+++ trunk/libgda/gda-set.h Sun Apr 27 18:52:38 2008
@@ -153,7 +153,6 @@
GdaSetSource *gda_set_get_source (GdaSet *set, GdaHolder *param);
GdaSetGroup *gda_set_get_group (GdaSet *set, GdaHolder *param);
-
G_END_DECLS
#endif
Modified: trunk/libgda/gda-util.c
==============================================================================
--- trunk/libgda/gda-util.c (original)
+++ trunk/libgda/gda-util.c Sun Apr 27 18:52:38 2008
@@ -789,7 +789,7 @@
ust->table = gda_sql_table_new (GDA_SQL_ANY_PART (ust));
ust->table->table_name = g_strdup ((gchar *) target->table_name);
ust->cond = dml_statements_build_condition (stsel,
- GDA_META_DB_OBJECT_GET_TABLE (target->validity_meta_object),
+ GDA_META_TABLE (target->validity_meta_object),
require_pk, error);
if (!ust->cond) {
retval = FALSE;
@@ -804,7 +804,7 @@
dst->table = gda_sql_table_new (GDA_SQL_ANY_PART (dst));
dst->table->table_name = g_strdup ((gchar *) target->table_name);
dst->cond = dml_statements_build_condition (stsel,
- GDA_META_DB_OBJECT_GET_TABLE (target->validity_meta_object),
+ GDA_META_TABLE (target->validity_meta_object),
require_pk, error);
if (!dst->cond) {
retval = FALSE;
@@ -1236,10 +1236,16 @@
compl_finished:
g_free (text);
if (compl) {
- gchar **ptr;
- ptr = (gchar**) compl->data;
- g_array_free (compl, FALSE);
- return ptr;
+ if (compl->len >= 1) {
+ gchar **ptr;
+ ptr = (gchar**) compl->data;
+ g_array_free (compl, FALSE);
+ return ptr;
+ }
+ else {
+ g_array_free (compl, TRUE);
+ return NULL;
+ }
}
else
return NULL;
Modified: trunk/libgda/sql-parser/gda-statement-struct-select.c
==============================================================================
--- trunk/libgda/sql-parser/gda-statement-struct-select.c (original)
+++ trunk/libgda/sql-parser/gda-statement-struct-select.c Sun Apr 27 18:52:38 2008
@@ -342,7 +342,6 @@
gda_sql_statement_select_check_validity (GdaSqlAnyPart *stmt, gpointer data, GError **error)
{
GdaSqlStatementSelect *select = (GdaSqlStatementSelect *) stmt;
- GdaSqlStatementCheckValidityData *ddata = (GdaSqlStatementCheckValidityData*) data;
gboolean retval = TRUE;
/* validate target's names and aliases:
Modified: trunk/libgda/sql-parser/gda-statement-struct.c
==============================================================================
--- trunk/libgda/sql-parser/gda-statement-struct.c (original)
+++ trunk/libgda/sql-parser/gda-statement-struct.c Sun Apr 27 18:52:38 2008
@@ -487,7 +487,7 @@
memset (&value, 0, sizeof (GValue));
g_value_set_string (g_value_init (&value, G_TYPE_STRING), field->field_name);
tcol = gda_meta_struct_get_table_column (data->mstruct,
- GDA_META_DB_OBJECT_GET_TABLE (stable->validity_meta_object),
+ GDA_META_TABLE (stable->validity_meta_object),
&value);
g_value_unset (&value);
field->validity_meta_table_column = tcol;
@@ -667,7 +667,7 @@
g_value_set_string (g_value_init (&value, G_TYPE_STRING), field->field_name);
tcol = gda_meta_struct_get_table_column (data->mstruct,
- GDA_META_DB_OBJECT_GET_TABLE (target->validity_meta_object),
+ GDA_META_TABLE (target->validity_meta_object),
&value);
g_value_unset (&value);
if (tcol) {
@@ -712,7 +712,7 @@
GdaMetaTableColumn *tcol;
g_value_set_string (g_value_init (&value, G_TYPE_STRING), field->field_name);
tcol = gda_meta_struct_get_table_column (data->mstruct,
- GDA_META_DB_OBJECT_GET_TABLE (field->validity_meta_object),
+ GDA_META_TABLE (field->validity_meta_object),
&value);
g_value_unset (&value);
field->validity_meta_table_column = tcol;
@@ -1306,7 +1306,7 @@
gda_identifier_equal (g_value_get_string (field->expr->value), "*"))) &&
field->validity_meta_object) {
/* expand * to all the fields */
- GdaMetaTable *mtable = GDA_META_DB_OBJECT_GET_TABLE (field->validity_meta_object);
+ GdaMetaTable *mtable = GDA_META_TABLE (field->validity_meta_object);
GSList *list;
GdaSqlAnyPart *parent_node = ((GdaSqlAnyPart*) field)->parent;
gint nodepos = g_slist_index (((GdaSqlStatementSelect*) parent_node)->expr_list, node);
Modified: trunk/libgda/sqlite/gda-sqlite-meta.c
==============================================================================
--- trunk/libgda/sqlite/gda-sqlite-meta.c (original)
+++ trunk/libgda/sqlite/gda-sqlite-meta.c Sun Apr 27 18:52:38 2008
@@ -460,20 +460,18 @@
if (*(g_value_get_string (tvalue)) == 'v')
is_view = TRUE;
g_value_set_boolean ((v1 = gda_value_new (G_TYPE_BOOLEAN)), TRUE);
- if (strcmp (schema_name, "main")) {
- str = g_strdup_printf ("%s.%s", schema_name, g_value_get_string (cvalue));
- g_value_take_string ((v2 = gda_value_new (G_TYPE_STRING)), str);
- }
+ str = g_strdup_printf ("%s.%s", schema_name, g_value_get_string (cvalue));
+ g_value_take_string ((v2 = gda_value_new (G_TYPE_STRING)), str);
if (! append_a_row (to_tables_model, error, 9,
- FALSE, catalog_value,
- FALSE, p_table_schema,
- FALSE, cvalue,
- FALSE, is_view ? view_type_value : table_type_value,
- TRUE, v1,
- FALSE, NULL,
- FALSE, cvalue,
- v2 ? TRUE : FALSE, v2 ? v2 : cvalue,
- FALSE, NULL))
+ FALSE, catalog_value, /* table_catalog */
+ FALSE, p_table_schema, /* table_schema */
+ FALSE, cvalue, /* table_name */
+ FALSE, is_view ? view_type_value : table_type_value, /* table_type */
+ TRUE, v1, /* is_insertable_into */
+ FALSE, NULL, /* table_comments */
+ FALSE, cvalue, /* table_short_name */
+ TRUE, v2, /* table_full_name */
+ FALSE, NULL)) /* table_owner */
retval = FALSE;
if (is_view && ! append_a_row (to_views_model, error, 6,
FALSE, catalog_value,
Modified: trunk/libgda/sqlite/gda-sqlite-provider.c
==============================================================================
--- trunk/libgda/sqlite/gda-sqlite-provider.c (original)
+++ trunk/libgda/sqlite/gda-sqlite-provider.c Sun Apr 27 18:52:38 2008
@@ -1202,7 +1202,10 @@
/*
* GdaStatement to SQL request
*/
-static gchar * sqlite_render_statement (GdaSqlOperation *op, GdaSqlRenderingContext *context, GError **error);
+static gchar *sqlite_render_operation (GdaSqlOperation *op, GdaSqlRenderingContext *context, GError **error);
+static gchar *sqlite_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
+ gboolean *is_default, gboolean *is_null,
+ GError **error);
static gchar *
gda_sqlite_provider_statement_to_sql (GdaServerProvider *provider, GdaConnection *cnc,
GdaStatement *stmt, GdaSet *params, GdaStatementSqlFlag flags,
@@ -1220,9 +1223,8 @@
memset (&context, 0, sizeof (context));
context.params = params;
context.flags = flags;
- context.render_operation = (GdaSqlRenderingFunc) sqlite_render_statement; /* only this part of the context is
- * modified for SQLite, other rendering
- * is the default */
+ context.render_operation = (GdaSqlRenderingFunc) sqlite_render_operation; /* specific REGEXP rendering */
+ context.render_expr = sqlite_render_expr; /* render "FALSE" as 0 and TRUE as !0 */
str = gda_statement_to_sql_real (stmt, &context, error);
@@ -1241,7 +1243,7 @@
}
static gchar *
-sqlite_render_statement (GdaSqlOperation *op, GdaSqlRenderingContext *context, GError **error)
+sqlite_render_operation (GdaSqlOperation *op, GdaSqlRenderingContext *context, GError **error)
{
gchar *str;
GSList *list;
@@ -1439,6 +1441,94 @@
return str;
}
+static gchar *
+sqlite_render_expr (GdaSqlExpr *expr, GdaSqlRenderingContext *context,
+ gboolean *is_default, gboolean *is_null,
+ GError **error)
+{
+ GString *string;
+ gchar *str = NULL;
+
+ g_return_val_if_fail (expr, NULL);
+ g_return_val_if_fail (GDA_SQL_ANY_PART (expr)->type == GDA_SQL_ANY_EXPR, NULL);
+
+ if (is_default)
+ *is_default = FALSE;
+ if (is_null)
+ *is_null = FALSE;
+
+ /* can't have:
+ * - expr->cast_as && expr->param_spec
+ */
+ if (!gda_sql_any_part_check_structure (GDA_SQL_ANY_PART (expr), error)) return NULL;
+
+ string = g_string_new ("");
+ if (expr->param_spec) {
+ str = context->render_param_spec (expr->param_spec, expr, context, is_default, is_null, error);
+ if (!str) goto err;
+ }
+ else if (expr->value) {
+ str = gda_value_stringify (expr->value);
+ if (!str) goto err;
+ if (is_null && gda_value_is_null (expr->value))
+ *is_null = TRUE;
+ else if (is_default && (G_VALUE_TYPE (expr->value) == G_TYPE_STRING) &&
+ !g_ascii_strcasecmp (g_value_get_string (expr->value), "default"))
+ *is_default = TRUE;
+ else if (!g_ascii_strcasecmp (str, "FALSE")) {
+ g_free (str);
+ str = g_strdup ("0");
+ }
+ else if (!g_ascii_strcasecmp (str, "TRUE")) {
+ g_free (str);
+ str = g_strdup ("1");
+ }
+ }
+ else if (expr->func) {
+ str = context->render_function (GDA_SQL_ANY_PART (expr->func), context, error);
+ if (!str) goto err;
+ }
+ else if (expr->cond) {
+ str = context->render_operation (GDA_SQL_ANY_PART (expr->cond), context, error);
+ if (!str) goto err;
+ }
+ else if (expr->select) {
+ gchar *str1;
+ str1 = context->render_select (GDA_SQL_ANY_PART (expr->select), context, error);
+ if (!str1) goto err;
+ str = g_strdup_printf ("(%s)", str1);
+ g_free (str1);
+ }
+ else if (expr->case_s) {
+ str = context->render_case (GDA_SQL_ANY_PART (expr->case_s), context, error);
+ if (!str) goto err;
+ }
+ else {
+ if (is_null)
+ *is_null = TRUE;
+ str = g_strdup ("NULL");
+ }
+
+ if (!str) {
+ /* TO REMOVE */
+ str = g_strdup ("[...]");
+ }
+
+ if (expr->cast_as)
+ g_string_append_printf (string, "CAST (%s AS %s)", str, expr->cast_as);
+ else
+ g_string_append (string, str);
+ g_free (str);
+
+ str = string->str;
+ g_string_free (string, FALSE);
+ return str;
+
+ err:
+ g_string_free (string, TRUE);
+ return NULL;
+}
+
/*
* Statement prepare request
*/
Modified: trunk/tests/value-holders/check_holder.c
==============================================================================
--- trunk/tests/value-holders/check_holder.c (original)
+++ trunk/tests/value-holders/check_holder.c Sun Apr 27 18:52:38 2008
@@ -589,8 +589,8 @@
const GValue *cvalue;
GValue *value;
- h1 = gda_holder_new_string ("Slave", "Master string");
- h2 = gda_holder_new_string ("Master", "Slave string");
+ h1 = gda_holder_new_string ("Slave", "Slave string");
+ h2 = gda_holder_new_string ("Master", "Master string");
emitted_signals_monitor_holder (h1);
emitted_signals_monitor_holder (h2);
emitted_signals_reset ();
Modified: trunk/tools/command-exec.c
==============================================================================
--- trunk/tools/command-exec.c (original)
+++ trunk/tools/command-exec.c Sun Apr 27 18:52:38 2008
@@ -612,26 +612,8 @@
if (!args[0]) {
/* use all tables or views */
- GdaDataModel *model;
- gint i, nrows;
- const gchar *sql = "SELECT t.table_catalog, t.table_schema, t.table_name, v.table_name FROM _tables as t LEFT JOIN _views as v ON (t.table_catalog=v.table_catalog AND t.table_schema=v.table_schema AND t.table_name=v.table_name) WHERE table_short_name != table_full_name";
- model = gda_meta_store_extract (store, sql, error, NULL);
- if (!model)
- return NULL;
- nrows = gda_data_model_get_n_rows (model);
- for (i = 0; i < nrows; i++) {
- const GValue *detv;
- detv = gda_data_model_get_value_at (model, 3, i);
- if (! gda_meta_struct_complement (mstruct, store,
- detv && !gda_value_is_null (detv) &&
- g_value_get_string (detv) && *g_value_get_string (detv) ?
- GDA_META_DB_VIEW : GDA_META_DB_TABLE,
- gda_data_model_get_value_at (model, 0, i),
- gda_data_model_get_value_at (model, 1, i),
- gda_data_model_get_value_at (model, 2, i), error))
- goto onerror;
- }
- g_object_unref (model);
+ if (!gda_meta_struct_complement_default (mstruct, store, error))
+ goto onerror;
}
for (index = 0, arg = args[0]; arg; index++, arg = args[index]) {
@@ -641,30 +623,13 @@
/* see if we have the form <schema_name>.*, to list all the objects in a given schema */
if (g_str_has_suffix (arg, ".*") && (*arg != '.')) {
gchar *str;
- GdaDataModel *model;
- gint i, nrows;
str = g_strdup (arg);
str[strlen (str) - 2] = 0;
g_value_take_string (v, str);
- const gchar *sql = "SELECT t.table_catalog, t.table_schema, t.table_name, v.table_name FROM _tables as t LEFT JOIN _views as v ON (t.table_catalog=v.table_catalog AND t.table_schema=v.table_schema AND t.table_name=v.table_name) WHERE t.table_schema = ##ts::string";
- model = gda_meta_store_extract (store, sql, error, "ts", v, NULL);
- if (!model)
- return NULL;
- nrows = gda_data_model_get_n_rows (model);
- for (i = 0; i < nrows; i++) {
- const GValue *detv;
- detv = gda_data_model_get_value_at (model, 3, i);
- if (! gda_meta_struct_complement (mstruct, store,
- detv && !gda_value_is_null (detv) &&
- g_value_get_string (detv) && *g_value_get_string (detv) ?
- GDA_META_DB_VIEW : GDA_META_DB_TABLE,
- gda_data_model_get_value_at (model, 0, i),
- gda_data_model_get_value_at (model, 1, i),
- gda_data_model_get_value_at (model, 2, i), error))
- goto onerror;
- }
- g_object_unref (model);
+
+ if (!gda_meta_struct_complement_schema (mstruct, store, NULL, v, error))
+ goto onerror;
}
else {
/* try to find it as a table or view */
@@ -675,32 +640,10 @@
str = g_strdup (arg);
str[strlen (str) - 1] = 0;
g_value_take_string (v, str);
- dbo = gda_meta_struct_complement (mstruct, store, GDA_META_DB_TABLE,
+ dbo = gda_meta_struct_complement (mstruct, store, GDA_META_DB_UNKNOWN,
NULL, NULL, v, NULL);
- if (!dbo)
- dbo = gda_meta_struct_complement (mstruct, store, GDA_META_DB_VIEW,
- NULL, NULL, v, NULL);
- if (dbo && dbo->depend_list) {
- GSList *list, *dep_list;
- GValue *catalog, *schema, *name;
-
- dep_list = g_slist_copy (dbo->depend_list);
- for (list = dep_list; list; list = list->next) {
- dbo = GDA_META_DB_OBJECT (list->data);
- g_value_set_string ((catalog = gda_value_new (G_TYPE_STRING)),
- dbo->obj_catalog);
- g_value_set_string ((schema = gda_value_new (G_TYPE_STRING)),
- dbo->obj_schema);
- g_value_set_string ((name = gda_value_new (G_TYPE_STRING)),
- dbo->obj_name);
- gda_meta_struct_complement (mstruct, store, dbo->obj_type,
- catalog, schema, name, NULL);
- gda_value_free (catalog);
- gda_value_free (schema);
- gda_value_free (name);
- }
- g_slist_free (dep_list);
- }
+ if (dbo)
+ gda_meta_struct_complement_depend (mstruct, store, dbo, NULL);
}
}
}
@@ -829,7 +772,7 @@
if ((dbo->obj_type == GDA_META_DB_VIEW) || (dbo->obj_type == GDA_META_DB_TABLE)) {
GdaInternalCommandResult *subres;
- GdaMetaTable *mt = GDA_META_DB_OBJECT_GET_TABLE (dbo);
+ GdaMetaTable *mt = GDA_META_TABLE (dbo);
GSList *list;
model = gda_data_model_array_new (4);
@@ -870,7 +813,7 @@
if (dbo->obj_type == GDA_META_DB_VIEW) {
/* VIEW specific */
- GdaMetaView *mv = GDA_META_DB_OBJECT_GET_VIEW (dbo);
+ GdaMetaView *mv = GDA_META_VIEW (dbo);
subres = g_new0 (GdaInternalCommandResult, 1);
subres->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
Modified: trunk/tools/gda-sql.c
==============================================================================
--- trunk/tools/gda-sql.c (original)
+++ trunk/tools/gda-sql.c Sun Apr 27 18:52:38 2008
@@ -933,7 +933,6 @@
data->settings = g_slist_append (data->settings, cs);
data->current = cs;
- /* set the GdaDict object's attributes */
GdaMetaStore *store;
gboolean update_store = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]