1 /*
2  * Copyright (C) 2009 - 2011 Vivien Malerba <malerba@gnome-db.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 #include <libgda/libgda.h>
19 
20 int
main(int argc,char * argv[])21 main (int argc, char *argv[])
22 {
23 	GdaConnection *cnc;
24 
25 	GdaTree *tree;
26         GdaTreeManager *schemas_mgr, *tables_mgr, *columns_mgr;
27         GError *error = NULL;
28 
29         gda_init ();
30 
31         cnc = gda_connection_open_from_dsn ("SalesTest", NULL, GDA_CONNECTION_OPTIONS_NONE, NULL);
32         g_assert (cnc);
33         g_print ("Updating meta store...");
34         GdaMetaContext context = {"_tables", 0};
35         gda_connection_update_meta_store (cnc, &context, NULL);
36         g_print ("done.\n");
37 
38         tree = gda_tree_new ();
39 
40 	/* create tree managers */
41         schemas_mgr = gda_tree_mgr_schemas_new (cnc);
42         tables_mgr = gda_tree_mgr_tables_new (cnc, NULL);
43         columns_mgr = gda_tree_mgr_columns_new (cnc, NULL, NULL);
44 
45 	/* set up the tree managers in the tree */
46         gda_tree_add_manager (tree, schemas_mgr);
47         gda_tree_add_manager (tree, tables_mgr);
48 
49         gda_tree_manager_add_manager (schemas_mgr, tables_mgr);
50         gda_tree_manager_add_manager (tables_mgr, columns_mgr);
51 
52 	/* we don't need object references anymore */
53         g_object_unref (schemas_mgr);
54         g_object_unref (tables_mgr);
55         g_object_unref (columns_mgr);
56 
57 	/* populate the tree and display its contents */
58         if (!gda_tree_update_all (tree, &error))
59                 g_print ("Can't populate tree: %s\n", error && error->message ? error->message : "No detail");
60         else
61                 gda_tree_dump (tree, NULL, NULL);
62 
63         g_object_unref (tree);
64         gda_connection_close (cnc);
65         g_object_unref (cnc);
66 
67         return 0;
68 }
69