in reply to Long file names in .dbf databases

Let's look at how the XBase database(s) work internally to store data first.

In a given XBase database, each database table is stored in a file of the corresponding name. For example, the table USER whould have been stored as USER.dbf.

When you construct an SQL to query data inside USER, you would do something like this:
$dbname = "USER"; $sql = "select USERNAME from $dbname";
And this should work fine.

Now what happens if you have spaces in the filenames, say, "User Names Database.dbf" on windows, which is valid, the SQL query becomes:
$dbname = "User Names Database"; $sql = "select USERNAME from $dbname";
And of cause it will not work, because the SQL string becomes
select USERNAME from User Names Database
which is an invalid SQL statement.

I haven't tried this, but to resolve the long name issue on Windows boxes, you could patch the database names by adding single quotes around it:
$dbname = "User Names Database"; $tblname = "'" . $dbname . "'"; # or $tblname = '"' . $dbname . '"'; $sql = "select USERNAME from $tblname";
And this should work because the new SQL string becomes
select USERNAME from 'User Names Database'
I think this might resolve the long filename issue on Windows machines.

Update: Ok, I tried my solution, but it didn't work on my Sybase database. It's more of a database implementation issue. **blush**

Try it anyway to see if it works or not. Otherwise the quick solution is to change spaces in the filenames to underscores.

Replies are listed 'Best First'.
Re: Re: Long file names in .dbf databases
by talwyn (Monk) on Oct 07, 2003 at 15:36 UTC
    LOL :) I *tried* to warn you :) Thats what the previous thread covered. Thanks for investigating the problem. Its nice to know I am not hallucinating :)

    Unfortunately I am trying to read tables generated by another application that still uses them so I cannot rename them. So thus far the best solution appears to be copying to a temp file and then accessing. The low-level driver has the same problem with long filenames. I haven't had a chance to try and nail down the problem in the code.

    I have also contemplated using Win32::ODBC or Win32::DBIODBC and using the native VFP drivers. I have also not had an opportunity to try to implement this.

    Again Thanks for the attempt, I appreciate it.