From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Anna Langer <anna_langer@hotmail.com>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [GENERAL] Problems with INSERT INTO?
Date: Mon, 24 May 1999 12:46:18 +0300
Message-ID: <l03130300b36ecf4b45e8@[147.233.159.109]> (raw)
In-Reply-To: <19990524092204.92750.qmail@hotmail.com>
At 12:22 +0300 on 24/05/1999, Anna Langer wrote:
> We are not really sure if this question is right for this mailinglist.
> We have some problem with INSERT INTO and we dont know how to solve it.We
> are writing it in a C-program. We are trying to get an integer from a file
> and put it into a database. And we are sure that we get a interger into our
> program.
The proper mailing list is the "interfaces" list, where I am redirecting
this post now.
> int a=500;
>
> PQexec(conn, "INSERT INTO octets VALUES(a)");
>
>
> But the program works when we do like this:
>
> PQexec(conn, "INSERT INTO octets VALUES(500)");
>
>
> It feels like we need to convert int a in some way, byt we dont know how. We
> are beginners with Postgresql.
This is less on the PostgreSQL side, and more on the C side. Just putting
"a" in a string doesn't tell C to pass the variable a. It just passes the
character "a", right?
What you have to do is pass the value of a as part of the command string.
So you have to make a string out of a. This is usually done with sprintf,
like this:
char command[1000];
int a=500;
sprintf( command, "INSERT INTO octets VALUES(%d)", a );
PQexec( conn, command );
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
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-interfaces@postgresql.org
Cc: herouth@oumail.openu.ac.il, anna_langer@hotmail.com
Subject: Re: [GENERAL] Problems with INSERT INTO?
In-Reply-To: <l03130300b36ecf4b45e8@[147.233.159.109]>
References: <19990524092204.92750.qmail@hotmail.com> <l03130300b36ecf4b45e8@[147.233.159.109]>
* 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