S_Shrum has asked for the wisdom of the Perl Monks concerning the following question:

I have a number (~25, all Pipe delimited) of flat-file databases that I use to store my site data in. I created a script to access the data and display the results but I have hit a strange impass.

For most of my databases, the script works great. However, when I attempt to do any queries such as a "Select *" or even if I specify a SELECT query with field names on , for example, the following file:

http://www.shrum.net/flying_sites.dat

I get the following msg in the server error log:

Execution ERROR: Can't use string ("CAN'T FIND COLUMN NAMES ON FIRST") as an ARRAY ref while "strict refs" in use at c:/Perl/site/lib/AnyData.pm line 126, <GEN0> line 2.

This can't be the *exact* problem as the first line of the database is the field names.

Out of all my flat-file databases, I am getting this error for about 5 of them. I can't figure it out. I am assuming that once I figure out the problem with one db, the rest *might* fall in line. I'm thinking that the problem may be in the formatting of CR/LF of the file itself (something I'm a bit ignorant about and don't know how to check). Any help would be apprechiated.

TIA

======================
Sean Shrum
http://www.shrum.net

  • Comment on DBI w/ AnyData...works except on a couple of files...

Replies are listed 'Best First'.
Re: DBI w/ AnyData...works except on a couple of files...
by princepawn (Parson) on Mar 01, 2002 at 21:23 UTC

      The mailbox no longer exists.

      Where else should I try? - TIA

      ======================
      Sean Shrum
      http://www.shrum.net

Re: DBI w/ AnyData...works except on a couple of files...
by S_Shrum (Pilgrim) on Mar 07, 2002 at 07:41 UTC

    I found the source after re-testing again (I could swear I tried this the first pass through...:-p Oh well).

    The problem was with the '/' char in the field name "AMA/FAI". Removing it solved the problem.

    Something to keep in mind...I do believe that there are other 'illegal' characters such as (I believe) single quotes and dash characters that will produce the same result if used in a field name so be careful with your field names people!

    Suprisingly, I found NOTHING directly about this via web search engines and in the archives of the various Perl forums I frequent. Hopefully someone will find it here.

    Ciaoness

    ======================
    Sean Shrum
    http://www.shrum.net

      Sorry I didn't see this earlier, I'm more likely to see things on comp.lang.perl.modules or dbi-users@perl.org. If you use the newest version of SQL::Statement with DBD::AnyData, it will catch those kinds of mistakes and warn you about them. It follows the SQL standard that names are composed of only alphanumerics and underscore and must start with an alphbetic character and be no longer than 128 characters and not be the same as a SQL reserved word. SQL Statement now allows quoted identfiers so characters like spaces and slashes are acceptable if used inside quotes. -- Jeff (author of the mods in question)
        I'm currently seeing problems with embedded newlines in CSV files.
        Eg. data like the following file
        C:\TEMP>cat events.csv
        UKEY,CITY,DATE,TIME,TITLE,LOCATION,TYPE
        unkey1,perth,27-mar-03,3:15,"guru
        god",office,1
        unkey2,Melb,12-mar-03,3:15,"at last, at home",home,1
        
        on code like
        my $sth = $dbh->prepare("SELECT location, title FROM things"); $sth->execute(); while (my $row = $sth->fetch) {print "@$row\n"; }

        Version information

        • DBD::Anydata 0.05
        • SQL::Statement 1.005
        • Perl v5.6.1 built for MSWin32-x86-multi-thread
Re: DBI w/ AnyData...works except on a couple of files...
by rinceWind (Monsignor) on Feb 27, 2002 at 11:50 UTC