real_data_tests 0.3.7 → 0.3.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f325960594ac352b4fbaae4adafb38256bde54feed249140838971e61c5fcef1
4
- data.tar.gz: d977dda68eac4fa8d13c82dc5a00bba7dd3b27e9c876ab5847a3b3b254cc7d4f
3
+ metadata.gz: 3a45102a35d4a4d4bff64e68a4edef1b7e29d8c2ca68c0a957ac2589b8ce3b04
4
+ data.tar.gz: 506f07bccd0524de51819b128a6a707979e68723e513e829e0437a9d7b503b75
5
5
  SHA512:
6
- metadata.gz: 40c69c54f989318441e697487673f7c019907cddcea3d81fa9b5775964fc2a6a76994b97093465d57f26521813780292f58d28f11ed75638222b458a75e514f8
7
- data.tar.gz: bce1cd39d64e2501b222135477c7e10d38769ae26b47827c3c76efb8d2651cdffae689ad3c8e2bb9bd0bdd1315e9f2dbfcdd3dd576079589c75d3d7585c2668c
6
+ metadata.gz: e33a481a786ef940d50eabf13b23ddc8175af68ec16892f685809a7acec88a27786f4b54e6588a890167c90a058d690acc7d1ba7d264e0802549590516d499aa
7
+ data.tar.gz: 45dcce0d68ce3011521aea9ffcefc7d355af5544c0cc8cc385b37b897e953cd51d9af928536c8c901f7ff35ba33a52df9886ac186b5182aecc0821c83d6ceb91
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.9] - 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.8] - 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.7] - 2025-01-14
4
20
  ### Fixed
5
21
  - Corrected SQL value handling in native loader
@@ -103,36 +103,83 @@ module RealDataTests
103
103
  statements
104
104
  end
105
105
 
106
+ def extract_conflict_clause(statement)
107
+ # Use a more precise regex that handles multiple closing parentheses
108
+ if statement =~ /(.+?\))\s*(ON\s+CONFLICT\s+.*?)(?:;?\s*$)/i
109
+ [$1, $2.strip]
110
+ else
111
+ [statement.sub(/;?\s*$/, ''), nil]
112
+ end
113
+ end
114
+
106
115
  def clean_sql_statement(statement)
107
- # Extract the ON CONFLICT clause if it exists
108
- statement, conflict_clause = extract_conflict_clause(statement)
116
+ # First, detect if this is an INSERT statement with VALUES
117
+ if statement =~ /INSERT INTO.*VALUES\s*\(/i
118
+ # Split the statement into three parts: pre-VALUES, values, and post-VALUES (ON CONFLICT clause)
119
+ if statement =~ /(.*VALUES\s*\()(.*)(\)\s*(?:ON CONFLICT.*)?;?\s*$)/i
120
+ pre_values = $1
121
+ values_content = $2
122
+ post_values = $3
109
123
 
110
- # Handle VALUES clause formatting
111
- if statement.include?('VALUES')
112
- # Split into pre-VALUES and VALUES parts
113
- parts = statement.split(/VALUES\s*\(/i, 2)
114
- if parts.length == 2
115
- # Clean and process the values
116
- values = clean_values(parts[1].split(/\)\s*$/)[0])
124
+ # Clean the values content while preserving complex JSON
125
+ cleaned_values = clean_complex_values(values_content)
117
126
 
118
127
  # Reassemble the statement
119
- statement = "#{parts[0]}VALUES (#{values})"
128
+ statement = "#{pre_values}#{cleaned_values}#{post_values}"
129
+ statement += ";" unless statement.end_with?(";")
120
130
  end
121
131
  end
122
-
123
- # Add back the conflict clause if it existed
124
- statement += " #{conflict_clause}" if conflict_clause
125
- statement += ";"
126
-
127
132
  statement
128
133
  end
129
134
 
130
- def extract_conflict_clause(statement)
131
- if statement =~ /(.+?)(\s+ON\s+CONFLICT\s+.*?)(?:;?\s*$)/i
132
- [$1, $2.strip]
133
- else
134
- [statement.sub(/;?\s*$/, ''), nil]
135
+ def clean_complex_values(values_str)
136
+ current_value = ''
137
+ values = []
138
+ in_quotes = false
139
+ in_json = false
140
+ json_brace_count = 0
141
+
142
+ chars = values_str.chars
143
+ i = 0
144
+ while i < chars.length
145
+ char = chars[i]
146
+
147
+ case char
148
+ when "'"
149
+ # Check if this is an escaped quote
150
+ if i > 0 && chars[i-1] != '\\'
151
+ in_quotes = !in_quotes
152
+ end
153
+ current_value << char
154
+ when '{'
155
+ if !in_quotes
156
+ in_json = true
157
+ json_brace_count += 1
158
+ end
159
+ current_value << char
160
+ when '}'
161
+ if !in_quotes
162
+ json_brace_count -= 1
163
+ in_json = json_brace_count > 0
164
+ end
165
+ current_value << char
166
+ when ','
167
+ if !in_quotes && !in_json
168
+ values << clean_value(current_value.strip)
169
+ current_value = ''
170
+ else
171
+ current_value << char
172
+ end
173
+ else
174
+ current_value << char
175
+ end
176
+ i += 1
135
177
  end
178
+
179
+ # Add the last value
180
+ values << clean_value(current_value.strip) unless current_value.strip.empty?
181
+
182
+ values.join(', ')
136
183
  end
137
184
 
138
185
  def clean_values(values_str)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RealDataTests
4
- VERSION = "0.3.7"
4
+ VERSION = "0.3.9"
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.7
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dias