Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 696609FB282 for ; Thu, 23 Nov 2006 12:20:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 73845-05 for ; Thu, 23 Nov 2006 16:20:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from nihrelayxway2.hub.nih.gov (mailfwd.nih.gov [128.231.90.107]) by postgresql.org (Postfix) with ESMTP id 2AE149FBC2C for ; Thu, 23 Nov 2006 11:39:18 -0400 (AST) Received: from nhgri-01620512.nhgri.nih.gov (HELO [192.168.1.103]) ([156.40.148.18]) by nihrelayxway2.hub.nih.gov with ESMTP; 23 Nov 2006 10:39:17 -0500 X-IronPortListener: NIH_Relay X-SBRS: None X-IronPort-AV: i="4.09,452,1157342400"; d="scan'208"; a="226766831:sNHT34901914" Message-ID: <4565C0A7.5030904@mail.nih.gov> Date: Thu, 23 Nov 2006 10:39:19 -0500 From: Sean Davis User-Agent: Thunderbird 1.5.0.8 (Macintosh/20061025) MIME-Version: 1.0 To: Niels Laakmann CC: pgsql-interfaces@postgresql.org Subject: Re: ECPG and COPY FROM STDIN References: <20061120111317.9889D77A3B@mail.toxisch.net> <200611200642.23872.sdavis2@mail.nih.gov> <20061123135805.286DA77A78@mail.toxisch.net> In-Reply-To: <20061123135805.286DA77A78@mail.toxisch.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/11 X-Sequence-Number: 6326 Niels Laakmann wrote: > Am heiligen Mo, 20 November 2006 06:42:23 -0500 > schrieb Sean Davis : > > >> On Monday 20 November 2006 06:12, Niels Laakmann wrote: >> >>> Hey List! >>> I have to do a Benchmark-Test in C (ECPG) with and without network. >>> After reading the Performance and COPY Documentation (not correctly), I >>> wanted to Copy a File over the Network by using "COPY FROM 'filename'". >>> After some curious Problems I knew why. >>> Now I read some about "COPY FROM STDIN. But I didn't find an Example. >>> Can someone please give me an Example for that ? >>> >>> Or: >>> >>> Is there another command to insert many tuples from a Client to a >>> Server in an adequate time ? >>> >> How about here: >> >> http://www.postgresql.org/docs/8.1/interactive/libpq-copy.html >> > > At first thanks for this Tipp. I rewrite my Code to use Libpq now. But > the next Problem comes up: > > > char textbuffer[120]; > > result = PQexec(connect, "COPY branches (branchid, branchname, balance, > address) FROM STDIN WITH DELIMITER ',';"); > > if(PQresultStatus(result) != PGRES_COPY_IN) > shutdown_conn(1, connect); //my own error-handling > //function > > for(n=0; n < count_tupel; n++) { > sprintf(textbuffer, "%d,text1,0,text2", n); > if(PQputCopyData(connect, textbuffer, strlen(textbuffer) + 1) != 1) > shutdown_conn(1, connect); > } > PQputCopyEnd(connect, NULL); > PQgetResult(connect); > > > If count_tupel is 1, one Tupel is inserted to the relation. If > count_tupel is greater than 1. No Tupel is inserted and I got the > Error-Message: "extra data after last expected column". > What are we doing wrong ? - Is there something wrong as I discard the > buffer ? - A Null-Termination etc. ? > You need to have each line end in "\n"; the line needs to be a line, just like you would print to the screen. Sean