Skip site navigation (1) Skip section navigation (2)

Re: Getting "copy from" to work from a C++ program

From: Mihnea Balta <dark(at)dark(dot)vodanet(dot)ro>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Getting "copy from" to work from a C++ program
Date: 2002-04-04 15:10:26
Message-ID: 20020404150413.0EEB04763B6@postgresql.org (view raw or flat)
Thread:
Lists: 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);
}


In response to

pgsql-interfaces by date

Next:From: jtvDate: 2002-04-04 16:54:53
Subject: Re: libpq++: trouble getting "copy table from" to work...
Previous:From: Carlos MorenoDate: 2002-04-04 09:24:41
Subject: Re: libpq++: trouble getting "copy table from" to work...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group