0

Making a header to connect to PostgreSQL database I'm encapsulating libpq functions into functions of my own but, in one of them, which supposedly returns a pointer of type PGconn I get an error of the type...

ConexionPostgres.c:32:6: aviso: la asignación crea un puntero desde un entero sin una conversión [activado por defecto] /tmp/ccCeaewL.o: In functionmain': ConexionPostgres.c:(.text+0x86): undefined reference tosetBD'

I thought it was because of the prototype so I changed the proto and put the definition directly before main but nothing...Could someone tell what's going on?

I'm checking Postgres libpq documentation and libpq-fe.h directly to see the proto's so I'm not missing anything but I've confused. Here's my code:

PGconn *setDB(char *conninfo)
{
    PGconn *db;
    db = PQconnectdb(conninfo);

    if(!db)
          printf("Error en conexion a la BD");

    if(PQstatus(db) != CONNECTION_OK)
    {
      printf( "%s\n", PQerrorMessage(db));
    }
    else
    {
        return db;
    }

}

int main()
{

      const char *conninfo = "dbname='database' host='somehost' user='me' password='somepass'";
    //char *query = "INSERT INTO productos VALUES ('1','5','235')";

    PGconn *con;
    con = setBD(conninfo); /* --> Here's apparently the problem */  

    PQfinish(con);
    exit(0);

}
2
  • Do you link against the postgre-libraries? Commented Apr 4, 2013 at 8:57
  • Yep, and works fine without that line... Commented Apr 4, 2013 at 15:25

1 Answer 1

3

Typo. You call the function setBD(), whereas the function defined is called setDB().

Sign up to request clarification or add additional context in comments.

1 Comment

Oh Man! Programming that late not's good for my eyes! ; I checked and rechecked my code but couldn't find the error, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.