Re: libpq/INSERT

From: "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net>
To: Andy Champion <andychampion(at)hotmail(dot)com>
Cc: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: libpq/INSERT
Date: 2001-04-24 16:21:12
Message-ID: Pine.LNX.4.30.0104241218010.20756-100000@chapelperilous.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On Tue, 24 Apr 2001, Andy Champion wrote:

> Hi, i'm trying to insert data pulled into a postgresql database but i'm
> having some problems with the inserts.
>
> i know that this:
> sprintf(insert_string, "INSERT INTO udpdata VALUES (1234);\n");
>
> is a valid statment, but how do i alter this so that instead of the 1234
> i insert the value of a variable?

int value = 1234;
sprintf(insert_string, "INSERT INTO udpdata VALUES(%d);\n", value);

Check the man page or the documentation for your C run-time libraries for
the sprintf-like functions (printf, sprintf, fprintf, etc) for information
on formatting rules.

-- Brett
http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
They are relatively good but absolutely terrible.
-- Alan Kay, commenting on Apollos

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message wsmuir 2001-04-24 18:52:09 SPI
Previous Message Oliver Elphick 2001-04-24 16:14:33 Re: libpq/INSERT