Re: memory leak while trying to update/alter column in postgresql
От | Michael Paquier |
---|---|
Тема | Re: memory leak while trying to update/alter column in postgresql |
Дата | |
Msg-id | CAB7nPqQ6W5ZiyD8cibTXLWmx3e3j5+A-5s8noeQTSCpixF2hjQ@mail.gmail.com обсуждение исходный текст |
Ответ на | memory leak while trying to update/alter column in postgresql (Madhurima Das <madhurima.das@gmail.com>) |
Список | pgsql-general |
On Sat, Jul 5, 2014 at 11:06 AM, Madhurima Das <madhurima.das@gmail.com> wrote: > int main() > { > PGconn *conn; > PGresult *res; > int i=0,nFields=0,row=0,col=0; > > conn = PQconnectdb("dbname=test1 host=localhost user=postgres > password=yyy"); > if(PQstatus(conn) == CONNECTION_BAD) > { > fprintf(stderr, "Connection to database \"%s\" failed.\n", > PQerrorMessage(conn)); > fprintf(stderr, "%s", PQerrorMessage(conn)); > exit_nicely(conn); > } > > res = PQexec(conn, "IF COL_LENGTH('xxx','comment') IS NULL"); Call to PQclear is missing here or before the next call to PQexec. > if(res) > res = PQexec(conn, "ALTER TABLE xxx ADD comment VARCHAR(500)"); > else > res = PQexec(conn, "UPDATE TABLE xxx ADD comment VARCHAR(500)"); Same here. > res = PQexec(conn, "IF COL_LENGTH('xxx','id') IS NULL"); Same here. > if(res) > res = PQexec(conn, "ALTER TABLE xxx ADD id VARCHAR(50)"); > else > res = PQexec(conn, "UPDATE TABLE xxx ADD id VARCHAR(50)"); Same here. > res = PQexec(conn, "SELECT * FROM xxx"); > if((!res) || (PQresultStatus(res) != PGRES_TUPLES_OK)) > { > fprintf(stderr, "SELECT command did not return tuples properly\n"); > PQclear(res); > } > > PQclear(res); > PQfinish(conn); > > return 0; > } Btw, there is a lot of code duplication... -- Michael
В списке pgsql-general по дате отправления: