in reply to AnyData and Column Names with Spaces

Thanks. I tried both of your suggestions, but no joy...

Here's the code sniplet:
my $dbh = DBI->connect( 'dbi:AnyData(RaiseError => 1):' ); $dbh->func( 'sms', 'Tab', $file, 'ad_catalog'); my $query = qq/select * from sms where "System Status" = '?'/; my $sth = $dbh->prepare( $query ); $sth->execute( 'ACTIVE' ); return $sth->fetchall_hashref( 'System Number' );
Here's the data sniplet:
System Number\tSystem Status\tSystem Duration 10001 \tACTIVE \t600 10002 \tINACTIVE \t0 10003 \tACTIVE \t900 ...

When I use just select * from rms, naturally, I get all the file's data (of which I am currently filtering later in my process).

However, it's interesting that with select * from rms, I'm able to use 'System Number' as a parameter in fetchall_hashref to retrieve all the data keyed on it, especially when it contains a space in its name.

Replies are listed 'Best First'.
Re^2: AnyData and Column Names with Spaces
by rehsack (Sexton) on Jun 03, 2010 at 18:23 UTC

    Sorry for late answer. General syntax for quoting identifiers in SQL is the double quote ("), so your statement should look like:

    $sql = q(select * from sms where "System Status" = 'foo');

    If you want use placeholders, ensure that they are not quoted:

    $sql = q(select * from sms where "System Status" = ?);

    Best source for help on DBD::AnyData, DBD::CSV and DBD::DBM would be the dbi-users@perl.org mailing list.