Re: facing problem in accessing postgresql with c language normally

From: "Bob McConnell" <rvm(at)CBORD(dot)com>
To: "hatem gamal elzanaty" <hatem(at)softpro(dot)bz>, <pgadmin-support(at)postgresql(dot)org>
Subject: Re: facing problem in accessing postgresql with c language normally
Date: 2011-05-13 12:16:57
Message-ID: FF8482A96323694490C194BABEAC24A0074F2589@Email.cbord.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

From: hatem gamal elzanaty

> i'm new to postgresql programming in c language the
> following code give the following error beneath and
> no reason for
> that error :
> in consice the code i brought from the net and try to
> change it to test what happen
>
> psql_test.c
>
> /* append sql statement and insert record into employee table */
> void insert_employee_rec(PGconn *conn, char* fname, char* lname)
> {
> // Append the SQL statment
> char* sSQL;
> sprintf(sSQL, "insert into employee values ('%s', '%s');", fname
,
> lname );
>
> // Execute with sql statement
> PGresult *res = PQexec(conn, sSQL);
>
> if (PQresultStatus(res) != PGRES_COMMAND_OK)
> {
> printf("insert employee record failed");
> PQclear(res);
> close_conn(conn);
> }
> else
> {
> printf("insert employee record - OK\n");
> }
> //create_employee_table clear result
> PQclear(res);
> }

It looks like you need to spend some time learning how to write code in
C. You did not allocate any space for sSQL. Try changing that
declaration to

char sSQL[512];

Bob McConnell

In response to

Browse pgadmin-support by date

  From Date Subject
Next Message r d 2011-05-13 12:26:27 Pgadmin3 and Postgres 9.0.4 observation
Previous Message hatem gamal elzanaty 2011-05-12 20:58:21 facing problem in accessing postgresql with c language normally