Received: from mymail.ro (www.mymail.ro [193.231.233.154]) by postgresql.org (Postfix) with SMTP id 0EEB04763B6 for ; Thu, 4 Apr 2002 10:04:13 -0500 (EST) Received: (qmail 29694 invoked from network); 4 Apr 2002 15:04:15 -0000 Received: from ns.vodanet.ro (HELO mail.vodanet.ro) (qmailr@212.93.138.42) by mymail.ro with SMTP; 4 Apr 2002 15:04:15 -0000 Received: (qmail 4922 invoked from network); 4 Apr 2002 16:08:20 -0000 Received: from dark.gamecraft.ro (HELO there) (194.102.183.160) by mail.vodanet.ro with SMTP; 4 Apr 2002 16:08:20 -0000 Content-Type: text/plain; charset="iso-8859-1" From: Mihnea Balta To: pgsql-interfaces@postgresql.org Subject: Re: Getting "copy from" to work from a C++ program Date: Thu, 4 Apr 2002 18:10:26 +0300 X-Mailer: KMail [version 1.3.1] References: <3CABD1C3.8020606@mo.com> In-Reply-To: <3CABD1C3.8020606@mo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BannersAdded2: 2 Message-Id: <20020404150413.0EEB04763B6@postgresql.org> X-Archive-Number: 200204/8 X-Sequence-Number: 2550 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); }