rsql 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rsql CHANGED
@@ -428,6 +428,18 @@ Signal.trap('INT') do
428
428
  cmd_thread.kill
429
429
  end
430
430
 
431
+ Signal.trap('CHLD') do
432
+ $stderr.puts "SSH child (#{ssh_pid}) stopped--shutting down..."
433
+ if cmd_thread[:running] && MySQLResults.conn
434
+ $stderr.puts 'Interrupting MySQL query...'
435
+ safe_timeout(MySQLResults.conn, :close, 'MySQL')
436
+ MySQLResults.conn = nil
437
+ end
438
+ cmd_thread[:shutdown] = true
439
+ sleep(0.3)
440
+ cmd_thread.kill
441
+ end
442
+
431
443
  begin
432
444
  cmd_thread.join
433
445
  rescue Exception => ex
@@ -451,6 +463,11 @@ if Readline::HISTORY.any?
451
463
  end
452
464
 
453
465
  if ssh_pid && 0 <= ssh_pid
454
- Process.kill('INT', ssh_pid)
455
- Process.waitpid(ssh_pid)
466
+ begin
467
+ Process.kill('INT', ssh_pid)
468
+ Process.waitpid(ssh_pid)
469
+ rescue Exception => ex
470
+ $stderr.puts ex.message
471
+ $stderr.puts ex.backtrace if verbose
472
+ end
456
473
  end
data/lib/rsql.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Commands using an EvalContext for handling recipes.
3
3
  #
4
4
  module RSQL
5
- VERSION = '0.2.2'
5
+ VERSION = '0.2.3'
6
6
 
7
7
  require 'rsql/mysql_results'
8
8
  require 'rsql/eval_context'
data/lib/rsql/commands.rb CHANGED
@@ -64,7 +64,7 @@ module RSQL
64
64
  sep = nil
65
65
  end
66
66
 
67
- if esc.any?
67
+ unless esc.empty?
68
68
  esc << match
69
69
  match = esc
70
70
  esc = ''
@@ -177,7 +177,7 @@ module RSQL
177
177
  displayer = @default_displayer
178
178
  end
179
179
 
180
- if content.any?
180
+ unless content.empty?
181
181
  @cmds << Command.new(content, bangs, declarator, displayer)
182
182
  return true
183
183
  end
@@ -100,7 +100,6 @@ module RSQL
100
100
  end
101
101
 
102
102
  def reload
103
- MySQLResults.reset_cache
104
103
  @loaded_fns.each{|fn| self.load(fn, false)}
105
104
  puts "loaded: #{@loaded_fns.inspect}"
106
105
  end
@@ -108,7 +107,7 @@ module RSQL
108
107
  def bang_eval(field, val)
109
108
  if bang = @bangs[field]
110
109
  begin
111
- val = Thread.new{ eval("$SAFE=2;#{bang}(val)") }.value
110
+ val = Thread.new{ eval("#{bang}(val)") }.value
112
111
  rescue Exception => ex
113
112
  $stderr.puts(ex.message, ex.backtrace.first)
114
113
  end
@@ -153,7 +152,7 @@ module RSQL
153
152
  # that we have file/line info, we need to rescue their
154
153
  # exceptions inside the evaluation
155
154
  th = Thread.new do
156
- eval('$SAFE=2;begin;' << content << %q{
155
+ eval('begin;' << content << %q{
157
156
  rescue Exception => ex
158
157
  if @verbose
159
158
  $stderr.puts("#{ex.class}: #{ex.message}", ex.backtrace)
@@ -223,7 +222,7 @@ module RSQL
223
222
  end
224
223
  limit -= 1
225
224
  end
226
- '%02x' % ch[0]
225
+ '%02x' % ch.bytes.first
227
226
  end
228
227
 
229
228
  if limit && limit < 1 && 0 < cnt
@@ -358,13 +357,14 @@ module RSQL
358
357
  next unless ending || i == lineno
359
358
  source << line
360
359
  unless ending
361
- unless m = line.match(/\{|do/)
360
+ unless m = line.match(/\{|do\b/)
362
361
  $stderr.puts "unable to locate block beginning at #{fn}:#{lineno}"
363
362
  return
364
363
  end
365
364
  ending = m[0] == '{' ? '\}' : 'end'
366
365
  next
367
366
  end
367
+
368
368
  if m = line.match(/^#{ending}/)
369
369
  found = true
370
370
  break
@@ -379,7 +379,7 @@ module RSQL
379
379
  end
380
380
  end
381
381
 
382
- if reg.source && reg.source.any?
382
+ if reg.source && !reg.source.empty?
383
383
  puts reg.source
384
384
  else
385
385
  $stderr.puts "unable to locate body for #{sym}"
@@ -440,7 +440,7 @@ module RSQL
440
440
  argstr = args.join(',')
441
441
  usage << "(#{argstr})" unless argstr.empty?
442
442
 
443
- blockstr = %{$SAFE=2;lambda{|#{argstr}|%{#{sql}} % [#{argstr}]}}
443
+ blockstr = %{lambda{|#{argstr}|%{#{sql}} % [#{argstr}]}}
444
444
  block = Thread.new{ eval(blockstr) }.value
445
445
  args = []
446
446
  else
@@ -260,7 +260,7 @@ module RSQL
260
260
  # we set this here so that (a) it occurs _after_ we are
261
261
  # successful and so we can show an appropriate messge in a
262
262
  # displayer
263
- if @sql.match(/use\s+(\S+)/)
263
+ if @sql.match(/use\s+(\S+)/i)
264
264
  @database_changed = true
265
265
  @@database_name = $1
266
266
  end
@@ -53,7 +53,7 @@ class TestCommands < Test::Unit::TestCase
53
53
 
54
54
  # make sure our logic to handle eval'd blocks with args works
55
55
  @strout.string = ''
56
- cmds = Commands.new('. Proc.new{|a| p a} | @results.value.call(:fancy)', :display_by_column)
56
+ cmds = Commands.new('. Proc.new{|a| puts a.inspect} | @results.value.call(:fancy)', :display_by_column)
57
57
  cmds.run!(@ctx)
58
58
  assert_equal(':fancy', @strout.string.chomp)
59
59
  end
@@ -61,7 +61,7 @@ class TestCommands < Test::Unit::TestCase
61
61
  def test_multiple
62
62
  @conn.expects(:query).with('one thing').returns(nil)
63
63
  @conn.expects(:affected_rows).returns(1)
64
- cmds = Commands.new('. "one thing" ; . p :hello', :display_by_column)
64
+ cmds = Commands.new('. "one thing" ; . puts :hello.inspect', :display_by_column)
65
65
  cmds.run!(@ctx)
66
66
  assert_match(/^QueryOK,1rowaffected\(\d+.\d+sec\):hello$/,
67
67
  @strout.string.gsub(/\s+/,''))
@@ -28,7 +28,6 @@ class TestEvalContext < Test::Unit::TestCase
28
28
  end
29
29
 
30
30
  def test_load
31
- @conn.expects(:list_dbs).returns([])
32
31
  orig = $stdout
33
32
  $stdout = out = StringIO.new
34
33
  @ctx.safe_eval('reload', nil, out)
@@ -97,8 +96,10 @@ class TestEvalContext < Test::Unit::TestCase
97
96
  assert_equal('', out.string)
98
97
  assert_equal('refusing to describe the version method', err.string.chomp)
99
98
 
99
+ err.string = ''
100
100
  out.string = ''
101
101
  val = @ctx.safe_eval('desc :cleanup_example', nil, out)
102
+ assert_equal('', err.string)
102
103
  assert_equal('DROP TEMPORARY TABLE IF EXISTS #{@rsql_table}', out.string.strip)
103
104
 
104
105
  out.string = ''
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsql
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brad Robel-Forrest
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-25 00:00:00 Z
18
+ date: 2011-09-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: net-ssh