}
}
+static void
+read_views ()
+{
+ GError *error;
+
+ GdaDataModel *dm_views;
+
+ guint rows;
+ guint row;
+
+ gchar *view_name;
+ gchar *view_def;
+
+ GdaServerOperation *op;
+
+ GValue *gval;
+ GdaMetaStore *store;
+ GdaMetaStruct *mstruct;
+ GdaMetaDbObject *dbo;
+
+ error = NULL;
+ dm_views = gda_connection_get_meta_store_data (gda_conn_ref_db,
+ GDA_CONNECTION_META_VIEWS,
+ &error,
+ 0);
+ if (dm_views != NULL && error == NULL)
+ {
+ rows = gda_data_model_get_n_rows (dm_views);
+ for (row = 0; row < rows; row++)
+ {
+ view_name = g_strdup (gda_value_stringify (gda_data_model_get_value_at (dm_views, 0, row, NULL)));
+
+ g_printf ("\tView: %s\n",
+ view_name);
+
+ if (drop_tables)
+ {
+ gchar *sql;
+
+ sql = g_strdup_printf ("DROP VIEW %s",
+ view_name);
+ gda_connection_execute_non_select_command (gda_conn_db,
+ sql,
+ NULL);
+
+ g_free (sql);
+ }
+
+ error = NULL;
+
+ gval = gda_value_new (G_TYPE_STRING);
+ g_value_set_string (gval, view_name);
+
+ store = gda_connection_get_meta_store (gda_conn_ref_db);
+ mstruct = gda_meta_struct_new (store, GDA_META_STRUCT_FEATURE_NONE);
+ dbo = gda_meta_struct_complement (mstruct, GDA_META_DB_VIEW,
+ NULL, NULL,
+ gval, &error);
+
+ gda_value_free (gval);
+ if (dbo != NULL)
+ {
+ gchar *tmp;
+ gchar *tmp_low;
+
+ GdaMetaView *meta_view = GDA_META_VIEW (dbo);
+
+ tmp_low = g_ascii_strup (meta_view->view_def, -1);
+ tmp = g_strstr_len (tmp_low, -1, "SELECT");
+ if (tmp != NULL)
+ {
+ view_def = g_strdup (meta_view->view_def +
+ (tmp - tmp_low));
+ g_free (tmp_low);
+ }
+ else
+ {
+ g_free (tmp_low);
+ g_warning ("Unable to get view's definition.");
+ continue;
+ }
+ }
+ else
+ {
+ g_warning ("Unable to get view's definition: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+ if (verbose)
+ {
+ g_printf ("\t\tSql: %s\n",
+ view_def);
+ }
+
+ /* starting server operation */
+ error = NULL;
+ op = gda_connection_create_operation (gda_conn_db, GDA_SERVER_OPERATION_CREATE_VIEW, NULL, &error);
+ if (op == NULL
+ || error != NULL)
+ {
+ g_warning ("Error on creating GdaServerOperation: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+ error = NULL;
+ if (!gda_server_operation_set_value_at (op, view_name, &error,
+ "/VIEW_DEF_P/VIEW_NAME"))
+ {
+ g_warning ("Error on setting GdaServerOperation's value: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+ error = NULL;
+ if (!gda_server_operation_set_value_at (op, view_def, &error,
+ "/VIEW_DEF_P/VIEW_DEF"))
+ {
+ g_warning ("Error on setting GdaServerOperation's value: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+ error = NULL;
+ if (!gda_connection_perform_operation (gda_conn_db, op, &error))
+ {
+ g_warning ("Error on performing GdaServerOperation: %s.",
+ error != NULL && error->message != NULL ? error->message : "no details");
+ continue;
+ }
+
+ g_free (view_def);
+ g_free (view_name);
+
+ g_object_unref (op);
+ }
+ }
+ if (dm_views != NULL)
+ {
+ g_object_unref (dm_views);
+ }
+}
+
int
main (int argc, char *argv[])
{
g_printf ("* Copying data.\n");
copy_data ();
+ g_printf ("* Reading views.\n");
+ read_views ();
+
g_object_unref (gda_conn_ref_db);
g_object_unref (gda_conn_db);