BUG #3015: libpq: PQftype() on a lo type result column returns Oid of type oid instead of Oid of type lo. - Mailing list pgsql-bugs

From
Subject BUG #3015: libpq: PQftype() on a lo type result column returns Oid of type oid instead of Oid of type lo.
Date
Msg-id 200702151852.l1FIqWOm063241@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #3015: libpq: PQftype() on a lo type result column returns Oid of type oid instead of Oid of type lo.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      3015
Logged by:
Email address:      churi@roguewave.com
PostgreSQL version: 8.2.3
Operating system:   Windows XP
Description:        libpq: PQftype() on a lo type result column returns Oid
of type oid instead of Oid of type lo.
Details:

=== Environment ===
PostgreSQL server version: 8.2.3
PostgreSQL libpq C library version: 8.2.3
CPU (client and server): Intel Pentium 4
Operating System (client & server): Windows XP SP2
Compiler: Visual C++ 2005 32-bit

=== Problem ===
I am migrating my product from using PostgreSQL 8.0.4 to PostgreSQL 8.2.3. I
am migrating both server as well as libpq client.
If a SELECT statement is querying a lo type column of a table, PQftype()
call on that column used to return Oid of type lo in PostgreSQL 8.0.4. It
now returns Oid of type oid in PostgreSQL 8.2.3.

=== Test Case ===

== SQLs ==

qe1=> select typname, oid from pg_catalog.pg_type where typname = 'lo' OR
typnam
e = 'oid';
 typname |  oid
---------+-------
 oid     |    26
 lo      | 17230
(2 rows)

qe1=> create table testtable(col1 lo, col2 oid);
CREATE TABLE

qe1=> \d testtable
 Table "public.testtable"
 Column | Type | Modifiers
--------+------+-----------
 col1   | lo   |
 col2   | oid  |


== libpq program ==
#include <stdio.h>
#include <libpq-fe.h>

void fetchQuerySchema(PGconn* dbc)
{
    PGresult *res;
    char *colName;
    int colType, size, mod;

    printf("\n\nFetching Select Query Schema.....\n");

    res = PQexec(dbc, "select * from testtable");
    if (res == 0) {
        printf("!!!!! Error.\n");
    }

    for (int i = 0; i < PQnfields(res); ++i) {
        colName = PQfname(res, i);
        colType = PQftype(res, i);
        size = PQfsize(res, i);
        mod = PQfmod(res, i);

        printf("Schema for Column %d: \n", i+1);
        printf("\tName: %s\n\tType: %d\n\tSize: %d\n\tMod: %d\n\n",
                   colName, colType, size, mod);
    }

    PQclear(res);
}

int main()
{
    PGconn *dbc;

    dbc = PQconnectdb(
        "host = hostname user = user password = pass dbname = qe1");
    if(dbc == 0 || PQstatus(dbc) == CONNECTION_BAD) {
        printf("!!!!! Failed to establish connection.\n");
    }

    fetchQuerySchema(dbc);

    PQfinish(dbc);

    return 0;
}


=== Output on 8.2.3 ===
Fetching Select Query Schema.....
Schema for Column 1:
        Name: col1
        Type: 26
        Size: 4
        Mod: -1

Schema for Column 2:
        Name: col2
        Type: 26
        Size: 4
        Mod: -1

=== Output on 8.0.4 ===
Fetching Select Query Schema.....
Schema for Column 1:
        Name: col1
        Type: 17230
        Size: 4
        Mod: -1

Schema for Column 2:
        Name: col2
        Type: 26
        Size: 4
        Mod: -1


The 8.0.4 server correctly returns the Oid for lo column as the Oid of lo
type. The 8.2.3 server on the other hand returns Oid of oid type.

Thank you. Your help will be greatly appreciated.

pgsql-bugs by date:

Previous
From: Phil Frost
Date:
Subject: Re: Segfaults and assertion failures with not too extraordinary views and queries
Next
From: Tom Lane
Date:
Subject: Re: BUG #3015: libpq: PQftype() on a lo type result column returns Oid of type oid instead of Oid of type lo.