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

Support PostgreSQL double qouted columns #590

Merged
merged 13 commits into from
Oct 10, 2022

Conversation

Zhaars
Copy link
Contributor

@Zhaars Zhaars commented Oct 5, 2022

This PR contains only sqlparser changes to fix the open issue. During debugging we faced that sqlparser flow has incorrect flow for parsing statements as WHERE "column" = 'value' as it looks on value rule instead of column_name.

In this PR two new types were introduced

  • column_name_ext which is almost as column_name but has primary DOUBLE_QUOTE_STRING rule to track double quoted column only for PostgreSQL.
  • column_name_expression - which is the same as value_expression but used column_name_ext instead of column_name.

Checklist

Added support of double quoted column names for PostgreSQL
@Zhaars Zhaars requested a review from Lagovas October 5, 2022 16:08
Added scenario comparison where test = test for MySQL
Added fix related to column names with double quotes in SELECT statements
Restructure sqlparser sql.y file
input: `select * from mytable where "test" = 1 and 'value' = 'value'`,
output: `select * from mytable where 'test' = 1 and 'value' = 'value'`,
}, {
input: `SELECT "id", "landline_number" AS "landlineNumber", "removal" FROM "users" AS "User" where "User"."is_active"`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets add some somparison too: WHERE "User"."AGE" = 123 and simple "AGE"='123' without table name.

Copy link
Collaborator

Choose a reason for hiding this comment

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

plus I remember that you mentioned some integration tests with double quotes. Can we extend them with additional cases that we caught?

@@ -215,6 +215,11 @@ var (
input: `select * from mytable where "AGE" = 1 and "TEST" = 'test'`,
// postgres allow to use double quote string for columns
dialect: postgresql.NewPostgreSQLDialect(),
}, {
input: `insert into some_table(id, data) VALUES (10918, "test")`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets add comment, that it is temporary valid for MySQL default settings, but invalid for PostgreSQL & MySQL with ANSI mode, and probably will be changed. It will help in the future to understand why this case will fail after future changes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, also added TODO in invalidSQL tests that such query should be tests on failure

Added comment about future updates
Fixed matching with Tables for searchable encryption
@Zhaars
Copy link
Contributor Author

Zhaars commented Oct 7, 2022

@Lagovas I added a couple of unit tests to cover correct matching with tables from config. Please let me know if you want more tests to be added.

"github.com/cossacklabs/acra/sqlparser"
)

func TestGetTableSchemaOfColumnMatchConfiTable(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func TestGetTableSchemaOfColumnMatchConfiTable(t *testing.T) {
func TestGetTableSchemaOfColumnMatchConfigTable(t *testing.T) {

)

func TestGetTableSchemaOfColumnMatchConfiTable(t *testing.T) {
tableName := "some_table"
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use name with upper-cased characters here and below? to be sure that we handle it correctly. Because previously we handled it in lowercase by default

quote: 34,
v: "table",
}
b, err := json.Marshal(str)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we use json package instead of sqlparser.String?

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 copied from another test.

Fixed after review/add integration tests to cover double quoted tables in search queries
@Zhaars Zhaars requested a review from Lagovas October 10, 2022 11:13
tests/test.py Outdated
self.insertRow(context)
self.insertDifferentRows(context, count=5)

query = 'SELECT * FROM "test_searchable_transparent_encryption" WHERE searchable = :searchable'
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe lets use "searchable" = ...? to test wrapped column too?

Added double quoted column in the integration test query
@Zhaars Zhaars merged commit 2ff0799 into master Oct 10, 2022
@Lagovas Lagovas deleted the zhars/support_postgres_double_qouted_columns branch October 10, 2022 12:16
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

3 participants