Skip to content

Commit

Permalink
parse validly identity if no size type provided
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuinside committed Mar 29, 2023
1 parent b0280ca commit b1b79ce
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 48 deletions.
16 changes: 10 additions & 6 deletions simple_ddl_parser/dialects/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,20 @@ def process_oracle_type_size(p_list):
return p_list

def process_type_to_column_data(self, p_list, p):
if len(p_list) <= 3:
if 'IDENTITY' in p_list[-1]['type'].upper():
split_type = p_list[-1]['type'].split()
del p_list[-1]
if len(split_type) == 1:
self.set_column_size(p_list, p)
else:
p[0]['type'] = split_type[0]
p[0]['identity'] = None
return True
elif len(p_list) <= 3:
p[0]["type"] = p_list[-1]["type"]
if p_list[-1].get("property"):
for key, value in p_list[-1]["property"].items():
p[0][key] = value
elif p_list[-1]['type'].upper() in ['IDENTITY']:
del p_list[-1]
self.set_column_size(p_list, p)
p[0]['identity'] = None
return True
else:
# for [] arrays
p[0]['type'] += p_list[-1]['type']
Expand Down
90 changes: 54 additions & 36 deletions tests/dialects/test_mssql_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def test_int_identity_type():
"name": "id",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -85,8 +86,9 @@ def test_mssql_foreign_ref_in_column():
"name": "id",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -212,8 +214,9 @@ def test_constraint_unique():
"name": "id",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -287,8 +290,9 @@ def test_constraint_unique_none():
"name": "id",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -397,8 +401,9 @@ def test_two_unique_constructs():
"name": "id",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -794,8 +799,9 @@ def test_foreign_keys():
"schema": None,
"table": "Persons",
},
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -1159,8 +1165,9 @@ def test_alter_unique():
"schema": None,
"table": "Persons",
},
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -1552,8 +1559,9 @@ def test_defaults_in_alter():
"schema": None,
"table": "Persons",
},
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -1822,8 +1830,9 @@ def test_constraint_primary_key():
"name": "[id]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -1926,8 +1935,9 @@ def test_constraint_with_with():
"name": "[id]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -2026,8 +2036,9 @@ def test_with_on():
"name": "[id]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -2167,8 +2178,9 @@ def test_period_for_system_time():
"name": "[id]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -2291,8 +2303,9 @@ def test_on_primary_on_table_level():
"name": "[id]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -2423,8 +2436,9 @@ def test_with_on_table_level():
"name": "[id]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -2514,8 +2528,9 @@ def test_with_on_with_properties():
"name": "[id]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -2669,8 +2684,9 @@ def test_output_separated_by_go_and_textimage():
"name": "[Request_ID]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -2841,8 +2857,9 @@ def test_output_separated_by_go_and_textimage():
"name": "[ID]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down Expand Up @@ -2903,8 +2920,9 @@ def test_output_separated_by_go_and_textimage():
"name": "[ToDoCommentsId]",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "[int] IDENTITY",
"size": None,
"identity": (1, 1),
"type": "[int]",
"unique": False,
},
{
Expand Down
5 changes: 3 additions & 2 deletions tests/non_statement_tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def test_flag_normalize_names():
"name": "Request_ID",
"nullable": False,
"references": None,
"size": (1, 1),
"type": "int IDENTITY",
"size": None,
"identity": (1, 1),
"type": "int",
"unique": False,
},
{
Expand Down
10 changes: 6 additions & 4 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def test_several_indexes_types():
"schema": None,
"table": "Persons",
},
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down Expand Up @@ -418,8 +419,9 @@ def test_clustered_index():
"schema": None,
"table": "Persons",
},
"size": (1, 1),
"type": "INT IDENTITY",
"size": None,
"identity": (1, 1),
"type": "INT",
"unique": False,
},
{
Expand Down

0 comments on commit b1b79ce

Please sign in to comment.