grass  7.8.6
About: GRASS (Geographic Resources Analysis Support System) is a raster- and vector-based GIS, image processing system, graphics production system and spatial modeling system.
  Fossies Dox: grass-7.8.6.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

select.c File Reference

DBMI Library (client) - select records from table. More...

#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>
Include dependency graph for select.c:

Go to the source code of this file.

Functions

static int cmp (const void *pa, const void *pb)
 
static int cmpcat (const void *pa, const void *pb)
 
static int cmpcatkey (const void *pa, const void *pb)
 
static int cmpvalueint (const void *pa, const void *pb)
 
static int cmpvaluedouble (const void *pa, const void *pb)
 
static int cmpvaluestring (const void *pa, const void *pb)
 
int db_select_int (dbDriver *driver, const char *tab, const char *col, const char *where, int **pval)
 Select array of ordered integers from table/column. More...
 
int db_select_value (dbDriver *driver, const char *tab, const char *key, int id, const char *col, dbValue *val)
 Select one (first) value from table/column for key/id. More...
 
int db_select_CatValArray (dbDriver *driver, const char *tab, const char *key, const char *col, const char *where, dbCatValArray *cvarr)
 Select pairs key/value to array, values are sorted by key (must be integer) More...
 
void db_CatValArray_sort (dbCatValArray *arr)
 Sort key/value array by key. More...
 
int db_CatValArray_sort_by_value (dbCatValArray *arr)
 Sort key/value array by value. More...
 
int db_CatValArray_get_value (dbCatValArray *arr, int key, dbCatVal **cv)
 Find value by key. More...
 
int db_CatValArray_get_value_int (dbCatValArray *arr, int key, int *val)
 Find value (integer) by key. More...
 
int db_CatValArray_get_value_double (dbCatValArray *arr, int key, double *val)
 Find value (double) by key. More...
 

Detailed Description

DBMI Library (client) - select records from table.

(C) 1999-2008 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Joel Jones (CERL/UIUC), Radim Blazek

Definition in file select.c.

Function Documentation

◆ cmp()

static int cmp ( const void *  pa,
const void *  pb 
)
static

Definition at line 21 of file select.c.

Referenced by db_select_int().

◆ cmpcat()

static int cmpcat ( const void *  pa,
const void *  pb 
)
static

Definition at line 33 of file select.c.

References dbCatVal::cat.

Referenced by db_CatValArray_get_value(), db_CatValArray_get_value_int(), and db_CatValArray_sort().

◆ cmpcatkey()

static int cmpcatkey ( const void *  pa,
const void *  pb 
)
static

Definition at line 45 of file select.c.

References dbCatVal::cat.

Referenced by db_CatValArray_get_value_double().

◆ cmpvaluedouble()

static int cmpvaluedouble ( const void *  pa,
const void *  pb 
)
static

Definition at line 70 of file select.c.

References dbCatVal::d, and dbCatVal::val.

Referenced by db_CatValArray_sort_by_value().

◆ cmpvalueint()

static int cmpvalueint ( const void *  pa,
const void *  pb 
)
static

Definition at line 57 of file select.c.

References dbCatVal::i, and dbCatVal::val.

Referenced by db_CatValArray_sort_by_value().

◆ cmpvaluestring()

static int cmpvaluestring ( const void *  pa,
const void *  pb 
)
static

Definition at line 83 of file select.c.

References a, and b.

Referenced by db_CatValArray_sort_by_value().

◆ db_CatValArray_get_value()

int db_CatValArray_get_value ( dbCatValArray arr,
int  key,
dbCatVal **  cv 
)

Find value by key.

Parameters
arrdbCatValArray (key/value array)
keykey value
[out]cvdbCatVal structure (key/value) to store within
Returns
DB_OK on success
DB_FAILED on error

Definition at line 466 of file select.c.

References cmpcat(), DB_FAILED, DB_OK, key, dbCatValArray::n_values, NULL, and dbCatValArray::value.

◆ db_CatValArray_get_value_double()

int db_CatValArray_get_value_double ( dbCatValArray arr,
int  key,
double *  val 
)

Find value (double) by key.

Parameters
arrdbCatValArray (key/value array)
keykey value
[out]valfound value (double)
Returns
DB_OK on success
DB_FAILED on error

Definition at line 518 of file select.c.

References cmpcatkey(), dbCatVal::d, DB_FAILED, DB_OK, G_debug(), key, dbCatValArray::n_values, NULL, dbCatVal::val, and dbCatValArray::value.

Referenced by IL_vector_input_data_2d(), NetA_get_node_costs(), Vect_net_build_graph(), and Vect_net_ttb_build_graph().

◆ db_CatValArray_get_value_int()

int db_CatValArray_get_value_int ( dbCatValArray arr,
int  key,
int *  val 
)

Find value (integer) by key.

Parameters
arrdbCatValArray (key/value array)
keykey value
[out]valfound value (integer)
Returns
DB_OK on success
DB_FAILED on error

Definition at line 492 of file select.c.

References cmpcat(), DB_FAILED, DB_OK, dbCatVal::i, key, dbCatValArray::n_values, NULL, dbCatVal::val, and dbCatValArray::value.

Referenced by IL_vector_input_data_2d(), Vect_net_build_graph(), and Vect_net_ttb_build_graph().

◆ db_CatValArray_sort()

void db_CatValArray_sort ( dbCatValArray arr)

Sort key/value array by key.

Parameters
[in,out]arrdbCatValArray (key/value array)

Definition at line 417 of file select.c.

References cmpcat(), dbCatValArray::n_values, and dbCatValArray::value.

Referenced by db_select_CatValArray().

◆ db_CatValArray_sort_by_value()

int db_CatValArray_sort_by_value ( dbCatValArray arr)

Sort key/value array by value.

Parameters
[in,out]arrdbCatValArray (key/value array)
Returns
DB_OK on success
DB_FAILED on error

Definition at line 430 of file select.c.

References cmpvaluedouble(), cmpvalueint(), cmpvaluestring(), dbCatValArray::ctype, DB_C_TYPE_DATETIME, DB_C_TYPE_DOUBLE, DB_C_TYPE_INT, DB_C_TYPE_STRING, DB_FAILED, DB_OK, dbCatValArray::n_values, and dbCatValArray::value.

Referenced by Vedit_bulk_labeling().

◆ db_select_CatValArray()

◆ db_select_int()

int db_select_int ( dbDriver driver,
const char *  tab,
const char *  col,
const char *  where,
int **  pval 
)

Select array of ordered integers from table/column.

Parameters
driverDB driver
tabtable name
colcolumn name
wherewhere statement
[out]pvalarray of ordered integer values
Returns
number of selected values
-1 on error

Definition at line 103 of file select.c.

References _, cmp(), count, DB_C_TYPE_DOUBLE, DB_C_TYPE_INT, DB_C_TYPE_STRING, db_close_cursor(), db_fetch(), db_free_string(), db_get_column_sqltype(), db_get_column_value(), db_get_cursor_table(), db_get_table_column(), db_get_value_double(), db_get_value_int(), db_get_value_string(), db_init_string(), DB_NEXT, DB_OK, db_open_select_cursor(), DB_SEQUENTIAL, db_set_string(), db_sqltype_to_Ctype(), G_asprintf(), G_debug(), G_free(), G_warning(), more(), NULL, table, and type.

Referenced by Vect_cats_set_constraint(), Vect_set_varray_from_db(), and Vect_write_ascii().

◆ db_select_value()

int db_select_value ( dbDriver driver,
const char *  tab,
const char *  key,
int  id,
const char *  col,
dbValue val 
)

Select one (first) value from table/column for key/id.

Parameters
driverDB driver
tabtable name
keykey column name
ididentifier in key column
colname of column to select the value from
[out]valdbValue to store within
Returns
number of selected values
-1 on error

Definition at line 204 of file select.c.

References _, count, db_close_cursor(), db_copy_value(), db_fetch(), db_free_string(), db_get_column_value(), db_get_cursor_table(), db_get_table_column(), db_init_string(), DB_NEXT, DB_OK, db_open_select_cursor(), DB_SEQUENTIAL, db_set_string(), G_asprintf(), G_free(), G_warning(), G_zero(), key, more(), NULL, and table.

Referenced by Gp_load_sites_thematic(), Gv_load_vect_thematic(), and Vect_write_ascii().