~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to db/base/columns.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/****************************************************************************
3
 
 *
4
 
 * MODULE:       db.columns
5
 
 * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
6
 
 *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
7
 
 * PURPOSE:      list the column names for a table
8
 
 * COPYRIGHT:    (C) 2002-2006 by the GRASS Development Team
9
 
 *
10
 
 *               This program is free software under the GNU General Public
11
 
 *               License (>=v2). Read the file COPYING that comes with GRASS
12
 
 *               for details.
13
 
 *
14
 
 *****************************************************************************/
15
 
 
16
 
#include <grass/gis.h>
17
 
#include <grass/dbmi.h>
18
 
#include <grass/codes.h>
19
 
#include <stdlib.h>
20
 
#include <grass/glocale.h>
21
 
 
22
 
 
23
 
struct
24
 
{
25
 
    char *driver, *database, *table;
26
 
} parms;
27
 
 
28
 
 
29
 
/* function prototypes */
30
 
static void parse_command_line(int, char **);
31
 
 
32
 
 
33
 
int main(int argc, char **argv)
34
 
{
35
 
    dbDriver *driver;
36
 
    dbHandle handle;
37
 
    dbTable *table;
38
 
    dbString table_name;
39
 
    int col, ncols;
40
 
 
41
 
    parse_command_line(argc, argv);
42
 
 
43
 
    driver = db_start_driver(parms.driver);
44
 
    if (driver == NULL)
45
 
        G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
46
 
 
47
 
    db_init_handle(&handle);
48
 
    db_set_handle(&handle, parms.database, NULL);
49
 
    if (db_open_database(driver, &handle) != DB_OK)
50
 
        exit(EXIT_FAILURE);
51
 
 
52
 
    db_init_string(&table_name);
53
 
    db_set_string(&table_name, parms.table);
54
 
    if (db_describe_table(driver, &table_name, &table) != DB_OK)
55
 
        exit(EXIT_FAILURE);
56
 
 
57
 
    db_close_database(driver);
58
 
    db_shutdown_driver(driver);
59
 
 
60
 
    ncols = db_get_table_number_of_columns(table);
61
 
    for (col = 0; col < ncols; col++)
62
 
        fprintf(stdout, "%s\n",
63
 
                db_get_column_name(db_get_table_column(table, col)));
64
 
 
65
 
    exit(EXIT_SUCCESS);
66
 
}
67
 
 
68
 
 
69
 
static void parse_command_line(int argc, char **argv)
70
 
{
71
 
    struct Option *driver, *database, *table;
72
 
    struct GModule *module;
73
 
    const char *drv, *db;
74
 
 
75
 
    /* Initialize the GIS calls */
76
 
    G_gisinit(argv[0]);
77
 
 
78
 
    table = G_define_standard_option(G_OPT_TABLE);
79
 
    table->required = YES;
80
 
 
81
 
    driver = G_define_standard_option(G_OPT_DRIVER);
82
 
    driver->options = db_list_drivers();
83
 
    if ((drv = db_get_default_driver_name()))
84
 
        driver->answer = (char *) drv;
85
 
 
86
 
    database = G_define_standard_option(G_OPT_DATABASE);
87
 
    if ((db = db_get_default_database_name()))
88
 
        database->answer = (char *) db;
89
 
 
90
 
    /* Set description */
91
 
    module = G_define_module();
92
 
    module->keywords = _("database, attribute table");
93
 
    module->description = _("List all columns for a given table.");
94
 
 
95
 
    if (G_parser(argc, argv))
96
 
        exit(EXIT_FAILURE);
97
 
 
98
 
    parms.driver = driver->answer;
99
 
    parms.database = database->answer;
100
 
    parms.table = table->answer;
101
 
}