[libgda] provider-meta: updated API for tables and views
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] provider-meta: updated API for tables and views
- Date: Fri, 12 Oct 2018 23:53:09 +0000 (UTC)
commit 4960245e4f50d8cfe57a95f9c3f5ff714dc3dd07
Author: Daniel Espinosa <esodan gmail com>
Date: Fri Oct 12 18:52:23 2018 -0500
provider-meta: updated API for tables and views
libgda/gda-init.c | 5 ++
libgda/gda-provider-meta.c | 98 ++++++++++++++++++++++++-------
libgda/gda-provider-meta.h | 33 +++++++----
libgda/gda-quark-list.c | 12 ++--
libgda/sqlite/gda-sqlite-provider.c | 96 ++++++++++++++++++++++++------
tests/meson.build | 4 +-
tests/test-provider-meta.c | 114 ++++++++++++++++++++----------------
7 files changed, 253 insertions(+), 109 deletions(-)
---
diff --git a/libgda/gda-init.c b/libgda/gda-init.c
index 315cde548..75053ab8c 100644
--- a/libgda/gda-init.c
+++ b/libgda/gda-init.c
@@ -273,6 +273,11 @@ gda_init (void)
g_free (file);
+ /* Initializing global GdaConfig */
+ GdaConfig *config = gda_config_get ();
+ g_assert (config != NULL);
+ g_object_unref (config);
+
initialized = TRUE;
g_mutex_unlock (&init_mutex);
}
diff --git a/libgda/gda-provider-meta.c b/libgda/gda-provider-meta.c
index a8126b50f..943ac4bc9 100644
--- a/libgda/gda-provider-meta.c
+++ b/libgda/gda-provider-meta.c
@@ -14,7 +14,6 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA 02110-1301, USA.
*/
#include <libgda/gda-provider-meta.h>
#include <libgda/gda-connection.h>
@@ -543,31 +542,31 @@ gda_provider_meta_schemata (GdaProviderMeta *prov,
/* _tables or _views */
/**
- * gda_provider_meta_tables_views:
+ * gda_provider_meta_tables:
*
* Returns: (transfer full):
* Since: 6.0
* Stability: Unstable
*/
GdaDataModel*
-gda_provider_meta_tables_views (GdaProviderMeta *prov, GError **error)
+gda_provider_meta_tables (GdaProviderMeta *prov, GError **error)
{
g_return_val_if_fail (prov, NULL);
GdaProviderMetaInterface *iface = GDA_PROVIDER_META_GET_IFACE (prov);
- if (iface->tables_views) {
- return iface->tables_views (prov, error);
+ if (iface->tables) {
+ return iface->tables (prov, error);
}
return NULL;
}
/**
- * gda_provider_meta_table_view:
+ * gda_provider_meta_table:
*
* Returns: (transfer full):
* Since: 6.0
* Stability: Unstable
*/
GdaRow*
-gda_provider_meta_table_view (GdaProviderMeta *prov,
+gda_provider_meta_table (GdaProviderMeta *prov,
const gchar *table_catalog,
const gchar *table_schema,
const gchar *table_name_n,
@@ -575,12 +574,51 @@ gda_provider_meta_table_view (GdaProviderMeta *prov,
{
g_return_val_if_fail (prov, NULL);
GdaProviderMetaInterface *iface = GDA_PROVIDER_META_GET_IFACE (prov);
- if (iface->table_view) {
- return iface->table_view (prov, table_catalog,
+ if (iface->table) {
+ return iface->table (prov, table_catalog,
table_schema, table_name_n, error);
}
return NULL;
}
+/**
+ * gda_provider_meta_views:
+ *
+ * Returns: (transfer full):
+ * Since: 6.0
+ * Stability: Unstable
+ */
+GdaDataModel*
+gda_provider_meta_views (GdaProviderMeta *prov, GError **error)
+{
+ g_return_val_if_fail (prov, NULL);
+ GdaProviderMetaInterface *iface = GDA_PROVIDER_META_GET_IFACE (prov);
+ if (iface->views) {
+ return iface->views (prov, error);
+ }
+ return NULL;
+}
+/**
+ * gda_provider_meta_view:
+ *
+ * Returns: (transfer full):
+ * Since: 6.0
+ * Stability: Unstable
+ */
+GdaRow*
+gda_provider_meta_view (GdaProviderMeta *prov,
+ const gchar *view_catalog,
+ const gchar *view_schema,
+ const gchar *view_name_n,
+ GError **error)
+{
+ g_return_val_if_fail (prov, NULL);
+ GdaProviderMetaInterface *iface = GDA_PROVIDER_META_GET_IFACE (prov);
+ if (iface->view) {
+ return iface->view (prov, view_catalog,
+ view_schema, view_name_n, error);
+ }
+ return NULL;
+}
/* _columns */
/**
@@ -601,6 +639,24 @@ gda_provider_meta_columns (GdaProviderMeta *prov, GError **error)
return NULL;
}
+/* _tables_column_usage */
+/**
+ * gda_provider_meta_tables_columns:
+ *
+ * Returns: (transfer full):
+ * Since: 6.0
+ * Stability: Unstable
+ */
+GdaDataModel*
+gda_provider_meta_tables_columns (GdaProviderMeta *prov, GError **error)
+{
+ g_return_val_if_fail (prov, NULL);
+ GdaProviderMetaInterface *iface = GDA_PROVIDER_META_GET_IFACE (prov);
+ if (iface->views_columns) {
+ return iface->views_columns (prov, error);
+ }
+ return NULL;
+}
/**
* gda_provider_meta_table_columns:
*
@@ -650,31 +706,31 @@ gda_provider_meta_table_column (GdaProviderMeta *prov,
/* _view_column_usage */
/**
- * gda_provider_meta_views_cols:
+ * gda_provider_meta_views_columns:
*
* Returns: (transfer full):
* Since: 6.0
* Stability: Unstable
*/
GdaDataModel*
-gda_provider_meta_views_cols (GdaProviderMeta *prov, GError **error)
+gda_provider_meta_views_columns (GdaProviderMeta *prov, GError **error)
{
g_return_val_if_fail (prov, NULL);
GdaProviderMetaInterface *iface = GDA_PROVIDER_META_GET_IFACE (prov);
- if (iface->views_cols) {
- return iface->views_cols (prov, error);
+ if (iface->views_columns) {
+ return iface->views_columns (prov, error);
}
return NULL;
}
/**
- * gda_provider_meta_view_cols:
+ * gda_provider_meta_view_colums:
*
* Returns: (transfer full):
* Since: 6.0
* Stability: Unstable
*/
GdaDataModel*
-gda_provider_meta_view_cols (GdaProviderMeta *prov,
+gda_provider_meta_view_columns (GdaProviderMeta *prov,
const gchar *view_catalog,
const gchar *view_schema,
const gchar *view_name,
@@ -682,21 +738,21 @@ gda_provider_meta_view_cols (GdaProviderMeta *prov,
{
g_return_val_if_fail (prov, NULL);
GdaProviderMetaInterface *iface = GDA_PROVIDER_META_GET_IFACE (prov);
- if (iface->view_cols) {
- return iface->view_cols (prov, view_catalog,
+ if (iface->view_columns) {
+ return iface->view_columns (prov, view_catalog,
view_schema, view_name, error);
}
return NULL;
}
/**
- * gda_provider_meta_view_col:
+ * gda_provider_meta_view_column:
*
* Returns: (transfer full):
* Since: 6.0
* Stability: Unstable
*/
GdaRow*
-gda_provider_meta_view_col (GdaProviderMeta *prov,
+gda_provider_meta_view_column (GdaProviderMeta *prov,
const gchar *view_catalog,
const gchar *view_schema,
const gchar *view_name,
@@ -705,8 +761,8 @@ gda_provider_meta_view_col (GdaProviderMeta *prov,
{
g_return_val_if_fail (prov, NULL);
GdaProviderMetaInterface *iface = GDA_PROVIDER_META_GET_IFACE (prov);
- if (iface->view_col) {
- return iface->view_col (prov, view_catalog,
+ if (iface->view_column) {
+ return iface->view_column (prov, view_catalog,
view_schema, view_name, column_name, error);
}
return NULL;
diff --git a/libgda/gda-provider-meta.h b/libgda/gda-provider-meta.h
index d19337177..099f45a78 100644
--- a/libgda/gda-provider-meta.h
+++ b/libgda/gda-provider-meta.h
@@ -115,11 +115,17 @@ struct _GdaProviderMetaInterface
GError **error);
/* _tables or _views */
- GdaDataModel *(*tables_views) (GdaProviderMeta *prov, GError **error);
- GdaRow *(*table_view) (GdaProviderMeta *prov,
+ GdaDataModel *(*tables_columns) (GdaProviderMeta *prov, GError **error);
+ GdaDataModel *(*tables) (GdaProviderMeta *prov, GError **error);
+ GdaRow *(*table) (GdaProviderMeta *prov,
const gchar *table_catalog,
const gchar *table_schema,
const gchar *table_name_n, GError **error);
+ GdaDataModel *(*views) (GdaProviderMeta *prov, GError **error);
+ GdaRow *(*view) (GdaProviderMeta *prov,
+ const gchar *view_catalog,
+ const gchar *view_schema,
+ const gchar *view_name_n, GError **error);
/* _columns */
GdaDataModel *(*columns) (GdaProviderMeta *prov, GError **error);
@@ -136,12 +142,12 @@ struct _GdaProviderMetaInterface
GError **error);
/* _view_column_usage */
- GdaDataModel *(*views_cols) (GdaProviderMeta *prov, GError **error);
- GdaDataModel *(*view_cols) (GdaProviderMeta *prov,
+ GdaDataModel *(*views_columns) (GdaProviderMeta *prov, GError **error);
+ GdaDataModel *(*view_columns) (GdaProviderMeta *prov,
const gchar *view_catalog,
const gchar *view_schema,
const gchar *view_name, GError **error);
- GdaRow *(*view_col) (GdaProviderMeta *prov,
+ GdaRow *(*view_column) (GdaProviderMeta *prov,
const gchar *view_catalog,
const gchar *view_schema,
const gchar *view_name,
@@ -320,15 +326,22 @@ GdaRow *gda_provider_meta_schemata (GdaProviderMeta *prov,
const gchar *catalog_name, const gchar *schema_name_n, GError **error);
/* _tables or _views */
-GdaDataModel *gda_provider_meta_tables_views (GdaProviderMeta *prov,
+GdaDataModel *gda_provider_meta_tables (GdaProviderMeta *prov,
GError **error);
-GdaRow *gda_provider_meta_table_view (GdaProviderMeta *prov,
+GdaRow *gda_provider_meta_table (GdaProviderMeta *prov,
const gchar *table_catalog, const gchar *table_schema,
const gchar *table_name_n, GError **error);
+GdaDataModel *gda_provider_meta_views (GdaProviderMeta *prov,
+ GError **error);
+GdaRow *gda_provider_meta_view (GdaProviderMeta *prov,
+ const gchar *view_catalog, const gchar *view_schema,
+ const gchar *view_name_n, GError **error);
/* _columns */
GdaDataModel *gda_provider_meta_columns (GdaProviderMeta *prov,
GError **error);
+GdaDataModel *gda_provider_meta_tables_columns (GdaProviderMeta *prov,
+ GError **error);
GdaDataModel *gda_provider_meta_table_columns (GdaProviderMeta *prov,
const gchar *table_catalog, const gchar *table_schema,
const gchar *table_name, GError **error);
@@ -338,12 +351,12 @@ GdaRow *gda_provider_meta_table_column (GdaProviderMeta *prov,
const gchar *column_name, GError **error);
/* _view_column_usage */
-GdaDataModel *gda_provider_meta_views_cols (GdaProviderMeta *prov,
+GdaDataModel *gda_provider_meta_views_columns (GdaProviderMeta *prov,
GError **error);
-GdaDataModel *gda_provider_meta_view_cols (GdaProviderMeta *prov,
+GdaDataModel *gda_provider_meta_view_columns (GdaProviderMeta *prov,
const gchar *view_catalog, const gchar *view_schema,
const gchar *view_name, GError **error);
-GdaRow *gda_provider_meta_view_col (GdaProviderMeta *prov,
+GdaRow *gda_provider_meta_view_column (GdaProviderMeta *prov,
const gchar *view_catalog, const gchar *view_schema,
const gchar *view_name,
const gchar *column_name,
diff --git a/libgda/gda-quark-list.c b/libgda/gda-quark-list.c
index bb2ebbf28..1a57f68b1 100644
--- a/libgda/gda-quark-list.c
+++ b/libgda/gda-quark-list.c
@@ -368,17 +368,17 @@ name_is_protected (const gchar *name)
void
gda_quark_list_add_from_string (GdaQuarkList *qlist, const gchar *string, gboolean cleanup)
{
- gchar **arr;
-
g_return_if_fail (qlist != NULL);
- if (!string || !*string)
- return;
+ g_return_if_fail (string != NULL);
+ g_return_if_fail (g_strrstr (string, ";") != NULL);
+
+ gchar **arr;
if (cleanup)
gda_quark_list_clear (qlist);
- arr = (gchar **) g_strsplit (string, ";", 0);
- if (arr) {
+ arr = g_strsplit (string, ";", -1);
+ if (arr != NULL) {
guint n;
for (n = 0; arr[n] && (* (arr[n])); n++) {
gchar **pair;
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 3dcc5a931..29fa4a9e2 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -443,12 +443,17 @@ static GdaDataModel *gda_sqlite_provider_meta_schematas (GdaProvider
GError **error);
static GdaRow *gda_sqlite_provider_meta_schemata (GdaProviderMeta *prov,
const gchar *catalog_name, const gchar *schema_name_n, GError **error);
-static GdaDataModel *gda_sqlite_provider_meta_tables_views (GdaProviderMeta *prov,
+static GdaDataModel *gda_sqlite_provider_meta_tables (GdaProviderMeta *prov,
GError **error);
-static GdaRow *gda_sqlite_provider_meta_table_view (GdaProviderMeta *prov,
+static GdaRow *gda_sqlite_provider_meta_table (GdaProviderMeta *prov,
const gchar *table_catalog, const gchar *table_schema,
const gchar *table_name_n, GError **error);
-static GdaDataModel *gda_sqlite_provider_meta_columns (GdaProviderMeta *prov,
+static GdaDataModel *gda_sqlite_provider_meta_views (GdaProviderMeta *prov,
+ GError **error);
+static GdaRow *gda_sqlite_provider_meta_view (GdaProviderMeta *prov,
+ const gchar *table_catalog, const gchar *table_schema,
+ const gchar *table_name_n, GError **error);
+static GdaDataModel *gda_sqlite_provider_meta_tables_columns (GdaProviderMeta *prov,
GError **error);
static GdaDataModel *gda_sqlite_provider_meta_table_columns (GdaProviderMeta *prov,
const gchar *table_catalog, const gchar *table_schema,
@@ -457,12 +462,12 @@ static GdaRow *gda_sqlite_provider_meta_table_column (GdaProvider
const gchar *table_catalog, const gchar *table_schema,
const gchar *table_name,
const gchar *column_name, GError **error);
-static GdaDataModel *gda_sqlite_provider_meta_views_cols (GdaProviderMeta *prov,
+static GdaDataModel *gda_sqlite_provider_meta_views_columns (GdaProviderMeta *prov,
GError **error);
-static GdaDataModel *gda_sqlite_provider_meta_view_cols (GdaProviderMeta *prov,
+static GdaDataModel *gda_sqlite_provider_meta_view_columns (GdaProviderMeta *prov,
const gchar *view_catalog, const gchar *view_schema,
const gchar *view_name, GError **error);
-static GdaRow *gda_sqlite_provider_meta_view_col (GdaProviderMeta *prov,
+static GdaRow *gda_sqlite_provider_meta_view_column (GdaProviderMeta *prov,
const gchar *view_catalog, const gchar *view_schema,
const gchar *view_name,
const gchar *column_name,
@@ -476,6 +481,8 @@ static GdaRow *gda_sqlite_provider_meta_constraint_table (GdaProvider
const gchar *table_catalog, const gchar *table_schema,
const gchar *table_name,
const gchar *constraint_name_n, GError **error);
+static GdaDataModel *gda_sqlite_provider_meta_columns (GdaProviderMeta *prov,
+ GError **error);
static GdaDataModel *gda_sqlite_provider_meta_constraints_ref (GdaProviderMeta *prov,
GError **error);
static GdaDataModel *gda_sqlite_provider_meta_constraints_ref_table (GdaProviderMeta *prov,
@@ -559,14 +566,17 @@ gda_sqlite_provider_meta_iface_init (GdaProviderMetaInterface *iface) {
iface->character_set = gda_sqlite_provider_meta_character_set;
iface->schematas = gda_sqlite_provider_meta_schematas;
iface->schemata = gda_sqlite_provider_meta_schemata;
- iface->tables_views = gda_sqlite_provider_meta_tables_views;
- iface->table_view = gda_sqlite_provider_meta_table_view;
+ iface->tables_columns = gda_sqlite_provider_meta_tables_columns;
+ iface->tables = gda_sqlite_provider_meta_tables;
+ iface->table = gda_sqlite_provider_meta_table;
+ iface->views = gda_sqlite_provider_meta_views;
+ iface->view = gda_sqlite_provider_meta_view;
iface->columns = gda_sqlite_provider_meta_columns;
iface->table_columns = gda_sqlite_provider_meta_table_columns;
iface->table_column = gda_sqlite_provider_meta_table_column;
- iface->views_cols = gda_sqlite_provider_meta_views_cols;
- iface->view_cols = gda_sqlite_provider_meta_view_cols;
- iface->view_col = gda_sqlite_provider_meta_view_col;
+ iface->views_columns = gda_sqlite_provider_meta_views_columns;
+ iface->view_columns = gda_sqlite_provider_meta_view_columns;
+ iface->view_column = gda_sqlite_provider_meta_view_column;
iface->constraints_tables = gda_sqlite_provider_meta_constraints_tables;
iface->constraints_table = gda_sqlite_provider_meta_constraints_table;
iface->constraint_table = gda_sqlite_provider_meta_constraint_table;
@@ -4465,22 +4475,22 @@ gda_sqlite_provider_meta_schemata (GdaProviderMeta *prov,
return NULL;
}
static GdaDataModel*
-gda_sqlite_provider_meta_tables_views (GdaProviderMeta *prov,
+gda_sqlite_provider_meta_tables (GdaProviderMeta *prov,
GError **error)
{
g_return_val_if_fail (prov, NULL);
g_return_val_if_fail (GDA_IS_PROVIDER_META (prov), NULL);
return gda_provider_meta_execute_query (prov,
- "SELECT name as 'Table', 'system' as 'Owner',"
+ "SELECT name, 'system' as 'Owner',"
" ' ' as 'Description', sql as 'Definition' "
"FROM (SELECT * FROM sqlite_master "
"UNION ALL SELECT * FROM sqlite_temp_master) "
- "WHERE name not like 'sqlite_%%' ORDER BY name",
+ "WHERE name not like 'sqlite_%%' AND type='table' ORDER BY name",
NULL, error);
}
static GdaRow*
-gda_sqlite_provider_meta_table_view (GdaProviderMeta *prov,
+gda_sqlite_provider_meta_table (GdaProviderMeta *prov,
const gchar *table_catalog, const gchar *table_schema,
const gchar *table_name_n, GError **error)
{
@@ -4507,6 +4517,48 @@ gda_sqlite_provider_meta_table_view (GdaProviderMeta *prov,
return row;
}
static GdaDataModel*
+gda_sqlite_provider_meta_views (GdaProviderMeta *prov,
+ GError **error)
+{
+ g_return_val_if_fail (prov, NULL);
+ g_return_val_if_fail (GDA_IS_PROVIDER_META (prov), NULL);
+
+ return gda_provider_meta_execute_query (prov,
+ "SELECT name, 'system' as 'Owner',"
+ " ' ' as 'Description', sql as 'Definition' "
+ "FROM (SELECT * FROM sqlite_master "
+ "UNION ALL SELECT * FROM sqlite_temp_master) "
+ "WHERE name not like 'sqlite_%%' AND type='view' ORDER BY name",
+ NULL, error);
+}
+static GdaRow*
+gda_sqlite_provider_meta_view (GdaProviderMeta *prov,
+ const gchar *table_catalog, const gchar *table_schema,
+ const gchar *table_name_n, GError **error)
+{
+ g_return_val_if_fail (prov, NULL);
+ g_return_val_if_fail (GDA_IS_PROVIDER_META (prov), NULL);
+ GdaRow *row;
+ GdaSet *params;
+
+ params = gda_set_new_inline (1, "name", G_TYPE_STRING, NULL);
+ gda_set_set_holder_value (params, error, "name", table_name_n, NULL);
+ if (*error != NULL) {
+ g_object_unref (params);
+ return NULL;
+ }
+
+ row = gda_provider_meta_execute_query_row (prov,
+ "SELECT name, 'system' as 'Owner',"
+ " ' ' as 'Description', sql as 'Definition' "
+ "FROM (SELECT * FROM sqlite_master UNION ALL "
+ "SELECT * FROM sqlite_temp_master) "
+ "WHERE name = ##name::string name not like 'sqlite_%%' AND type = 'view' ORDER BY name",
+ params, error);
+ g_object_unref (params);
+ return row;
+}
+static GdaDataModel*
gda_sqlite_provider_meta_columns (GdaProviderMeta *prov,
GError **error)
{
@@ -4515,6 +4567,14 @@ gda_sqlite_provider_meta_columns (GdaProviderMeta *prov,
return NULL;
}
static GdaDataModel*
+gda_sqlite_provider_meta_tables_columns (GdaProviderMeta *prov,
+ GError **error)
+{
+ g_return_val_if_fail (prov, NULL);
+ g_return_val_if_fail (GDA_IS_PROVIDER_META (prov), NULL);
+ return NULL;
+}
+static GdaDataModel*
gda_sqlite_provider_meta_table_columns (GdaProviderMeta *prov,
const gchar *table_catalog, const gchar *table_schema,
const gchar *table_name, GError **error)
@@ -4534,7 +4594,7 @@ gda_sqlite_provider_meta_table_column (GdaProviderMeta *prov,
return NULL;
}
static GdaDataModel*
-gda_sqlite_provider_meta_views_cols (GdaProviderMeta *prov,
+gda_sqlite_provider_meta_views_columns (GdaProviderMeta *prov,
GError **error)
{
g_return_val_if_fail (prov, NULL);
@@ -4542,7 +4602,7 @@ gda_sqlite_provider_meta_views_cols (GdaProviderMeta *prov,
return NULL;
}
static GdaDataModel*
-gda_sqlite_provider_meta_view_cols (GdaProviderMeta *prov,
+gda_sqlite_provider_meta_view_columns (GdaProviderMeta *prov,
const gchar *view_catalog, const gchar *view_schema,
const gchar *view_name, GError **error)
{
@@ -4551,7 +4611,7 @@ gda_sqlite_provider_meta_view_cols (GdaProviderMeta *prov,
return NULL;
}
static GdaRow*
-gda_sqlite_provider_meta_view_col (GdaProviderMeta *prov,
+gda_sqlite_provider_meta_view_column (GdaProviderMeta *prov,
const gchar *view_catalog, const gchar *view_schema,
const gchar *view_name,
const gchar *column_name,
diff --git a/tests/meson.build b/tests/meson.build
index 4c66858a1..c4c2f7664 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -267,7 +267,7 @@ tmp = executable('test-provider-meta',
],
install: false
)
-test('ProviderMeta', tso,
+test('ProviderMeta', tmp,
env: [
'GDA_TOP_SRC_DIR='+meson.source_root(),
'GDA_TOP_BUILD_DIR='+meson.build_root()
@@ -283,4 +283,4 @@ subdir('value-holders')
subdir('ddl')
if enable_ui
subdir('ui')
-endif
+endif
\ No newline at end of file
diff --git a/tests/test-provider-meta.c b/tests/test-provider-meta.c
index 2f9c783f7..77cc8a07e 100644
--- a/tests/test-provider-meta.c
+++ b/tests/test-provider-meta.c
@@ -27,70 +27,80 @@ typedef struct {
GdaConnection *cnn;
} CheckProviderMeta;
-void init_data (CheckProviderMeta *data, gconstpointer user_data);
-void finish_data (CheckProviderMeta *data, gconstpointer user_data);
-void test_iface (CheckProviderMeta *data, gconstpointer user_data);
+void test_iface (void);
gint
main (gint argc,
gchar *argv[])
{
+ gchar *duri, *strc, *cstr, *db, *fpath;
+ const gchar *pdir;
+ GdaConnection *cnn;
+ GError *error = NULL;
+ GFile *dir, *dbf;
+ gint num = -1;
+
setlocale (LC_ALL,"");
gda_init ();
- g_test_init (&argc,&argv,NULL);
-
- g_test_add ("/gda/provider-meta/iface",
- CheckProviderMeta,
- NULL,
- init_data,
- test_iface,
- finish_data);
-
- return g_test_run();
-}
-
-void
-init_data (CheckProviderMeta *data, gconstpointer user_data) {
- GString *strc, *cstr;
- GdaConnection *cnn;
- GError *error = NULL;
- GFile *dir, *dbf;
-
- dir = g_file_new_for_path (BUILD_DIR);
- g_assert (g_file_query_exists (dir, NULL));
- cstr = g_string_new ("");
- g_string_printf (cstr, "%s/iter.db", g_file_get_uri (dir));
- dbf = g_file_new_for_uri (cstr->str);
- if (g_file_query_exists (dbf, NULL)) {
- g_file_delete (dbf, NULL, &error);
- if (error) {
- g_print ("Error deleting DB file: %s", error->message != NULL ? error->message : "No detail");
- g_assert_not_reached ();
- }
+ gchar **penv = g_get_environ ();
+ pdir = g_environ_getenv (penv, "GDA_TOP_BUILD_DIR");
+ GRand *rand = g_rand_new ();
+ dir = g_file_new_for_path (pdir);
+ if (!g_file_query_exists (dir, NULL)) {
+ g_assert_not_reached ();
}
- g_object_unref (dbf);
- strc = g_string_new ("");
- g_string_printf (strc,"DB_DIR=%s;DB_NAME=iter", g_file_get_path (dir));
+ duri = g_file_get_uri (dir);
+ num = g_rand_int (rand);
+ db = g_strdup_printf ("test%d", num);
+ strc = g_strdup_printf ("%s/tests/test%d.db", duri, num);
+ g_free (duri);
+ dbf = g_file_new_for_uri (strc);
+ g_free (strc);
+ while (g_file_query_exists (dbf, NULL)) {
+ g_free (db);
+ num = g_rand_int (rand);
+ db = g_strdup_printf ("test%d", num);
+ strc = g_strdup_printf ("%s/tests/meta-store/test%d.db", duri, num);
+ g_object_unref (dbf);
+ dbf = g_file_new_for_uri (db);
+ }
+ g_free (duri);
+ fpath = g_strdup_printf ("%s/tests", pdir);
+ cstr = g_strdup_printf ("DB_NAME=%s;DB_DIR=%s", db, fpath);
+ g_message ("Initializing Connection");
cnn = gda_connection_open_from_string ("SQLite",
- strc->str,
+ cstr,
NULL,
GDA_CONNECTION_OPTIONS_NONE,
&error);
- g_string_free (strc, TRUE);
+ g_free (cstr);
+ g_free (fpath);
+ g_free (db);
+ g_object_unref (dbf);
if (error) {
g_print ("Error creating/opening database: %s", error->message != NULL ? error->message : "No detail");
g_assert_not_reached ();
}
- g_print ("Initializing DB\n");
+ /* Initializing DB */
gint rows = 0;
- gda_connection_execute_non_select_command (cnn, "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)",
&error);
+ gda_connection_execute_non_select_command (cnn, "CREATE TABLE countries (id INTEGER PRIMARY KEY, name
TEXT)", &error);
+ if (error) {
+ g_print ("Error creating table users: %s", error->message != NULL ? error->message : "No detail");
+ g_assert_not_reached ();
+ }
+ gda_connection_execute_non_select_command (cnn, "CREATE TABLE cities (id INTEGER PRIMARY KEY, name TEXT,
city INTEGER REFERENCES cities(id))", &error);
+ if (error) {
+ g_print ("Error creating table users: %s", error->message != NULL ? error->message : "No detail");
+ g_assert_not_reached ();
+ }
+ gda_connection_execute_non_select_command (cnn, "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT,
city INTEGER REFERENCES cities(id)", &error);
if (error) {
g_print ("Error creating table users: %s", error->message != NULL ? error->message : "No detail");
g_assert_not_reached ();
@@ -113,20 +123,20 @@ init_data (CheckProviderMeta *data, gconstpointer user_data) {
g_print ("Error inserting data into table users: %s", error->message != NULL ? error->message : "No
detail");
g_assert_not_reached ();
}
- data->cnn = cnn;
-}
-
-
-void
-finish_data (CheckProviderMeta *data, gconstpointer user_data) {
- g_object_unref (data->cnn);
-}
+ /* Testing */
-
-void test_iface (CheckProviderMeta *data, gconstpointer user_data) {
- GdaConnection *cnn = data->cnn;
- GdaServerProvider *prov = gda_connection_get_provider (cnn);
+ GdaProviderMeta *prov = GDA_PROVIDER_META (gda_connection_get_provider (cnn));
+ GdaDataModel *model = NULL;
g_assert (prov != NULL);
g_assert (GDA_IS_PROVIDER_META (prov));
+ model = gda_provider_meta_tables (prov, &error);
+ if (model == NULL) {
+ g_message ("Error: %s", error->message);
+ g_assert_not_reached ();
+ }
+ g_assert (gda_data_model_get_n_rows (model) == 3);
+ g_message ("Tables:\n%s", gda_data_model_dump_as_string (model));
+ g_object_unref (cnn);
}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]