Thread: libpq++: trouble getting "copy table from" to work...

libpq++: trouble getting "copy table from" to work...

From
Carlos Moreno
Date:
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.  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.

I even tried creating a temporary file and then using
copy from 'filename' -- but I get an error message saying
that I need superuser access to be allowed to copy from
and to regular files...

Help?!!  :-(


Thanks,

Carlos
-- 





Re: libpq++: trouble getting "copy table from" to work...

From
jtv
Date:
On Thu, Apr 04, 2002 at 01:57:33AM -0500, Carlos Moreno wrote:
> 
> PgDatabase db(" ..... ");
> db.Exec ("copy deleteme from stdin\n1\tName1\n2\tName2");
There are separate calls to actually feed the data to the backend through
stdin.  Unfortunately, these calls are in libpq, and libpq++ does not
expose them so you can't access them without going "underneath" and
coding to the C API.

#include <stdplug>

...

May I suggest checking out libpqxx, an alternative to libpq++ that does
expose 'copy from stdin'?  It's at
 http://members.ams.chello.nl/j.vermeulen31/proj-libpqxx.html

The stuff you're looking for is in the TableWriter class.


Jeroen



Re: libpq++: trouble getting "copy table from" to work...

From
Carlos Moreno
Date:
Thanks for your reply, Jeroen,

>May I suggest checking out libpqxx, an alternative to libpq++ that does
>expose 'copy from stdin'?  It's at
>
>  http://members.ams.chello.nl/j.vermeulen31/proj-libpqxx.html
>
>The stuff you're looking for is in the TableWriter class.
>
Hmmm...  I've been *very* tempted to check out this library,
but have been too busy with a project that is already using
libpq++  (not that it is excessively long, but still, changing
everything scares me, mainly because I'm already overflowed
with the tasks that were due yesterday!  :-( )

One always wonders...  Is it more the time that I'm going to
spend learning/understanding this new library and translating
all the code to it?  Or will I end up hating myself and wishing
I had decided to go with this new library when I keep hitting
walls here and there?  (the reluctance to switch is even higher
when you are in the middle of urgent "repairs" to an already
functional system...)

BTW, I didn't find any links to the documentation from the
link you gave me...  I recall you mentioning some docs that
were available.  Could you send me a pointer to it?

Thanks!

Carlos
--





Re: libpq++: trouble getting "copy table from" to work...

From
jtv
Date:
On Thu, Apr 04, 2002 at 04:24:41AM -0500, Carlos Moreno wrote:
>
> Hmmm...  I've been *very* tempted to check out this library,
> but have been too busy with a project that is already using
> libpq++  (not that it is excessively long, but still, changing
> everything scares me, mainly because I'm already overflowed
> with the tasks that were due yesterday!  :-( )
One thing I guess it depends on is the C++ "dialect" you're using.  If
you're using C++ as the proverbial "a better C," then libpqxx is not
for you.  But if the existing code deals with and uses exceptions and
such, libpqxx should make your life a lot easier.  No more checking
for errors in return values, no more manual conversion of fields to
integers, no more GetValue().

Perhaps (when I've got time--the weather's too good now!) I should
put together some examples of converting code from libpq++ to libpqxx.


> BTW, I didn't find any links to the documentation from the
> link you gave me...  I recall you mentioning some docs that
> were available.  Could you send me a pointer to it?

They're in the archive.  I'll put them up separately as well.


Jeroen