skylight 0.4.1 → 0.4.2

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
  SHA1:
3
- metadata.gz: 766b35710e2c5cc91f17df574ceb6ae2d99c476a
4
- data.tar.gz: 9145a148d2b08e8d4c74e283d57cb922664d72b2
3
+ metadata.gz: 01262f190b63ef103a1e1bc671f3a98ff12798f6
4
+ data.tar.gz: d0fcae9d16a2fcff34cad93d33f16a4fcb4b8113
5
5
  SHA512:
6
- metadata.gz: 29c0ae3e1fea0b3e180fdbf6a1db5e9818783f4ea46241101afa0e8d601c9dee6100f7432e89b03f0c6318f981227f160da197f2a17108683919301f95a295c0
7
- data.tar.gz: fb823dc8938a5db2292a9ab10aedb2269f00bb180605a55dee8844d12dfbda4f7b722e5b79f1e8d53e34eca641875433efd669f03eb5a6b4bf95749ccd6ac49d
6
+ metadata.gz: acbb99369ebb3807ac990756d6606d99d86a716cf81b6bf0f6a4cc83d0832916da010d374e926435c3012044c572b4222e480bfba8f3bfcabf9a740538edb1ee
7
+ data.tar.gz: 8ed42b17470c205f40ef6c37c45572b1d84449d914ac9047bff2c7707b47e23bd537bf158bcce6f6898340d5342776992686fde8109538b59f795ee3e273b314
@@ -1,3 +1,8 @@
1
+ ## 0.4.2 (November 12, 2014)
2
+
3
+ * [BUGFIX] Fix exit status on MRI 1.9.2
4
+ * [BUGFIX] Strip SQL comments for better aggregation
5
+
1
6
  ## 0.4.1 (November 7, 2014)
2
7
 
3
8
  * [BUGFIX] Fix downloading native agent on 32bit systems
@@ -60,7 +60,18 @@ module Skylight
60
60
  end
61
61
  end
62
62
 
63
- at_exit { stop! }
63
+ at_exit do
64
+ if RUBY_VERSION == '1.9.2'
65
+ # workaround for MRI bug losing exit status in at_exit block
66
+ # http://bugs.ruby-lang.org/issues/5218
67
+ exit_status = $!.status if $!.is_a?(SystemExit)
68
+ stop!
69
+ exit exit_status if exit_status
70
+ else
71
+ stop!
72
+ end
73
+ end
74
+
64
75
 
65
76
  attr_reader :config, :gc, :trace_info
66
77
 
@@ -39,7 +39,7 @@ module Skylight
39
39
 
40
40
  private
41
41
  def extract_binds(payload, precalculated)
42
- title, sql, binds = SqlLexer::Lexer.bindify(payload[:sql], precalculated)
42
+ title, sql, binds = SqlLexer::Lexer.bindify(payload[:sql], precalculated, true)
43
43
  [ title, sql, binds, nil ]
44
44
  rescue => e
45
45
  group = "sql_parse"
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
4
4
 
@@ -108,9 +108,9 @@ module SqlLexer
108
108
  array: :process_array
109
109
  }
110
110
 
111
- def self.bindify(string, binds=nil)
111
+ def self.bindify(string, binds=nil, strip_comments=false)
112
112
  scanner = instance(string)
113
- scanner.process(binds)
113
+ scanner.process(binds, strip_comments)
114
114
  [scanner.title, scanner.output, scanner.binds]
115
115
  end
116
116
 
@@ -176,8 +176,8 @@ module SqlLexer
176
176
  PLACEHOLDER = "?".freeze
177
177
  UNKNOWN = "<unknown>".freeze
178
178
 
179
- def process(binds)
180
- process_comments
179
+ def process(binds, strip_comments)
180
+ process_comments(strip_comments)
181
181
 
182
182
  @operation = nil
183
183
  @provided_binds = binds
@@ -220,9 +220,33 @@ module SqlLexer
220
220
  nil
221
221
  end
222
222
 
223
- EMPTY = "".freeze
223
+ def replace_comment(pos, length, strip)
224
+ if strip
225
+ # Dup the string if necessary so we aren't destructive to the original value
226
+ if @input == @original_input
227
+ @input = @input.dup
228
+ @scanner.string = @input
229
+ end
230
+
231
+ # Replace the comment with a space to ensure valid SQL
232
+ # Updating the input also updates the scanner
233
+ @input[pos, length] = SPACE
234
+ @output[pos, length] = SPACE
235
+
236
+ # Move back to start of removed string
237
+ @scanner.pos = pos
238
+ else
239
+ # Dup the string if necessary so we aren't destructive to the original value
240
+ @scanner.string = @input.dup if @scanner.string == @original_input
241
+
242
+ # Replace the comment with spaces
243
+ @scanner.string[pos, length] = SPACE*length
244
+ end
245
+ end
246
+
247
+ def process_comments(strip_comments)
248
+ @original_input = @input
224
249
 
225
- def process_comments
226
250
  # SQL treats comments as similar to whitespace
227
251
  # Here we replace all comments with spaces of the same length so as to not affect binds
228
252
 
@@ -256,10 +280,7 @@ module SqlLexer
256
280
  if count == 0
257
281
  # We've closed all comments
258
282
  length = @scanner.charpos - pos
259
- # Dup the string if necessary so we aren't destructive to the original value
260
- @scanner.string = @input.dup if @scanner.string == @input
261
- # Replace the comment with spaces
262
- @scanner.string[pos, length] = SPACE*length
283
+ replace_comment(pos, length, strip_comments)
263
284
  break
264
285
  end
265
286
  end
@@ -271,10 +292,7 @@ module SqlLexer
271
292
  while @scanner.skip_until(TkComment)
272
293
  pos = @scanner.charpos
273
294
  len = @scanner.matched_size
274
- # Dup the string if necessary so we aren't destructive to the original value
275
- @scanner.string = @input.dup if @scanner.string == @input
276
- # Replace the comment with spaces
277
- @scanner.string[pos-len, len] = SPACE*len
295
+ replace_comment(pos-len, len, strip_comments)
278
296
  end
279
297
 
280
298
  @scanner.reset
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport