Hi Prakash,

You wrote:

$dbh->do(UPDATE ...) is not working as per the recommended syntax.
The query returns a 0 (undef?) for the line: $dbh->do("UPDATE info SET Owner
= 'me' WHERE SerialNumber = '1234") or die "update: " . $dbh->errstr();


I suggest you turn on RaiseError in your connect statement and omit all of your "or die" statements since some are misapplied. Read the DBI docs on RaiseError and also on the return value for do() - there are several reasons a do("UPDATE..") would not return a true value. Also, you are missing a quote mark around the first occurrence of 1234, you can avoid that kind of error by reading about placeholders in the DBI docs.

Please remove me from the cc list. I don't mind answering questions on dbi-users and perlmonks when I have time, but my mailbox is not a good place to send general DBI and script debugging questions. Thanks and good luck.

--
Jeff

Prakash Prabhakar wrote:
$dbh->do(UPDATE ...) is not working as per the recommended syntax.
The query returns a 0 (undef?) for the line: $dbh->do("UPDATE info SET Owner
= 'me' WHERE SerialNumber = '1234") or die "update: " . $dbh->errstr();

Is there anything that I am missing?
------------------------------------------------------------
*Full code:*
use DBI;
 $dbh = DBI->connect("DBI:CSV:")
  or die "Cannot connect: " . $DBI::errstr;
 $dbh->{'csv_tables'}->{'info'} = { 'file' => 'test.csv', 'eol'  => "\n"};
 $sth = $dbh->prepare("SELECT * FROM info WHERE SerialNumber =
'$serialnum'")
  or die "prepare: " . $dbh->errstr();
 $sth->execute()
  or die "execute: " . $dbh->errstr();

 while (my $row = $sth->fetchrow_hashref)
 {
      print("Found result row: Equipment = ", $row->{'Equipment'},",Serial
Number = ", $row->{'SerialNumber'});
 }

 $sth->finish();
 $ret = $dbh->do("UPDATE info SET Owner = 'me' WHERE SerialNumber = '1234")
   or die "update: " . $dbh->errstr();
 print "update returned $ret";
--------------------------------------

$ret always has value 0E0.




On 6/2/08, Prakash Prabhakar <[EMAIL PROTECTED]> wrote:
Jeff, All,

Thank you very much for that information. My code's working now.

Regards,
Prakash


 On 6/1/08, Jeff Zucker <[EMAIL PROTECTED]> wrote:
ReneeB wrote:

Why do you use the Windows line endings as the default? Why not the value
of $/?

Because 1) the module was already several years old and widely used when
I inherited it and I didn't want to break backward compatability 2) Because,
I think using $/ would be a disaster since you'd never be able to depend on
consistency within the program since you wouldn't know where or by what that
had been set and 3) if we have to make either people who access *nix files
or people who access winodws files do something that takes a tiny bit of
smarts (like knowing what the line endings are in a file), better depend on
the *nix people to figure it out :-).  Now that Ubuntu etc. have opened up
the field that's less true than it used to be but eight or ten years ago
when I made the decision, it seemed like the right one.  I'm afraid I still
don't see a reason to change it.

--
Jeff

See also https://rt.cpan.org/Public/Bug/Display.html?id=20340
Try adding this :
  $dbh->{'csv_tables'}->{'info'} = {
      'file' => 'testtable.csv',
      'eol'  => "\n"
  };

Be sure to use double quotes qround the \n.  If that doesn't work try a
line ending specific to your OS (e.g. '\012' for *nix).


Cheers,
Renee




Reply via email to