real_data_tests 0.3.8 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 573f1753777e04a6168a09385b8332cedbb4d521d11f1807012a25b8b846013c
4
- data.tar.gz: b884098abbc9134a22479d5e9211a2d8bb153622022ba9116acb0057419cbe4a
3
+ metadata.gz: f76c93165cf56a1bb2e90311afc6bf92f42f17553271a977dec2e17f39afc67f
4
+ data.tar.gz: f1caa35f8eaa904dba0b608484d43d8beffaa7208646e067f046b8add97db10d
5
5
  SHA512:
6
- metadata.gz: 1d4bcb84f7d3ab3ee0901ae46763c912f3c86935930cc17607d500ae7a2e26649f8c6ff629e8215437d8f08ae93d482870e253b294e84e720971c9bf681c7b50
7
- data.tar.gz: 67cad3bda841d3e1de61d61dd30121ef3b6ddfc96a3162438a2b25f904185e6e4c59206d2626e6b40d44a72d123ed123e4073a4fdfe10d04fea807a8702bf689
6
+ metadata.gz: 1097a749d0dd8ad287130dbab5a75c0f526de6689e9877d4f218657d6c03ad49ccd8c0c3cd02697306d1fee41c11c0915f11e4c264e2254cb21013e266d130aa
7
+ data.tar.gz: c0b6f6c9f84558801e5140eea8da6c5f068ad5adbe4dd3ba520e87fe2ef2259921374d52713e8e3a52775b64bb439f426be72a698d83e5a0144b16a6282cfc14
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.10] - 2025-01-14
4
+ ### Fixed
5
+ - Enhanced SQL statement parsing in native loader
6
+ - Improved handling of complex ON CONFLICT clauses with multiple closing parentheses
7
+ - Fixed spacing issues between VALUES and ON CONFLICT clauses
8
+ - Enhanced regex pattern for more precise conflict clause extraction
9
+ - Added proper statement reassembly for complex SQL structures
10
+
11
+ ## [0.3.9] - 2025-01-14
12
+ ### Fixed
13
+ - Enhanced SQL statement parsing in native loader
14
+ - Improved handling of complex ON CONFLICT clauses with multiple closing parentheses
15
+ - Fixed spacing issues between VALUES and ON CONFLICT clauses
16
+ - Enhanced regex pattern for more precise conflict clause extraction
17
+ - Added proper statement reassembly for complex SQL structures
18
+
3
19
  ## [0.3.8] - 2025-01-14
4
20
  ### Fixed
5
21
  - Enhanced SQL statement parsing in native loader
@@ -113,61 +113,78 @@ module RealDataTests
113
113
  end
114
114
 
115
115
  def clean_sql_statement(statement)
116
- # Extract the ON CONFLICT clause if it exists
117
- statement, conflict_clause = extract_conflict_clause(statement)
118
-
119
- # Handle VALUES clause formatting
120
- if statement.include?('VALUES')
121
- # Split into pre-VALUES and VALUES parts
122
- parts = statement.split(/VALUES\s*\(/i, 2)
123
- if parts.length == 2
124
- # Clean and process the values
125
- values = clean_values(parts[1].split(/\)\s*$/)[0])
126
-
127
- # Make sure we properly close the VALUES parentheses
128
- statement = "#{parts[0]}VALUES (#{values})"
116
+ # Match either INSERT INTO...VALUES or just VALUES
117
+ if statement =~ /(?:INSERT INTO.*)?VALUES\s*\(/i
118
+ # Split the statement into parts, being careful with the ending
119
+ if statement =~ /(.*?VALUES\s*\()(.*)(\)\s*(?:ON CONFLICT.*)?;?\s*$)/i
120
+ pre_values = $1
121
+ values_content = $2
122
+ post_values = $3
123
+
124
+ # Clean the values content while preserving complex JSON
125
+ cleaned_values = clean_complex_values(values_content)
126
+
127
+ # Reassemble the statement, ensuring exactly one semicolon at the end
128
+ statement = "#{pre_values}#{cleaned_values}#{post_values}"
129
+ statement = statement.gsub(/;*\s*$/, '') # Remove any trailing semicolons and whitespace
130
+ statement += ";"
129
131
  end
130
132
  end
131
-
132
- # Add back the conflict clause if it existed
133
- statement = "#{statement}#{conflict_clause ? ' ' + conflict_clause : ''}"
134
-
135
- # Ensure the statement ends with a semicolon
136
- statement += ";" unless statement.end_with?(';')
137
-
138
133
  statement
139
134
  end
140
135
 
141
- def clean_values(values_str)
142
- values = []
136
+ def clean_complex_values(values_str)
143
137
  current_value = ''
138
+ values = []
144
139
  in_quotes = false
145
- nested_level = 0
140
+ in_json = false
141
+ json_brace_count = 0
142
+ escaped = false
143
+
144
+ chars = values_str.chars
145
+ i = 0
146
+ while i < chars.length
147
+ char = chars[i]
146
148
 
147
- values_str.chars.each do |char|
148
149
  case char
150
+ when '\\'
151
+ current_value << char
152
+ escaped = !escaped
149
153
  when "'"
150
- in_quotes = !in_quotes
154
+ if !escaped
155
+ in_quotes = !in_quotes
156
+ end
157
+ escaped = false
151
158
  current_value << char
152
159
  when '{'
153
- nested_level += 1
160
+ if !in_quotes
161
+ in_json = true
162
+ json_brace_count += 1
163
+ end
154
164
  current_value << char
155
165
  when '}'
156
- nested_level -= 1
166
+ if !in_quotes
167
+ json_brace_count -= 1
168
+ in_json = json_brace_count > 0
169
+ end
157
170
  current_value << char
158
171
  when ','
159
- if !in_quotes && nested_level == 0
172
+ if !in_quotes && !in_json
160
173
  values << clean_value(current_value.strip)
161
174
  current_value = ''
162
175
  else
163
176
  current_value << char
164
177
  end
165
178
  else
179
+ escaped = false
166
180
  current_value << char
167
181
  end
182
+ i += 1
168
183
  end
169
184
 
170
- values << clean_value(current_value.strip)
185
+ # Add the last value
186
+ values << clean_value(current_value.strip) unless current_value.strip.empty?
187
+
171
188
  values.join(', ')
172
189
  end
173
190
 
@@ -181,8 +198,42 @@ module RealDataTests
181
198
  if value.match?(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)
182
199
  "'#{value}'" # UUID
183
200
  else
201
+ # Handle any other string value, including those with commas
184
202
  "'#{value}'" # Other strings
185
203
  end
186
204
  end
205
+
206
+ def clean_values(values_str)
207
+ values = []
208
+ current_value = ''
209
+ in_quotes = false
210
+ nested_level = 0
211
+
212
+ values_str.chars.each do |char|
213
+ case char
214
+ when "'"
215
+ in_quotes = !in_quotes
216
+ current_value << char
217
+ when '{'
218
+ nested_level += 1
219
+ current_value << char
220
+ when '}'
221
+ nested_level -= 1
222
+ current_value << char
223
+ when ','
224
+ if !in_quotes && nested_level == 0
225
+ values << clean_value(current_value.strip)
226
+ current_value = ''
227
+ else
228
+ current_value << char
229
+ end
230
+ else
231
+ current_value << char
232
+ end
233
+ end
234
+
235
+ values << clean_value(current_value.strip)
236
+ values.join(', ')
237
+ end
187
238
  end
188
239
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RealDataTests
4
- VERSION = "0.3.8"
4
+ VERSION = "0.3.10"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: real_data_tests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dias