21static int cmp(
const void *
pa,
const void *pb)
33static int cmpcat(
const void *
pa,
const void *pb)
38 if (
p1->cat < p2->
cat)
40 if (
p1->cat > p2->
cat)
45static int cmpcatkey(
const void *
pa,
const void *pb)
57static int cmpvalueint(
const void *
pa,
const void *pb)
62 if (
p1->val.i < p2->
val.i)
64 if (
p1->val.i > p2->
val.i)
70static int cmpvaluedouble(
const void *
pa,
const void *pb)
75 if (
p1->val.d < p2->
val.d)
77 if (
p1->val.d > p2->
val.d)
83static int cmpvaluestring(
const void *
pa,
const void *pb)
88 return strcmp((
const char *)a, (
const char *)
b);
104 const char *where,
int **
pval)
106 int type, more, alloc,
count;
149 val = (
int *)
G_malloc(alloc *
sizeof(
int));
161 if (
count == alloc) {
163 val = (
int *)
G_realloc(val, alloc *
sizeof(
int));
274 const char *
col,
const char *where,
277 int i, type, more, nrows, ncols;
285 G_debug(3,
"db_select_CatValArray ()");
320 G_debug(3,
" %d rows selected", nrows);
335 G_debug(3,
" key type = %d", type);
338 G_warning(
_(
"Key column type is not integer"));
347 G_debug(3,
" col type = %d", type);
359 for (i = 0; i < nrows; i++) {
375 cvarr->value[i].val.i = 0;
382 cvarr->value[i].val.d = 0.0;
407 cvarr->n_values = nrows;
436 switch (
arr->ctype) {
523 G_debug(3,
"db_CatValArray_get_value_double(), key = %d", key);
int db_CatValArray_get_value_double(dbCatValArray *arr, int key, double *val)
Find value (double) by key.
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)
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.
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.
int db_CatValArray_get_value_int(dbCatValArray *arr, int key, int *val)
Find value (integer) by key.
void db_CatValArray_sort(dbCatValArray *arr)
Sort key/value array by key.
int db_CatValArray_sort_by_value(dbCatValArray *arr)
Sort key/value array by value.
int db_CatValArray_get_value(dbCatValArray *arr, int key, dbCatVal **cv)
Find value by key.
Main header of GRASS DataBase Management Interface.
struct _db_date_time dbDateTime
#define DB_C_TYPE_DATETIME
void db_copy_value(dbValue *, dbValue *)
Copy value.
int db_CatValArray_alloc(dbCatValArray *, int)
Allocate dbCatValArray.
dbColumn * db_get_table_column(dbTable *, int)
Returns column structure for given table and column number.
double db_get_value_double(dbValue *)
Get double precision value.
int db_sqltype_to_Ctype(int)
Get C data type based on given SQL data type.
dbValue * db_get_column_value(dbColumn *)
Returns column value for given column structure.
int db_get_column_sqltype(dbColumn *)
Returns column sqltype for column.
int db_get_num_rows(dbCursor *)
Get number of selected rows.
void db_free_string(dbString *)
Free allocated space for dbString.
char * db_get_string(const dbString *)
Get string.
dbTable * db_get_cursor_table(dbCursor *)
Get table allocated by cursor.
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
int db_get_value_int(dbValue *)
Get integer value.
void db_init_string(dbString *)
Initialize dbString.
int db_close_cursor(dbCursor *)
Close cursor.
int db_open_select_cursor(dbDriver *, dbString *, dbCursor *, int)
Open select cursor.
int db_append_string(dbString *, const char *)
Append string to dbString.
const char * db_get_value_string(dbValue *)
Get string value.
int db_fetch(dbCursor *, int, int *)
Fetch data from open cursor.
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
void G_free(void *)
Free allocated memory.
void G_warning(const char *,...) __attribute__((format(printf
int G_asprintf(char **, const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf