pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Getting "copy from" to work from a C++ program
2+ messages / 2 participants
[nested] [flat]

* Getting "copy from" to work from a C++ program
@ 2002-04-04 04:08 Carlos Moreno <moreno_at_mochima_dot_com@mo.com>
  2002-04-04 15:10 ` Re: Getting "copy from" to work from a C++ program Mihnea Balta <dark@dark.vodanet.ro>
  0 siblings, 1 reply; 2+ messages in thread

From: Carlos Moreno @ 2002-04-04 04:08 UTC (permalink / raw)
  To: pgsql-interfaces


Hi,

I'm trying to insert several records into a table in one shot
(from a C++ program, that is).

All my attempts to use "copy from" have failed  (well, I
haven't tried copying from an actual file, since I have
the data in memory, and I'd like to avoid the overhead
to write it to a file first).  Is it possible??  I've
tried things like:

PgDatabase db(" ..... ");
db.Exec ("copy deleteme from stdin\n1\tName1\n2\tName2");

And similar things  (with a ; after stdin, with a \n. or
\n\\. at the end of the string -- they all fail with an
ErrorMessage() indicating a syntax error in the statement.

Help?!!  :-(

Will it be necessary that I dump the data into a temporary
file and then do copy deleteme from tmpfile.txt ??

Thanks,

Carlos
--





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Getting "copy from" to work from a C++ program
  2002-04-04 04:08 Getting "copy from" to work from a C++ program Carlos Moreno <moreno_at_mochima_dot_com@mo.com>
@ 2002-04-04 15:10 ` Mihnea Balta <dark@dark.vodanet.ro>
  0 siblings, 0 replies; 2+ messages in thread

From: Mihnea Balta @ 2002-04-04 15:10 UTC (permalink / raw)
  To: pgsql-interfaces

On Thursday 04 April 2002 07:08, you wrote:
> Hi,
>
> I'm trying to insert several records into a table in one shot
> (from a C++ program, that is).
>
> All my attempts to use "copy from" have failed  (well, I
> haven't tried copying from an actual file, since I have
> the data in memory, and I'd like to avoid the overhead
> to write it to a file first).  Is it possible??  I've
> tried things like:
>
> PgDatabase db(" ..... ");
> db.Exec ("copy deleteme from stdin\n1\tName1\n2\tName2");

I use this (libpq, not libpq++, but you'll get it):

void dbcon::copy(char* table, char* buf){
        char copy_qry[256];

        snprintf(copy_qry, 256, "copy %s from stdin", table);
        PQexec(conn, copy_qry);
        PQputline(conn, buf);
        PQputline(conn, "\\.\n");
        PQendcopy(conn);
}




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-04-04 15:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-04 04:08 Getting "copy from" to work from a C++ program Carlos Moreno <moreno_at_mochima_dot_com@mo.com>
2002-04-04 15:10 ` Mihnea Balta <dark@dark.vodanet.ro>

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