请问如下语句:
select sum(money) from table;
如何取得计算出来的值 。
c libpq 接口 用哪个API 谢谢!

解决方案 »

  1.   

    呵呵,帖一段给你参考,具体还要看手册:
    PGconn * connection, const char * query_text       
    PGresult  *       result; 97   if(( result = PQexec( connection, query_text )) == NULL )
     98   {
     99     printf( "%s\n", PQerrorMessage( connection ));
    100     return;
    101   }
    102
    103   if( PQresultStatus( result ) == PGRES_TUPLES_OK )
    104   {
    105     print_result_set( result );
    106   }17 void print_result_set( PGresult * result )
     18 {
     19   int          col;
     20   int          row;
     21   int            * sizes;
     22
     23 /*
     24 ** Compute the size for each column
     25 */
     26   sizes = (int *)calloc( PQnfields( result ), sizeof( int ));
     27
     28   for( col = 0; col < PQnfields( result ); col++ )
     29   {
     30     int     len = 0;
     31
     32     for( row = 0; row < PQntuples( result ); row++ )
     33     {
     34       if( PQgetisnull( result, row, col ))
     35         len = 0;
     36       else
     37         len = PQgetlength( result, row, col );
     38
     39       if( len > sizes[col] )
     40         sizes[col] = len;
     41     }
     42
     43     if(( len = strlen( PQfname( result, col ))) > sizes[col] )
     44       sizes[col] = len;
     45
     46     if( sizes[col] > MAX_PRINT_LEN )
     47       sizes[col] = MAX_PRINT_LEN;
     48   }
      

  2.   

    上边的参考代码还不够吗?
    PQexec
    PQresultStatus
    PQnfields
    PQntuples
    就这几个api啊。