[Haskell-cafe] postgresql foreign function call segfaults

Edwin Eyan Moragas haaktu at gmail.com
Mon Feb 28 11:24:21 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 here:
http://www.eyan.org/haskell/Postgresql.hsc

the makefile i'm using is here:
http://www.eyan.org/haskell/Makefile

the generated hc file is here:
http://www.eyan.org/haskell/POstgresql.hc
-- 
kind regards,
eyan

http://www.eyan.org


More information about the Haskell-Cafe mailing list