#7242 closed defect (fixed)
GDAL ODBC (MS Access driver), can't deal with table names that have spaces
Reported by: | robe | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 2.2.4 |
Component: | default | Version: | unspecified |
Severity: | normal | Keywords: | |
Cc: |
Description
I tested this on GDAL 2.1.3, GDAL 2.2.1, and GDAL 2.2.3 and all seemed to have the same issue.
This is under windows 7 64-bit
# This correctly gives list of layers
ogrinfo "C:\Temp\test.mdb" INFO: Open of `C:\Temp\test.mdb' using driver `ODBC' successful. 1: a table 2: test
#But when I try to query the table that has spaces in name, I get this
ogrinfo "S:\Temp\test.mdb" "a table" INFO: Open of `C:\Temp\test.mdb' using driver `ODBC' successful. Layer name: a table Geometry: Unknown (any) ERROR 1: GetFeatureCount() failed on query SELECT COUNT(*) FROM a table. [Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause. Feature Count: 0 Layer SRS WKT: (unknown) ID: Integer (10.0) A Number: Integer (10.0) A Text: String (255.0)
Attached Is sample database I was using to troubleshoot the problem.
Attachments (3)
Change History (12)
by , 6 years ago
comment:1 by , 6 years ago
@robe Can you try the attached patch ? (based on trunk, but should hopefully apply on 2.2 branch) Just compile-tested on my side.
by , 6 years ago
Attachment: | ticket7242.patch added |
---|
comment:2 by , 6 years ago
That seems to do the trick. I'll test on other ODBC sources besides MS Access to confirm they all work. But I think this one is a winner.
comment:5 by , 6 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Even sorry when I was testing SQL Server, I had by ODBC connection look something like this:
ogrinfo "ODBC:sa/whatever@SServer,Table1,Table2" Table1
So layers didn't come thru schema qualified
However if I do it this way so all tables are brought in with their schema qualification
Then it doesn't work
ogrinfo "ODBC:sa/whatever@SServer" dbo.Table1
I get this error:
ERROR 1: GetFeatureCount() failed on query SELECT COUNT(*) FROM "dbo.Table1". [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.Table1'
When it should be doing this:
SELECT COUNT(*) FROM "dbo"."Table1"
comment:7 by , 6 years ago
This isn't perfect as I guess someone could create a table with a . in it
like myspecialtable.hasadot
and it won't correctly handle that, unless we move the logic the ogrodbcdatasource.cpp -> OGRODBCDataSource::Open where it explicitly glues the schema + . + the tablename together.
That seemed a little invasive though.
by , 6 years ago
Attachment: | ogrodbctablelayer.cpp.patch added |
---|
properly quote schema qualified layers
test.mdb