[GRASS5] db_get_value_...

Radim Blazek radim.blazek at gmail.com
Wed Feb 1 04:01:50 EST 2006


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 at 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 at 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 at node.mendelu.cz
> URL: http://mapserver.mendelu.cz
> Tel.: +420 545 134 514
>
> _______________________________________________
> grass5 mailing list
> grass5 at grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass5
>




More information about the grass-dev mailing list