Skip to content

Commit

Permalink
fix character set mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuinside committed Oct 4, 2024
1 parent 836de21 commit 21f3284
Show file tree
Hide file tree
Showing 7 changed files with 27,468 additions and 26,723 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
**v1.7.1**
### Fixes:
1. Fix 'character set' issue - https://github.com/xnuinside/simple-ddl-parser/issues/288


**v1.7.0**
### Fixes
1. DEFAULT Value with '::' cast parsed correctly now - https://github.com/xnuinside/simple-ddl-parser/issues/286
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ for help with debugging & testing support for BigQuery dialect DDLs:
* https://github.com/kalyan939

## Changelog
**v1.7.1**
### Fixes:
1. Fix 'character set' issue - https://github.com/xnuinside/simple-ddl-parser/issues/288


**v1.7.0**
### Fixes
1. DEFAULT Value with '::' cast parsed correctly now - https://github.com/xnuinside/simple-ddl-parser/issues/286
Expand Down
8 changes: 8 additions & 0 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ for help with debugging & testing support for BigQuery dialect DDLs:
Changelog
---------

**v1.7.1**

Fixes:
^^^^^^


#. Fix 'character set' issue - https://github.com/xnuinside/simple-ddl-parser/issues/288

**v1.7.0**

Fixes
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "simple-ddl-parser"
version = "1.7.0"
version = "1.7.1"
description = "Simple DDL Parser to parse SQL & dialects like HQL, TSQL (MSSQL), Oracle, AWS Redshift, Snowflake, MySQL, PostgreSQL, etc ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc.; sequences, alters, custom types & other entities from ddl."
authors = ["Iuliia Volkova <xnuinside@gmail.com>"]
license = "MIT"
Expand Down
8 changes: 6 additions & 2 deletions simple_ddl_parser/dialects/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ def p_create_table(self, p: List):

class Column:
def p_column_property(self, p: List):
"""c_property : id id"""
"""c_property : id id
| id SET id
| SET id"""
p_list = list(p)
if p[1].lower() == "auto":
p[0] = {"increment": True}
Expand Down Expand Up @@ -413,6 +415,9 @@ def set_property(p: List) -> List:
if isinstance(item, dict):
if "property" in item:
for key, value in item["property"].items():
if key == "SET" and "CHARACTER" in p[0]["type"].upper():
p[0]["type"] = p[0]["type"].split("CHARACTER")[0].strip()
key = f"CHARACTER_{key}".lower()
p[0][key] = value
del item["property"]
p[0].update(item)
Expand Down Expand Up @@ -480,7 +485,6 @@ def p_defcolumn(self, p: List) -> None:
"""
p[0] = p[1]
p_list = list(p)

pk, default, unique, references, nullable, index = self.get_column_properties(
p_list
)
Expand Down
54,106 changes: 27,386 additions & 26,720 deletions simple_ddl_parser/parsetab.py

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions tests/dialects/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,3 +722,60 @@ def test_set_type():
output_mode="mysql",
)
assert expected == result


def test_mysql_character_set():
ddl = """
CREATE TABLE `table_notes` (
`id` int NOT NULL AUTO_INCREMENT,
`notes` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL,
);"""
result = DDLParser(ddl, debug=True).run(
group_by_type=True,
output_mode="mysql",
)
expected = {
"ddl_properties": [],
"domains": [],
"schemas": [],
"sequences": [],
"tables": [
{
"alter": {},
"checks": [],
"columns": [
{
"autoincrement": True,
"check": None,
"default": None,
"name": "`id`",
"nullable": False,
"references": None,
"size": None,
"type": "int",
"unique": False,
},
{
"character_set": "utf8mb3",
"check": None,
"collate": "utf8mb3_general_ci",
"default": None,
"name": "`notes`",
"nullable": False,
"references": None,
"size": 255,
"type": "varchar",
"unique": False,
},
],
"index": [],
"partitioned_by": [],
"primary_key": [],
"schema": None,
"table_name": "`table_notes`",
"tablespace": None,
}
],
"types": [],
}
assert expected == result

0 comments on commit 21f3284

Please sign in to comment.