tags:

views:

166

answers:

2

I use PostgreSQL database and C to connect to it. With a help from dyntest.pgc I can access to number of columns and their (SQL3) types from a result table of a query.

Problem is that when result table is empty, I can't fetch a row to get this data. Does anyone have a solution for this?

Query can be SELECT 1,2,3 - so, I think I can't use INFORMATION SCHEMA for this because there is no base table.

A: 

Problem is that when result table is empty, I can't fetch a row to get this data. Does anyone have a solution for this?

I am not sure to really get what you want, but it seems the answer is in the question. If the table is empty, there are no rows...

The only solution here seems you must wait a non empty result table, and then get the needed informations.

Jérôme
I don't want to fetch a row, I just want number of columns and types, but I must because I don't know a better way to get this other that one in "dyntest.pgc"
kliketa
+1  A: 

I'm not familiar with ecpg, but with libpq you should be able to call PQnfields to get the number of fields and then call various PQf* routines (like PQftype, PQfname) to get detailed info. Those functions take a PGResult, which you have even if there are no rows.

dwc