Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres driver query bug ? #55

Closed
remoe opened this issue Jan 11, 2012 · 7 comments
Closed

postgres driver query bug ? #55

remoe opened this issue Jan 11, 2012 · 7 comments

Comments

@remoe
Copy link
Contributor

remoe commented Jan 11, 2012

I have troubles with postgres driver from osgEarth

Part of my log:

PG: PostgreSQL version string : 'PostgreSQL 9.1.2 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.5 20110214 (Red Hat 4.4.5-6), 64-bit'

PG: PQexec(DECLARE executeSQLCursor CURSOR for SELECT * FROM 'b_table_test_text_1') = PGRES_FATAL_ERROR
PG: PQexec(FETCH 0 in executeSQLCursor) = PGRES_FATAL_ERROR

It has to do with the following

FeatureCursorOGR::FeatureCursorOGR(OGRDataSourceH dsHandle,
                                   OGRLayerH layerHandle,
                                   const FeatureProfile* profile,
                                   const Symbology::Query& query,
                                   const FeatureFilterList& filters )
...
        from = std::string("'") + from + std::string("'"); // this is not needed

...

This quoting is not needed. When i remove this it works. But i using PG 9.1.

i use the following parameters for configure the driver:

feature_opt.connection() = "PG:dbname='map' host=host.com port=5432 user='postgres' tables=b_table_test_text_1";
style_selector.query()->expression() = "display_level = 1";

Thanks
Remo

@remoe
Copy link
Contributor Author

remoe commented Jan 12, 2012

Hi

When you look at the documentation of PostGres then table names are identifiers also in older versions:

http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html
http://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html

This can be quoted with double-quotes but NOT with single quotes.

Can someone please confirm this ? Thanks.

@gwaldron
Copy link
Owner

Remo,

I guess the issue is that different back ends have different syntax. So somehow we need to account for that. Any suggestions?

@remoe
Copy link
Contributor Author

remoe commented Jan 12, 2012

Glenn, but please look at the lexical - docs. It says that single quotes are not correct.

@gwaldron
Copy link
Owner

Not correct for Postgres. But they are correct for OGR SQL, and possibly other OGR drivers. When the back-end driver supports SQL, OGR passes the SQL string along to the driver. But different drivers supports different flavors of SQL. I'm saying we need a way to account for that.

@remoe
Copy link
Contributor Author

remoe commented Jan 13, 2012

Ok, thanks. I need to read some docs and code ;)

@jasonbeverage
Copy link
Collaborator

Remo, try doing a pull and see if it works for you now. I made a change to only quote the table name if contains spaces and I'm also checking to see if the driver is PostgreSQL, and if it is using double quotes instead of single quotes as the delimiter.

@remoe
Copy link
Contributor Author

remoe commented Jan 16, 2012

@jasonbeverage , thanks, it works now.

@remoe remoe closed this as completed Jan 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants