pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mariano Reingart <mariano@nsis.com.ar>
To: pgsql-interfaces@postgresql.org
Subject: LibPqEasy, binary cursor, x86-64, fetch(int4) problem?
Date: Sat, 11 Feb 2006 20:28:25 -0300
Message-ID: <000301c62f62$dbd72b90$0300000a@PC1> (raw)

Hi, I recently moved a simple application from a 32bit Intel to a new AMD64 
server (migrated from Postgres 7.2 to 8.1.2 and LibPqEasy 3.0.4), running 
Slamd64 (Slackware port to the AMD64). Everything compiled just fine but the 
applicattion didn't work as expected.
When I look into the tables (with psql) I see strange values in int4 columns 
like ( 16777216, 402653184, 1124073472, ...) instead of normal ones (1, 24, 
67)
Looking at application logs I found that libpqeasy is returning bad values 
in fetch( &int4 ) functions.
Thinking that my code is wrong, I run pginsert example from libpgeasy and it 
didn't work either.
Using text cursors (not binary) and atoi() solved the problem.

Here is a sample code to reproduce the bug, adapted from 
/libpgeasy-3.0.4/examples/pginsert.c:

#include <stdio.h>
#include <unistd.h>
#include "libpq-fe.h"
#include "libpgeasy.h"

int main(void) {
    int aint;
    char astring[1024];

    connectdb("dbname=fichadas");
    on_error_stop();


    doquery("BEGIN WORK");
    doquery("CREATE TABLE testfetch(aint int4)");
    doquery("INSERT INTO testfetch (aint) VALUES ( 1 )");


    /* this will print a strange number like 16777216 instead of 1: */

    doquery("DECLARE c_testfetch BINARY CURSOR FOR SELECT aint FROM 
testfetch WHERE aint=1");
    doquery("FETCH ALL IN c_testfetch");

    fetch(&aint);
    printf("aint=%d\n",aint);


    /* this will print a correct value: */

    doquery("DECLARE c2_testfetch CURSOR FOR SELECT aint FROM testfetch 
WHERE aint=1");
    doquery("FETCH ALL IN c2_testfetch");

    fetch(astring);
    printf("atoi(astring)=%d\n",atoi(astring));

    return 0;
}

/* ------------------------------- */

gcc -o test1 test1.c -lpgeasy

Output:

aint=16777216
atoi(astring)=1

Hope this helps,
Regards,
Mariano Reingart 




view thread (3+ messages)  latest in thread

Message-ID: <000301c62f62$dbd72b90$0300000a@PC1>
Permalink:  ../000301c62f62$dbd72b90$0300000a@PC1/
Also on:    postgresql.org/message-id/000301c62f62$dbd72b90$0300000a@PC1

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: mariano@nsis.com.ar
  Subject: Re: LibPqEasy, binary cursor, x86-64, fetch(int4) problem?
  In-Reply-To: <000301c62f62$dbd72b90$0300000a@PC1>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox