Consider the following script:

  #!/usr/bin/perl 
  
  use strict;
  use warnings;
  use DBI;
  
  my $dbh = DBI->connect('dbi:mysql:music', 'user', 'pass');
  
  my $insert = $dbh->prepare_cached(qq{
    INSERT INTO user (username, password)
    VALUES (?, ?)
  });
  
  my $delete = $dbh->prepare_cached(qq{
    DELETE FROM user WHERE username = ?
  });
  
  $insert->execute('foo', 'nine');
  $insert->execute('bar', 9);
  
  $delete->execute('foo');
  $delete->execute('bar');
  
When I run this, everything is fine.

However, if I reverse the two 'insert' lines, so that the one with the 9
comes before the one with the 'nine', I get:

  DBD::mysql::st execute failed: Unknown column 'nine' in 'field list' at
   test-fail line 18.

I'm assuming that the first time the statement is executed something is
trying to work out whether the field is numeric or string, and seeing a
number, assumes it's numeric. But then, every future insert fails, with
a highly misleading error ...

Took me quite a while to realise this wasn't a Class::DBI / Ima::DBI
problem ...

Tony


Reply via email to