[PHP-DB] COPY with PostgreSQL

2004-10-22 Thread Robert Fitzpatrick
I am using COPY for PostgreSQL and having problems now that the incoming file contains 
more than approx 1500 lines. Is this an issue anyone is aware of? Lot's of files over 
1000 lines have worked fine, but after getting a file over 1800 I began having 
problems. I have broke the file down to a approx. 1500 line that works sometimes and 
not others. Here is a snippet of what I'm trying to do:

  $result = pg_exec($dbh, COPY tblxrf FROM stdin USING DELIMITERS ',');
  fseek($temp_fh,0); // go to beginning of temp file
  while (($csv_line = fgets($temp_fh,1024))) {
   pg_put_line($dbh, $csv_line);
  }
  $stat = pg_put_line($dbh, \\.\n); // notify db finished or report error
  if (!$stat) { echo ERROR: An error has occurred while putting last line of copy 
databr\n; exit; }
  $stat = pg_end_copy($dbh); // post (sync data) or report error

The process just hangs with the large number of lines, I have to kill the COPY process 
for postgresql on the server before trying again.

--
Robert

RE: [PHP-DB] COPY with PostgreSQL

2004-10-22 Thread Robert Fitzpatrick
On Fri, 2004-10-22 at 15:45, Norland, Martin wrote:
 What are the line endings of the file?  Maybe php is getting confused.
 How many KB is the file on disk when it's the ~1500 line version?
 There's length of each line (which you want under 1KB, probably not a
 problem unless you have BLOBS or equivalent) - and then there's how PHP
 determines what a line actually is.

Actually, I thought of line endings first. But after chopping the file
into pieces and getting all records to go in, ruled it out.

I finally, after trying many things have gotten this to work with the
large files. I found, if I issue a pg_connection_busy($dbh) before the
pg_put_line(...) in the while statement processing the lines of the temp
file handle, it works. Don't ask me why, that is what I'd like to know.
If I report back if busy is true, I get nothing. Maybe it is just giving
a millisecond to breathe or something while checking to see if the
connection is busy. But with that one line, all is well.

-- 
Robert

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php