Skip to content

Commit

Permalink
Fix bug in DBML column default rendering with single quotes
Browse files Browse the repository at this point in the history
- Integrated `prepare_text_for_dbml` into `default_to_str` for consistent handling of special characters in DBML column strings.
- Updated the test suite to include a new test case for handling binary string input (`b'0'`).
  • Loading branch information
psw0625 committed Nov 26, 2024
1 parent 2606d18 commit 7ccd5c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pydbml/renderer/dbml/default/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydbml.classes import Column, Enum, Expression
from pydbml.renderer.dbml.default.renderer import DefaultDBMLRenderer
from pydbml.renderer.dbml.default.utils import comment_to_dbml, note_option_to_dbml, quote_string
from pydbml.renderer.dbml.default.utils import comment_to_dbml, note_option_to_dbml, quote_string, prepare_text_for_dbml
from pydbml.renderer.sql.default.utils import get_full_name_for_sql


Expand All @@ -11,7 +11,7 @@ def default_to_str(val: Union[Expression, str, int, float]) -> str:
if val.lower() in ('null', 'true', 'false'):
return val.lower()
else:
return f"'{val}'"
return f"'{prepare_text_for_dbml(val)}'"
elif isinstance(val, Expression):
return val.dbml
else: # int or float or bool
Expand Down
1 change: 1 addition & 0 deletions test/test_renderer/test_dbml/test_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
(True, "True"),
("False", "false"),
("null", "null"),
("b'0'", "'b\\'0\\''"),
],
)
def test_default_to_str(input: Any, expected: str) -> None:
Expand Down

0 comments on commit 7ccd5c6

Please sign in to comment.