[GRASS5] db_get_value_...

Hallo,
I try do get some data (double, string) from database column and I'm not able to manage this. What is the best place (module/file), where to look at the code, how to do this?
I try following:

double height;
int cat;
int point = 0;
char sql[1024];
...

cat = Vect_get_line_cat(&In, point, Clist->field);
db_init_string(&sql);
sprintf(query, "SELECT %s FROM %s WHERE %s = %d",
                        hcolumn->answer, Fi->table, Fi->key, cat);
printf("%s", query);
# SELECT height FROM strom WHERE cat = 1

db_append_string(&sql, query);

db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL)
table = db_get_cursor_table(&cursor);
hdbcolumn = db_get_table_column(table, 0);/* first column */
value = db_get_column_value(hdbcolumn);
height = db_get_value_as_double(value, db_get_column_host_type(hdbcolumn));

printf("%f",height);
# 0.0

height will allways get 0.0 value. There is only one point in the file of category 1. Height column is of type double. I can not find, where the problem could be :-/

Thanks for help

Jachym

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
LDF MZLU v Brnì
Zemìdìlská 3
613 00 Brno
e-mail: xcepicky@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

On Tue, January 31, 2006 20:08, Jáchym Èepický wrote:

Hallo,
I try do get some data (double, string) from database column and I'm not
able to manage this. What is the best place (module/file), where to look
at the code, how to do this?

How about v.db.select ?

Moritz

Reading individual values using WHERE is very slow
because of communication between GRASS and DB server.
The solution is to read all the values to a cat-value array and then
read values from the array. There is API ready in GRASS, look
for example into r.to.vect. You should be able to do it with
db_start_driver_open_database
db_select_CatValArray
db_close_database_shutdown_driver
db_CatValArray_get_value_int

Radim

On 1/31/06, Jáchym Èepický <jachym.cepicky@centrum.cz> wrote:

Hallo,
I try do get some data (double, string) from database column and I'm not able to manage this. What is the best place (module/file), where to look at the code, how to do this?
I try following:

double height;
int cat;
int point = 0;
char sql[1024];
...

cat = Vect_get_line_cat(&In, point, Clist->field);
db_init_string(&sql);
sprintf(query, "SELECT %s FROM %s WHERE %s = %d",
                        hcolumn->answer, Fi->table, Fi->key, cat);
printf("%s", query);
# SELECT height FROM strom WHERE cat = 1

db_append_string(&sql, query);

db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL)
table = db_get_cursor_table(&cursor);
hdbcolumn = db_get_table_column(table, 0);/* first column */
value = db_get_column_value(hdbcolumn);
height = db_get_value_as_double(value, db_get_column_host_type(hdbcolumn));

printf("%f",height);
# 0.0

height will allways get 0.0 value. There is only one point in the file of category 1. Height column is of type double. I can not find, where the problem could be :-/

Thanks for help

Jachym

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
LDF MZLU v Brnì
Zemìdìlská 3
613 00 Brno
e-mail: xcepicky@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

_______________________________________________
grass5 mailing list
grass5@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass5