Regarding PQputline and PQendcopy - Mailing list pgsql-hackers
From | soni de |
---|---|
Subject | Regarding PQputline and PQendcopy |
Date | |
Msg-id | 9f2e40a90611282232g3edb0d6ds4f6d366c20d3de7f@mail.gmail.com Whole thread Raw |
Responses |
Re: Regarding PQputline and PQendcopy
|
List | pgsql-hackers |
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Hello,</span></font><pclass="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">We are using PQputline function for copying data todatabase</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial">Postgres version 7.2.4</span></font><p class="MsoNormal" style="MARGIN: 0in 0in0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Followingis the code snapshot:</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><spanstyle="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">We are taking data from one database, 100records at time and storing that records in string array "strArr" </span></font><p class="MsoNormal" style="MARGIN: 0in0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">After filling "strArr", we arepassing this string array to PQputline as follows:</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-tab-count:1"> </span>res = PQexec(conn, "COPY <tablename> from STDIN"); </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt;FONT-FAMILY: Arial">PQclear(res);</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">i = 0; </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial">while(true) {</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><spanstyle="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>status = PQputline(conn,strArr[i]);//contains one row of data </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>if(status!= 0) {</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><spanstyle="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>cout<<endl<<"Unableto send string: "<< strArr[i] <<endl; </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial"><span style="mso-spacerun: yes"> </span>if (status == EOF) {</span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-tab-count:1"> </span>cout<<endl<<"status is EOF"<<endl; </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial"><span style="mso-spacerun: yes"> </span>}</span></font><p class="MsoNormal" style="MARGIN: 0in 0in0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>}</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>i++;</span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial"><span style="mso-spacerun: yes"> </span>if(i > 100) {</span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun:yes"> </span>break;</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><span style="mso-spacerun: yes"> </span>}</span></font><pclass="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial">} </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.5in"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">status = PQputline(conn,</span></font><font face="TimesNew Roman"> </font><font face="Arial" size="2"> <span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">"\\.\n"); //terminator line</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"><font face="Arial" size="2"><spanstyle="FONT-SIZE: 10pt; FONT-FAMILY: Arial">status = PQendcopy(conn);<span style="mso-spacerun: yes"> </span></span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Sometime above codeworks fine but at sometime PQputline returns EOF and code goes in hang state for PQendcopy function. </span></font><pclass="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY:Arial">How to recognize, why PQputline sends EOF?</span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><fontface="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Please provide me some help regarding whataction must be taken when PQputline returns EOF or PQputline unable to send the line to server. </span></font><p class="MsoNormal"style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Alsohow to avoid the hang state of postgres server in PQendcopy function</span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </span></font><pclass="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE:10pt; FONT-FAMILY: Arial"> </span></font><p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Arial"size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Thanks,</span></font><p class="MsoNormal" style="MARGIN:0in 0in 0pt"><font face="Arial" size="2"><span style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Soni</span></font>
pgsql-hackers by date: