in reply to Tie::DBI question

I don't know how Tie::DBI handles quoting, but I'll assume it does. I don't see anything immediately wrong, so I would try an insert with the normal DBI module:
use POSIX qw(strftime); my $now_string = strftime "%Y-%m-%d %H:%M:%S", localtime; use DBI; my $dbh = DBI->connect('DBI:mysql:foothills', 'root', '') or die; my $sth = $dbh->prepare("INSERT INTO users values('test', 'test', 1, 1 +, 1, 1, ?)"); $sth->execute($now_string); $dbh->disconnect();
You may want to make better fake values than I've used -- I just created a new table with a single datetime column.

If that insert works, the problem's probably somewhere in Tie::DBI. Yuck.

Update: The problem *is* in Tie::DBI, specifically within the _fields() method. It checks the allowed column names from the database, then issues the statement:

my %fields = map { lc($_)=>1 } @{$sth->{NAME}};

The lc there is the trouble.

If you add WARN => 1 to the tie statement, you'll get a warning about an unknown field named 'dateCreated' in the initialization line.

The solution is either to remove the lc() from Tie::DBI, or to use lowercase keys in the anonymous hash. Perhaps some databases don't support mixed case in field names, so Dr. Stein thought he would be safer than sorry.

Replies are listed 'Best First'.
Re: Re: Tie::DBI question
by tmbg (Novice) on May 07, 2001 at 06:05 UTC
    It works fine with inserts from either the mysql shell or bits of DBI code like above, but it doesn't work at all from Tie::DBI no matter how I quote it. This is driving me insane. I know I can break down and do it using the standard DBI stuff, but I really want it to work with Tie::DBI.