Hi, i am testing PostgreSQL and have already run into questions...
Can someone explain why i don´t get a error message the second time i
run this program saying "TABLE slask ALREADY EXISTS", instead i get
"Segmentation fault (core dumped)"
Thanks !
/Stefan
#include <stdio.h>
#include "libpq-fe.h"
void exit_nicely(PGconn* conn)
{
PQfinish(conn);
exit(1);
}
main()
{
char *pghost, *pgport, *pgoptions, *pgtty;
char* dbName;
PGconn* conn;
PGresult* res;
pghost = NULL;
pgport = NULL;
pgoptions = NULL;
pgtty = NULL;
dbName = "test";
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr,"%s",PQerrorMessage(conn));
exit_nicely(conn);
}
// create the table
res = PQexec(conn, "CREATE TABLE slask(name char(20), phone
char(10))");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr,"CREATE TABLE slask failed !");
PQclear(res);
exit_nicely(conn);
}
PQclear(res);
PQfinish(conn);
}