Re: dump_results

2006-04-18 Thread Tim Bunce
On Thu, Apr 13, 2006 at 03:22:19PM -0700, Loo, Peter # PHX wrote:
 Hi,
  
 I am passing the correct arguments to dump_results, but it appears that
 the records are not getting separated with new line.
  
 $maxlen = 500;
 $lsep = '\n';
 $fsep = '|';
 $fh = \*FH;
  
 $rows = $sth-dump_results($maxlen, $lsep, $fsep, $fh);

 Also, how can I force it so that the output does not have the quotes for
 every field?

Don't use dump_results() for this. The docs say:

Since it uses L/neat_list to format and edit the string for reading by
humans, it is not recomended for data transfer applications.

Tim.


RE: dump_results

2006-04-14 Thread Ronald J Kimball
Loo, Peter # PHX [mailto:[EMAIL PROTECTED]:

 I am passing the correct arguments to dump_results, but it appears that
 the records are not getting separated with new line.
 
 $maxlen = 500;
 $lsep = '\n';
 $fsep = '|';
 $fh = \*FH;
 
 $rows = $sth-dump_results($maxlen, $lsep, $fsep, $fh);

Single quoted strings do not do backslash substitution (except for \\ and
\').  You meant $lsep = \n;


 Also, how can I force it so that the output does not have the quotes for
 every field?

DBI::neat() won't quote the value if it knows it's a number.  Unfortunately,
I'm not sure how to let it know it's a number in this case.  Sorry.


Ronald




RE: dump_results

2006-04-14 Thread Loo, Peter # PHX

Thanks Ronald.
 
Peter Loo
Wolters Kluwer Health
(602) 381-9553

-Original Message-
From: Ronald J Kimball [mailto:[EMAIL PROTECTED] 
Sent: Friday, April 14, 2006 6:51 AM
To: Loo, Peter # PHX; dbi-users@perl.org
Subject: RE: dump_results

Loo, Peter # PHX [mailto:[EMAIL PROTECTED]:

 I am passing the correct arguments to dump_results, but it appears 
 that the records are not getting separated with new line.
 
 $maxlen = 500;
 $lsep = '\n';
 $fsep = '|';
 $fh = \*FH;
 
 $rows = $sth-dump_results($maxlen, $lsep, $fsep, $fh);

Single quoted strings do not do backslash substitution (except for \\
and \').  You meant $lsep = \n;


 Also, how can I force it so that the output does not have the quotes 
 for every field?

DBI::neat() won't quote the value if it knows it's a number.
Unfortunately, I'm not sure how to let it know it's a number in this
case.  Sorry.


Ronald




This E-mail message is for the sole use of the intended recipient(s) and
may contain confidential and privileged information.  Any unauthorized
review, use, disclosure or distribution is prohibited.  If you are not
the intended recipient, please contact the sender by reply E-mail, and
destroy all copies of the original message.


This E-mail message is for the sole use of the intended recipient(s) and may 
contain confidential and privileged information.  Any unauthorized review, use, 
disclosure or distribution is prohibited.  If you are not the intended 
recipient, please contact the sender by reply E-mail, and destroy all copies of 
the original message.


Re: dump_results

2006-04-14 Thread Jeffrey Seger



 Single quoted strings do not do backslash substitution (except for \\
 and \').  You meant $lsep = \n;


  Also, how can I force it so that the output does not have the quotes
  for every field?

 DBI::neat() won't quote the value if it knows it's a number.
 Unfortunately, I'm not sure how to let it know it's a number in this
 case.  Sorry.



I'm guessing that this is happening when you hit a an empty string that you
are trying to insert into a numeric field.  Convert empty strings in @row
into undef and it should work.

foreach my $i (0..$#row){$row[$i] = undef if $row[$i] eq ''}

The only drawback to this is if you actually want empty strings in your
character fields instead of nulls.



--
--
The darkest places in hell are reserved for those who maintain their
neutrality in times of moral crisis.
Dante Alighieri (1265 - 1321)

They who would give up an essential liberty for temporary security, deserve
neither liberty or security.
Benjamin Franklin

Our lives begin to end the day we become silent about things that matter.
Martin Luther King

Our government can't be bought.  The oil companies will never give it up at
any price.
My opinion
--


Re: dump_results

2006-04-14 Thread Peter Loo
Hi Jeffrey,

But why does this work when I select the rows into memory and insert
them to the same table?  I must be missing something.

Thanks.

Peter

--- Jeffrey Seger [EMAIL PROTECTED] wrote:

 
 
 
  Single quoted strings do not do backslash substitution (except for
 \\
  and \').  You meant $lsep = \n;
 
 
   Also, how can I force it so that the output does not have the
 quotes
   for every field?
 
  DBI::neat() won't quote the value if it knows it's a number.
  Unfortunately, I'm not sure how to let it know it's a number in
 this
  case.  Sorry.
 
 
 
 I'm guessing that this is happening when you hit a an empty string
 that you
 are trying to insert into a numeric field.  Convert empty strings in
 @row
 into undef and it should work.
 
 foreach my $i (0..$#row){$row[$i] = undef if $row[$i] eq ''}
 
 The only drawback to this is if you actually want empty strings in
 your
 character fields instead of nulls.
 
 
 
 --

--
 The darkest places in hell are reserved for those who maintain their
 neutrality in times of moral crisis.
 Dante Alighieri (1265 - 1321)
 
 They who would give up an essential liberty for temporary security,
 deserve
 neither liberty or security.
 Benjamin Franklin
 
 Our lives begin to end the day we become silent about things that
 matter.
 Martin Luther King
 
 Our government can't be bought.  The oil companies will never give it
 up at
 any price.
 My opinion

--
 


Peter Loo
Worldwide Consulting, Inc.
Phoenix, Arizona
U.S.A.


Re: dump_results() format

2002-01-08 Thread Tim Bunce

On Tue, Jan 08, 2002 at 10:12:37AM -0600, Nguyen, David M wrote:
 Hi all,
 
 I use DBI and dump_results() to allow users access database and download
 data to view in CSV format. My question is how do I setup dump_results() to
 point the a file to .CSV extension?

The docs say:

=item Cdump_results
 
  $rows = $sth-dump_results($maxlen, $lsep, $fsep, $fh);
 
Fetches all the rows from C$sth, calls CDBI::neat_list for each row, and
prints the results to C$fh (defaults to CSTDOUT) separated by C$lsep
(default C\n). C$fsep defaults to C,  and C$maxlen defaults to 35.
 
This method is designed as a handy utility for prototyping and
testing queries. Since it uses L/neat_list to
format and edit the string for reading by humans, it is not recomended
for data transfer applications.

So do

open(FH, foo.csv) or die ... $!;
$sth-dump_results($maxlen, $lsep, $fsep, \*FH);

Tim.