sql-blocks 1.25.610999999999__py3-none-any.whl → 1.25.6109999999999__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sql_blocks/sql_blocks.py CHANGED
@@ -84,6 +84,17 @@ class SQLObject:
84
84
  appendix = {WHERE: r'\s+and\s+|', FROM: r'\s+join\s+|\s+JOIN\s+'}
85
85
  return KEYWORD[key][0].format(appendix.get(key, ''))
86
86
 
87
+ @staticmethod
88
+ def contains_CASE_statement(text: str) -> bool:
89
+ return re.search(r'\bCASE\b', text, re.IGNORECASE)
90
+
91
+ @classmethod
92
+ def split_fields(cls, text: str, key: str) -> list:
93
+ if key == SELECT and cls.contains_CASE_statement(text):
94
+ return Case.parse(text)
95
+ separator = cls.get_separator(key)
96
+ return re.split(separator, text)
97
+
87
98
  @staticmethod
88
99
  def is_named_field(fld: str, name: str='') -> bool:
89
100
  return re.search(fr'(\s+as\s+|\s+AS\s+){name}', fld)
@@ -103,16 +114,13 @@ class SQLObject:
103
114
  result += re.split(r'([=()]|<>|\s+ON\s+|\s+on\s+)', fld)
104
115
  return result
105
116
  def cleanup(text: str) -> str:
106
- if re.search(r'^CASE\b', text):
117
+ # if re.search(r'^CASE\b', text):
118
+ if self.contains_CASE_statement(text):
107
119
  return text
108
120
  text = re.sub(r'[\n\t]', ' ', text)
109
121
  if exact:
110
122
  text = text.lower()
111
123
  return text.strip()
112
- def split_fields(text: str) -> list:
113
- if key == SELECT:
114
- return Case.parse(text)
115
- return re.split(separator, text)
116
124
  def field_set(source: list) -> set:
117
125
  return set(
118
126
  (
@@ -122,14 +130,13 @@ class SQLObject:
122
130
  re.sub(pattern, '', cleanup(fld))
123
131
  )
124
132
  for string in disassemble(source)
125
- for fld in split_fields(string)
133
+ for fld in self.split_fields(string, key)
126
134
  )
127
135
  pattern = KEYWORD[key][1]
128
136
  if exact:
129
137
  if key == WHERE:
130
138
  pattern = r'["\']| '
131
139
  pattern += f'|{PATTERN_PREFIX}'
132
- separator = self.get_separator(key)
133
140
  s1 = field_set(search_list)
134
141
  s2 = field_set(self.values.get(key, []))
135
142
  if exact:
@@ -727,7 +734,7 @@ class Case:
727
734
  result += block.fields
728
735
  block.fields = []
729
736
  elif word not in RESERVED_WORDS:
730
- result.append(word)
737
+ result.append(word.replace(',', ''))
731
738
  last_word = word
732
739
  return result
733
740
 
@@ -1417,13 +1424,12 @@ class SQLParser(Parser):
1417
1424
  for key in USUAL_KEYS:
1418
1425
  if not key in values:
1419
1426
  continue
1420
- separator = self.class_type.get_separator(key)
1421
1427
  cls = {
1422
1428
  ORDER_BY: OrderBy, GROUP_BY: GroupBy
1423
1429
  }.get(key, Field)
1424
1430
  obj.values[key] = [
1425
1431
  cls.format(fld, obj)
1426
- for fld in re.split(separator, values[key])
1432
+ for fld in self.class_type.split_fields(values[key], key)
1427
1433
  if (fld != '*' and len(tables) == 1) or obj.match(fld, key)
1428
1434
  ]
1429
1435
  result[obj.alias] = obj
@@ -2111,4 +2117,3 @@ def detect(text: str, join_queries: bool = True, format: str='') -> Select | lis
2111
2117
  return result
2112
2118
  # ===========================================================================================//
2113
2119
 
2114
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.25.610999999999
3
+ Version: 1.25.6109999999999
4
4
  Summary: Allows you to create objects for parts of SQL query commands. Also to combine these objects by joining them, adding or removing parts...
5
5
  Home-page: https://github.com/julio-cascalles/sql_blocks
6
6
  Author: Júlio Cascalles
@@ -0,0 +1,7 @@
1
+ sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
+ sql_blocks/sql_blocks.py,sha256=09o87wu2xc82AMMyV-OBiYmv0d_kfL_DIH6G--3-DIA,71615
3
+ sql_blocks-1.25.6109999999999.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
+ sql_blocks-1.25.6109999999999.dist-info/METADATA,sha256=KpFEm1tvvHvoURZ3kV1VjvBvSIEGGAWuskacBXg0Xp4,22236
5
+ sql_blocks-1.25.6109999999999.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ sql_blocks-1.25.6109999999999.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
+ sql_blocks-1.25.6109999999999.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
2
- sql_blocks/sql_blocks.py,sha256=tdfGConHw2iosex_BSXAWxYTGufPyOVMSTyi3g6gqpM,71400
3
- sql_blocks-1.25.610999999999.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
4
- sql_blocks-1.25.610999999999.dist-info/METADATA,sha256=09DIeKq_SinVNKt0OyYQQDOZ2_DDR6CmoP_n99t4ZXA,22235
5
- sql_blocks-1.25.610999999999.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- sql_blocks-1.25.610999999999.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
7
- sql_blocks-1.25.610999999999.dist-info/RECORD,,