Обсуждение: libpq/INSERT

Поиск
Список
Период
Сортировка

libpq/INSERT

От
"Andy Champion"
Дата:
<div><div>Hi, i'm trying to insert data pulled into a postgresql database but i'm having some problems with the
inserts.</div><div> </div><div>iknow that this:<br />sprintf(insert_string, "INSERT INTO udpdata VALUES
(1234);\n");</div><div> </div><div>isa valid statment, but how do i alter this so that instead of the 1234 i insert the
valueof a variable?</div><div> </div><div>thanks</div></div><br clear="all" /><hr />Get Your Private, Free E-mail from
MSNHotmail at <a href="http://www.hotmail.com">http://www.hotmail.com</a>.<br /> 

Re: libpq/INSERT

От
liam
Дата:
At 3:31 PM +0000 4/24/01, 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");
>

i= 1234 ;
sprintf (insert_string, "INSERT INTO updata VALUES(%i);\n",i) ;


it's just plain old ordinary ansi c.
-- 
Later . . . 'liam

allenwc@home.com
William C Allen, BLS, EET

"It may be that your sole purpose in life is to serve as a warning to others"
At least I /have/ a purpose!


Re: libpq/INSERT

От
"Oliver Elphick"
Дата:
"Andy Champion" wrote: ><html><DIV>

Please turn off html mode in your mailer.
 >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
doi alter this so that instead of the 123     >4 i insert the value of a variable? 
 
It sounds as though you need a basic course in C programming.

sprintf(insert_string, "INSERT INTO udpdata VALUES (%s);\n", string_variable);
sprintf(insert_string, "INSERT INTO udpdata VALUES (%d);\n", integer_variable);

You could find this out by reading the manual for sprintf...

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
========================================   "Now unto him that is able to do exceeding abundantly      above all that we
askor think, according to the power     that worketh in us, Unto him be glory in the church by     Christ Jesus
throughoutall ages, world without end.      Amen."          Ephesians 3:20,21 
 




Re: libpq/INSERT

От
"Brett W. McCoy"
Дата:
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