[GRASS-user] db_fetch questions

Jaime Carrera jaicarrerahdez at yahoo.com
Thu Mar 20 10:11:53 EDT 2008


Hi Moritz,

Yes... that one works too; I overlooked it. Now its more clear for me how it works.

Thanks,
Jaime

Moritz Lennert <mlennert at club.worldonline.be> escribió: On 20/03/08 14:31, Jaime Carrera wrote:
> Hi Markus and Moritz,
> 
> Thanks for your suggestions; I tried another loop (the one from v.in.db) 
> and gave the result that I needed. Below are my "experiments":
> The first db_fetch loop (exits after one interaction): I have to "cheat" 
> to be able to get all the records from the database:
> 
>   while(1){
>     if(db_fetch (&cursor, DB_NEXT, &more) != DB_OK)
>       return(-1);
>     nodeprop=db_get_value_as_double(dbvalue,ctype);
>     printf("node prop= %.2f\n",nodeprop);
>     count++;
>     if(count<12699) /* use max(cat) value for this one, just testing*/
>        more=0;
>     if ( more) break;
>   }
> 
> Now, using the loop as used in v.in.db I get what I need, without 
> "cheating':
> 
>    while ( db_fetch (&cursor, DB_NEXT, &more ) == DB_OK && more ) {
>      nodeprop=db_get_value_as_double(dbvalue,ctype);
>      printf("node prop= %.2f\n",nodeprop);
>    }
> 
> There are two differences: on the first loop more==1 immediately, and 
> thus exits the loop; while on the second one the loop is exptecting 
> more==1. Another difference is the != or == DB_OK part.
> 
> What I can gather from this, is that the first loop is more appropriate 
> to queries done on a category basis, but not for fetching an entire table.

I don't really understand the first one. Why do you break if more==1 ? 
Instead of

if(count<12699) /* use max(cat) value for this one, just testing*/
      more=0;
if ( more) break;

Shouldn't this just be

if(!more) break;

?

Moritz


       
---------------------------------

¡Capacidad ilimitada de almacenamiento en tu correo!
No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:
http://correo.espanol.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20080320/29bccafb/attachment.html


More information about the grass-user mailing list