~ubuntu-branches/ubuntu/karmic/libgda4/karmic

« back to all changes in this revision

Viewing changes to tests/test-ddl-creator.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2009-02-02 23:06:15 UTC
  • Revision ID: james.westby@ubuntu.com-20090202230615-q081lez252bfipw5
Tags: upstream-3.99.11
ImportĀ upstreamĀ versionĀ 3.99.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GDA - Information schema documentation extractor
 
2
 * Copyright (C) 2008 The GNOME Foundation.
 
3
 *
 
4
 * AUTHORS:
 
5
 *      Vivien Malerba <malerba@gnome-db.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
 */
 
21
 
 
22
#include <libgda/libgda.h>
 
23
#include <gda-ddl-creator.h>
 
24
 
 
25
int
 
26
main (int argc, char** argv)
 
27
{
 
28
        GdaDDLCreator *ddl;
 
29
        GError *error = NULL;
 
30
        GdaConnection *cnc;
 
31
        gchar *str;
 
32
 
 
33
        gda_init ();
 
34
        
 
35
        ddl = gda_ddl_creator_new ();
 
36
        if (!gda_ddl_creator_set_dest_from_file (ddl, "dbstruct.xml", &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
        
 
42
        /* open a connection */
 
43
        cnc = gda_connection_open_from_string ("SQLite", "DB_DIR=.;DB_NAME=creator", NULL, GDA_CONNECTION_OPTIONS_NONE, &error);
 
44
        if (!cnc) {
 
45
                g_print ("Error opening connection: %s\n", error && error->message ? error->message : "No detail");
 
46
                g_error_free (error);
 
47
                return EXIT_FAILURE;
 
48
        }
 
49
        gda_ddl_creator_set_connection (ddl, cnc);
 
50
        g_object_unref (cnc);
 
51
 
 
52
        /* get SQL */
 
53
        str = gda_ddl_creator_get_sql (ddl, &error);
 
54
        if (!str) {
 
55
                g_print ("Error getting SQL: %s\n", error && error->message ? error->message : "No detail");
 
56
                g_error_free (error);
 
57
                return EXIT_FAILURE;
 
58
        }
 
59
        g_print ("%s\n", str);
 
60
        g_free (str);
 
61
 
 
62
        /* execute */
 
63
        if (!gda_ddl_creator_execute (ddl, &error)) {
 
64
                g_print ("Error creating database objects: %s\n", error && error->message ? error->message : "No detail");
 
65
                g_error_free (error);
 
66
                return EXIT_FAILURE;
 
67
        }
 
68
 
 
69
        g_object_unref (ddl);
 
70
 
 
71
        return EXIT_SUCCESS;
 
72
}