pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedProblems with INSERT INTO?
5+ messages / 4 participants
[nested] [flat]
* Problems with INSERT INTO?
@ 1999-05-24 02:22 Anna Langer <anna_langer@hotmail.com>
1999-05-24 09:46 ` Re: [GENERAL] Problems with INSERT INTO? Herouth Maoz <herouth@oumail.openu.ac.il>
1999-05-24 13:25 ` Re: [GENERAL] Problems with INSERT INTO? Simon Drabble <simond@foxlink.net>
0 siblings, 2 replies; 5+ messages in thread
From: Anna Langer @ 1999-05-24 02:22 UTC (permalink / raw)
To: pgsql-general@postgreSQL.org
Hi!
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.
When we created the table in the database we set the attribut to int4.
We get the problem when we trying to move the interger to the database.
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.
/Anna and Maria
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [GENERAL] Problems with INSERT INTO?
1999-05-24 02:22 Problems with INSERT INTO? Anna Langer <anna_langer@hotmail.com>
@ 1999-05-24 09:46 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1 sibling, 0 replies; 5+ messages in thread
From: Herouth Maoz @ 1999-05-24 09:46 UTC (permalink / raw)
To: Anna Langer <anna_langer@hotmail.com>; +Cc: pgsql-interfaces
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [GENERAL] Problems with INSERT INTO?
1999-05-24 02:22 Problems with INSERT INTO? Anna Langer <anna_langer@hotmail.com>
@ 1999-05-24 13:25 ` Simon Drabble <simond@foxlink.net>
1999-05-24 13:37 ` Re: [GENERAL] Problems with INSERT INTO? Simon Drabble <simond@foxlink.net>
1 sibling, 1 reply; 5+ messages in thread
From: Simon Drabble @ 1999-05-24 13:25 UTC (permalink / raw)
To: Anna Langer <anna_langer@hotmail.com>; +Cc: pgsql-general@postgreSQL.org
On Mon, 24 May 1999, Anna Langer wrote:
> Hi!
> 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.
>
> When we created the table in the database we set the attribut to int4.
> We get the problem when we trying to move the interger to the database.
>
> 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.
>
> /Anna and Maria
>
Do this:
PQexec(conn, "INSERT INTO octets VALUES(%d)", a);
and read up on C's printf family of functions.
Simon.
--
On October 7, 1998 the routine process of running anti-virus software on a
Windows NT server at the Boeing Corporation shut the system down. Evidently,
the software identified Windows NT itself as a virus and disabled it.
-- http://www.vcnet.com/bmc/departments/nt/bugs.shtml
Simon Drabble Somewhere in cyberspace
simond@foxlink.net
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [GENERAL] Problems with INSERT INTO?
1999-05-24 02:22 Problems with INSERT INTO? Anna Langer <anna_langer@hotmail.com>
1999-05-24 13:25 ` Re: [GENERAL] Problems with INSERT INTO? Simon Drabble <simond@foxlink.net>
@ 1999-05-24 13:37 ` Simon Drabble <simond@foxlink.net>
1999-05-24 17:34 ` Re: [GENERAL] Problems with INSERT INTO? Dustin Sallings <dustin@spy.net>
0 siblings, 1 reply; 5+ messages in thread
From: Simon Drabble @ 1999-05-24 13:37 UTC (permalink / raw)
To: Anna Langer <anna_langer@hotmail.com>; +Cc: pgsql-general@postgreSQL.org
On Mon, 24 May 1999, Simon Drabble wrote:
> On Mon, 24 May 1999, Anna Langer wrote:
>
> > When we created the table in the database we set the attribut to int4.
> > We get the problem when we trying to move the interger to the database.
> >
> > 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.
> >
> > /Anna and Maria
> >
>
> Do this:
>
> PQexec(conn, "INSERT INTO octets VALUES(%d)", a);
>
> and read up on C's printf family of functions.
>
>
> Simon.
>
*oops* heh-heh.
Do _this_:
char query[LOTS_OF_ROOM];
sprintf(query, "INSERT INTO octects VALUES(%d)", a);
PQexec(conn, query);
and read up etc..
-or- download my libpq wrapper, which allows you to perform queries without
using a temporary char array, in a manner similar to printf(). Available via
anon ftp from
brainkarma.dyndns.org/pub/dblib/
Note: it's very alpha right now and possibly quite messy as it's still under
development - works though :)
Simon.
--
On October 7, 1998 the routine process of running anti-virus software on a
Windows NT server at the Boeing Corporation shut the system down. Evidently,
the software identified Windows NT itself as a virus and disabled it.
-- http://www.vcnet.com/bmc/departments/nt/bugs.shtml
Simon Drabble Somewhere in cyberspace
simond@foxlink.net
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [GENERAL] Problems with INSERT INTO?
1999-05-24 02:22 Problems with INSERT INTO? Anna Langer <anna_langer@hotmail.com>
1999-05-24 13:25 ` Re: [GENERAL] Problems with INSERT INTO? Simon Drabble <simond@foxlink.net>
1999-05-24 13:37 ` Re: [GENERAL] Problems with INSERT INTO? Simon Drabble <simond@foxlink.net>
@ 1999-05-24 17:34 ` Dustin Sallings <dustin@spy.net>
0 siblings, 0 replies; 5+ messages in thread
From: Dustin Sallings @ 1999-05-24 17:34 UTC (permalink / raw)
To: Simon Drabble <simond@foxlink.net>; +Cc: Anna Langer <anna_langer@hotmail.com>; pgsql-general@postgreSQL.org
On Mon, 24 May 1999, Simon Drabble wrote:
# char query[LOTS_OF_ROOM];
# sprintf(query, "INSERT INTO octects VALUES(%d)", a);
#
# PQexec(conn, query);
snprintf would probably be a better choice.
# -or- download my libpq wrapper, which allows you to perform queries without
# using a temporary char array, in a manner similar to printf(). Available via
# anon ftp from
#
# brainkarma.dyndns.org/pub/dblib/
I was about to suggest something like this be part of the core
library. It makes a lot of sense, and that's what vsnprintf is for. :)
--
SA, beyond.com My girlfriend asked me which one I like better.
pub 1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin@spy.net>
| Key fingerprint = 87 02 57 08 02 D0 DA D6 C8 0F 3E 65 51 98 D8 BE
L_______________________ I hope the answer won't upset her. ____________
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~1999-05-24 17:34 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-05-24 02:22 Problems with INSERT INTO? Anna Langer <anna_langer@hotmail.com>
1999-05-24 09:46 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1999-05-24 13:25 ` Simon Drabble <simond@foxlink.net>
1999-05-24 13:37 ` Simon Drabble <simond@foxlink.net>
1999-05-24 17:34 ` Dustin Sallings <dustin@spy.net>
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