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

fix: allow uppercase table names using haveInDatabase with postgreSql #82

Merged
merged 2 commits into from
Feb 6, 2025

Conversation

jandrusku
Copy link
Contributor

Fix error when using haveInDatabase() on databases with illegal table names (like uppercase chars).

According to PostgreSQL Wiki:

The table name must be double-quoted for otherwise illegal names (upper-case letters, reserved words etc.): '"oDD table name"'::regclass

Exception throwed:

  [PDOException] SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "nopk" does not exist
LINE 5:                 WHERE  i.indrelid = 'NoPk'::regclass

fixes #14

@@ -164,7 +164,7 @@ public function getPrimaryKey(string $tableName): array
FROM pg_index i
JOIN pg_attribute a ON a.attrelid = i.indrelid
AND a.attnum = ANY(i.indkey)
WHERE i.indrelid = '{$tableName}'::regclass
WHERE i.indrelid = " . $this->postgreQuotedName($tableName) . "::regclass
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could explicitly quote every table name without the extra overhead of a regex. I believe it's fully backward-compatible. What do you think?

Suggested change
WHERE i.indrelid = " . $this->postgreQuotedName($tableName) . "::regclass
WHERE i.indrelid = '\"{$tableName}\"'::regclass

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 created the postgreQuotedName method because I was not sure it would be backwards compatible, but if it works, your suggestion it's ok for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All tests pass. Changed.

@szhajdu szhajdu merged commit 8a295c4 into Codeception:master Feb 6, 2025
6 checks passed
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

Successfully merging this pull request may close these issues.

[PDOException] SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "pictograms_tags_uk-UA" does not exist
2 participants