-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use sqlalchemy's 'quote' function to quote table names
- Loading branch information
Showing
3 changed files
with
63 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
|
||
from cratedb_toolkit.util import DatabaseAdapter | ||
|
||
|
||
def test_quote_relation_name(): | ||
database = DatabaseAdapter(dburi="crate://localhost") | ||
assert database.quote_relation_name("my_table") == "my_table" | ||
assert database.quote_relation_name("my-table") == '"my-table"' | ||
assert database.quote_relation_name("MyTable") == '"MyTable"' | ||
assert database.quote_relation_name('"MyTable"') == '"MyTable"' | ||
assert database.quote_relation_name("my_schema.my_table") == "my_schema.my_table" | ||
assert database.quote_relation_name("my-schema.my_table") == '"my-schema".my_table' | ||
assert database.quote_relation_name('"wrong-quoted-fqn.my_table"') == '"wrong-quoted-fqn.my_table"' | ||
assert database.quote_relation_name('"my_schema"."my_table"') == '"my_schema"."my_table"' | ||
# reserved keyword must be quoted | ||
assert database.quote_relation_name("table") == '"table"' | ||
|
||
|
||
def test_quote_relation_name_with_invalid_fqn(): | ||
database = DatabaseAdapter(dburi="crate://localhost") | ||
with pytest.raises(ValueError): | ||
database.quote_relation_name("my-db.my-schema.my-table") |