Re: facing problem in accessing postgresql with c language normally - Mailing list pgadmin-support

From Bob McConnell
Subject Re: facing problem in accessing postgresql with c language normally
Date
Msg-id FF8482A96323694490C194BABEAC24A0074F2589@Email.cbord.com
Whole thread Raw
In response to facing problem in accessing postgresql with c language normally  (hatem gamal elzanaty <hatem@softpro.bz>)
List 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


pgadmin-support by date:

Previous
From: hatem gamal elzanaty
Date:
Subject: facing problem in accessing postgresql with c language normally
Next
From: r d
Date:
Subject: Pgadmin3 and Postgres 9.0.4 observation