Reputation: 273
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 function
main':
ConexionPostgres.c:
(.text+0x86
): undefined reference to
setBD'
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);
}
Upvotes: 0
Views: 635
Reputation:
Typo. You call the function setBD()
, whereas the function defined is called setDB()
.
Upvotes: 3