Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read an Access database table that has spaces in the name

Status
Not open for further replies.

KingDufus

Technical User
Oct 9, 2001
19
US
I'm new to Perl, and am connecting to an Access Databse using the DBI:ODBC module. I can make the connection without any problems, but can't seem to get the "SELECT * FROM" code to work because the table name I need to read has spaces in it. (For example: "Name of Table") I am not in a position to have the table name changed (it's an existing database). Is there a way I can read this table?
I had a similar problem with field names, but solved that one by enclosing the field name in [] but this doesn't work with the table name. Thanks for your help!

King Dufus
 
Most modules come with perldocs to help explain how to use them. I'm not familiar with the Windows modules, but on Linux, you'd need the DBI module, and also the DBD::ODBC module. I'd read the perldocs on the DBD::ODBC module - maybe it would describe how to SELECT from tables that have spaces in the tablename.

At a command prompt(in a DOS window), do

perldoc DBD::ODBC

Hope this helps.
Hardy Merrill
Mission Critical Linux, Inc.
 
One thing you can try - in your code

my $sth = $dbh->prepare(qq{
SELECT *
FROM "TEST TABLE"
});

Using the qq is the same as using double quotes, but double quotes are allowed to be *in* the text that you quote with qq, whereas if you used double quotes to surround the text, you'd need to escape each double quote that occurred in the text.

Hope this helps.
Hardy Merrill
Mission Critical Linux, Inc.
 
It should work with [] around table names in Access. The simplest way is building the query in Access until it runs and cut'n paste it into the perl program.

Thomas
 
Thanks everyone for posting. Sorry for the huge delay in my response. I tried the qq statement that Hardy suggested, and that unfortunately that didn't work for me. I also tried the [] around the names that Thomas suggested, and that too did not seem to work. The [] worked for field names in the table itself, but not for the actual table name.
Thomas, I am new to Access, and didn't understand the second part of your suggestion about building a query. Could you elaborate? Thanks,
-King Dufus
 
Since no-one seems to have a workable answer to this question, I would recommend that you post your question to the DBI mailing list - there are people on that list with experience with DBD::ODBC and I'm sure someone could answer this question having to do with spaces in the table name.
Hardy Merrill
Mission Critical Linux, Inc.
 
This is just a shot, but some DBs allow you to use underscore in place of spaces. Might give that a try. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top