File: db.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (42 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <grass/vector.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>

/* get height for DB
   returns 0 on success -1 on failure
 */
int get_height(const struct field_info *Fi, const char *hcolumn,
               dbDriver *driver, int cat, double *height)
{
    int more;
    double objheight;
    char query[DB_SQL_MAX];

    dbString sql;
    dbCursor cursor;
    dbTable *table;
    dbColumn *column;
    dbValue *value;

    db_init_string(&sql);
    sprintf(query, "SELECT %s FROM %s WHERE %s = %d", hcolumn, Fi->table,
            Fi->key, cat);
    G_debug(3, "SQL: %s", query);
    db_set_string(&sql, query);
    if (db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL) != DB_OK)
        G_fatal_error(_("Unable to select attributes category %d"), cat);
    table = db_get_cursor_table(&cursor);
    column = db_get_table_column(table, 0); /* first column */

    if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK)
        return -1;

    value = db_get_column_value(column);
    G_debug(3, "column_host_type: %d", db_get_column_host_type(column));
    objheight = db_get_value_as_double(value, DB_C_TYPE_DOUBLE);
    G_debug(3, "height from DB: %f", objheight);

    *height = objheight;

    return 0;
}