[Haskell] postgresql foreign function call segfaults

Edwin Eyan Moragas haaktu at gmail.com
Mon Feb 28 12:49:10 EST 2005


Hi Group,

i'm trying to complete an haskell pgsql interface.
all compiles well when using ghc's generated executable
but it segfaults when i do a pqexec.

-- PGresult *PQexec(PGconn *conn, const char *query);
foreign import ccall "libpq-fe.h PQexec"
    pqexec::X_PGconn->CString->IO X_PGresult

here's the offending code:

create conn=do
    putStrLn "creating table products"
    putStrLn ("\t"++screate)
    q<- newCString screate
    -- segmentation fault here!
    rs<- pqexec conn q
    stat<- pqcmdstatus rs
    stats<-peekCString stat
    putStrLn ("\tstatus is: "++ show stats)
    ra<- pqcmdtuples rs
    ras<-peekCString ra
    putStrLn ("\trows affected is: "++ show ras)

screate=
    "CREATE TABLE products ("
    ++  "product_no integer,"
    ++  "name text,"
    ++  "price numeric"
    ++")"

i'm using pgsql 7.4, gcc 3.3.4, ghc 6.2.2

i tried compiling with -fvia-C and it doesn't finish compiling.
i'm asking this question in the fear that i have done something wrong.

i have posted my code the code, makefile and generated .hc file here:
http://www.eyan.org/haskell/

-- 
kind regards,
eyan

http://www.eyan.org


More information about the Haskell mailing list