Обсуждение: Question regarding string returned from PQgetvalue

Поиск
Список
Период
Сортировка

Question regarding string returned from PQgetvalue

От
Louis Bouchard
Дата:
I run this query and put the result into a PGresult variable caller result:

SELECT COUNT(*) FROM driver WHERE driverID = :driverID

I then grab the value using PQgetvalue and put it into a string.

The query should return 0 because there are no records in the table as
of yet. When I run the program however, the value returned is 48.

I used GDB to look at what was in the string and I saw this information:

48 "0"

When I put a record in the table with driverID of 1 and run the query
again, I get this value:

49 "1"

This tells me that the value is put into the string correctly but I am
getting extra information. Is there a way to get rid of this extra
information without having to parse the string?

Thank You

--
Louis J Bouchard
de KC2FNN
Rochester Minnesota USA
louisjbouchard@charter.net
--
"I wanted you to see what real courage is, instead of getting the idea that
courage is a man with a gun in hand. It's when you know you're licked before
you begin but you begin anyway and you see it through no matter what. You
rarely win, but sometimes you do."
-----------------------------
Atticus Finch            To Kill a Mockingbird


Re: Question regarding string returned from PQgetvalue

От
Tom Lane
Дата:
Louis Bouchard <louisjbouchard@charter.net> writes:
> The query should return 0 because there are no records in the table as
> of yet. When I run the program however, the value returned is 48.
> I used GDB to look at what was in the string and I saw this information:
> 48 "0"

You seem to have a fundamental confusion between text strings and
machine integers.  PQgetvalue is going to return a pointer to a text
string.  Use strtol or atoi or some such to convert the string to
an integer.

            regards, tom lane