1 /*
2 * Copyright (C) 2008 - 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
19 #include <libgda/libgda.h>
20 #include <glib/gstdio.h>
21 #include <gda-ddl-creator.h>
22
23 int
main(int argc,char ** argv)24 main (int argc, char** argv)
25 {
26 GdaDDLCreator *ddl;
27 GError *error = NULL;
28 GdaConnection *cnc;
29 gchar *str;
30 gchar *file;
31
32 gda_init ();
33
34 ddl = gda_ddl_creator_new ();
35 file = g_build_filename (CHECK_FILES, "tests", "dbstruct.xml", NULL);
36 if (!gda_ddl_creator_set_dest_from_file (ddl, file, &error)) {
37 g_print ("Error creating GdaDDLCreator: %s\n", error && error->message ? error->message : "No detail");
38 g_error_free (error);
39 return EXIT_FAILURE;
40 }
41 g_free (file);
42
43 /* open a connection */
44 g_unlink ("creator.db");
45 cnc = gda_connection_open_from_string ("SQLite", "DB_DIR=.;DB_NAME=creator", NULL, GDA_CONNECTION_OPTIONS_NONE, &error);
46 if (!cnc) {
47 g_print ("Error opening connection: %s\n", error && error->message ? error->message : "No detail");
48 g_error_free (error);
49 return EXIT_FAILURE;
50 }
51 gda_ddl_creator_set_connection (ddl, cnc);
52 g_object_unref (cnc);
53
54 /* get SQL */
55 str = gda_ddl_creator_get_sql (ddl, &error);
56 if (!str) {
57 g_print ("Error getting SQL: %s\n", error && error->message ? error->message : "No detail");
58 g_error_free (error);
59 return EXIT_FAILURE;
60 }
61 g_print ("%s\n", str);
62 g_free (str);
63
64 /* execute */
65 if (!gda_ddl_creator_execute (ddl, &error)) {
66 g_print ("Error creating database objects: %s\n", error && error->message ? error->message : "No detail");
67 g_error_free (error);
68 return EXIT_FAILURE;
69 }
70
71 g_object_unref (ddl);
72 g_unlink ("creator.db");
73
74 return EXIT_SUCCESS;
75 }
76