pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Miguel Carvalho <miguel@ipatimup.pt>
To: pgsql-php@postgresql.org
Subject: Re: libpq interfacing
Date: Tue, 5 Mar 2002 14:58:42 -0000 (WET)
Message-ID: <11436.195.23.103.182.1015340322.squirrel@www.ipatimup.pt> (raw)
In-Reply-To: <Pine.BSO.4.21.0203050936510.18942-100000@library.iisc.ernet.in>
References: <Pine.BSO.4.21.0203050936510.18942-100000@library.iisc.ernet.in>

> hello,
>      i am accessing a postgresql table using libpq interface ( i.e. c
> program) i am opening a text file and reading contents and trying to
> insert the same to postgresql table. suppose i read some string
> like"computer" from file and stored in a variable key. no i want to
> write the content of key to table i.e using insert command.


Use something like is:
char buffer[1024];
//char_pointer_for_field1 AND  char_pointer_for_field2 are char*
//type variables

 buffer = sprintf("INSERT INTO TABLE(field1,field2) VALUES('%s','%s'),
                char_pointer_for_field1, char_pointer_for_field2
          );

NOTE: You may have to use a bigger buffer string. This depends on the
length of variables char_pointer_for_field1 and char_pointer_for_field2.
If for some reason the buffer space reserved is smaller, it means that the
previous sprinf instaruction will *corrupt* other SO memory...and you will
notice an error like: Segmentation fault.






view thread (2+ messages)

Message-ID: <11436.195.23.103.182.1015340322.squirrel@www.ipatimup.pt>
Permalink:  ../11436.195.23.103.182.1015340322.squirrel@www.ipatimup.pt/
Also on:    postgresql.org/message-id/11436.195.23.103.182.1015340322.squirrel@www.ipatimup.pt

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: miguel@ipatimup.pt
  Subject: Re: libpq interfacing
  In-Reply-To: <11436.195.23.103.182.1015340322.squirrel@www.ipatimup.pt>
  References: <Pine.BSO.4.21.0203050936510.18942-100000@library.iisc.ernet.in> <11436.195.23.103.182.1015340322.squirrel@www.ipatimup.pt>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox