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

Allow escaped column and table names in postgres. #450

Merged
merged 1 commit into from
Jan 1, 2016

Conversation

igieon
Copy link
Contributor

@igieon igieon commented Dec 18, 2015

Allow to have table names like public."Pos++Pers" and column names like "Pers++Pos+id"

String qry = " select column_name, data_type, character_maximum_length "
+ " as direction from information_schema.columns where ";

if (qualifiers.length == 2) {
qry += " lower(table_schema)=? and lower(table_name)=? ";
qry += " table_schema=? and table_name=? ";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we making tables case-sensitive here? Are the other tests still working fine, will both below succeed:

|update|users|
|username=|name|
|adent2|arthur dent|
|UPDATE|USERS|
|USERNAME=|NAME|
|adent2|arthur dent|

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to put in correct way if you create table or columns without " postgres automatically convert it to lower case adn then it will by stored in information schema. I added that test into test suite.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to put in correct way if you create table or columns without " postgres automatically convert it to lower case adn then it will by stored in information schema. I added that test into test suite.

Have you pushed that test, I don't see it yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now is pushed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK... Update actually works a bit different than e.g. Insert. It's interesting to check also Insert with both upper and lower case - maybe in the same test can be split to check both scenarios:

|insert|users|
|name|username|
|arthur dent|adent|

|INSERT|USERS|
|NAME|USERNAME|
|ford prefect|fpref|
|zaphod beeblebrox|zaphod|

Will this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed modified test. For lower case is everything in SimpleUpdate all modification upper case are in SimpleUpdate2

@javornikolov
Copy link
Contributor

Thank you @igieon for submitting this pull request! Looks like a useful feature, just needs some polishing. I just posted a few comments inline.

@@ -74,7 +74,7 @@ protected String parseCommandText(String commandText) {
paramName = "";
String dataType = rs.getString(2);
DbParameterAccessor dbp = createDbParameterAccessor(
paramName,
'"' + paramName + '"',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can avoid escaping that here (since it has always been the original name unmodified)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added one new test for this. We need to put there escapped character because its column name and we need to escape collumn name, because in information schema is alway unescapped stored. Meaning that if you use unexcapped character is column always stored as lower case and we can escaped it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added one new test for this. We need to put there escapped character because its column name and we need to escape collumn name, because in information schema is alway unescapped stored. Meaning that if you use unexcapped character is column always stored as lower case and we can escaped it.

Yes, but what I was wondering is if we can do the escaping somewhere else? I guess for buildInsertCommand we can easily handle since it's inside environment class; for Update - hmm, maybe we can introduce some general ability for case-sensitive escaping (there is similar issue for other database types). I'm not sure if anything else is affected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me when i look into code everything could be change if we modify NameNormaliser and little refactor code around it. As i look now my change doesn't affect weird function parameters. I want just implement this case, because we need to transform old weird naming schema to new one understandable views and we want to have covered with tests ;-).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I think the current change is well isolated (only pgsql code is affected) and is working good enough. We can go with it as initial version and think of possible refactoring later.

@javornikolov
Copy link
Contributor

Merging... @igieon, thanks a lot for that contribution!

@javornikolov
Copy link
Contributor

Just a final touch: @igieon, could you squash your commits into single one before we merge the PR?

@igieon
Copy link
Contributor Author

igieon commented Jan 1, 2016

Squashed. Just the question when you make new release ?

@javornikolov
Copy link
Contributor

Squashed.

Thanks! Can we just have the commit message description refined a bit (says Add more tests. right now).

Just the question when you make new release ?

I think we can make it pretty soon. Do you have any preference?

- allow table names like "Pers+""+Pos" in PostgresSQL
- allow column names like "Info""+desc"
- look usage in tests
DbFit/AcceptanceTests/JavaTests/PostgresTests/FlowMode/SimpleUpdateEscaped.html
@igieon
Copy link
Contributor Author

igieon commented Jan 1, 2016

Could be like that ?

@javornikolov
Copy link
Contributor

Yes, it looks good now 👍 . Thank you!

javornikolov added a commit that referenced this pull request Jan 1, 2016
Allow escaped column and table names  in postgres.
@javornikolov javornikolov merged commit fc2e1e8 into dbfit:master Jan 1, 2016
@javornikolov javornikolov added this to the 4.0.0 milestone Jan 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants