rsql 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -14,13 +14,13 @@ to an intermediary host for access to the SQL server.
14
14
  gem install rsql
15
15
 
16
16
  Alternatively, RSQL can be downloaded as a tar.gz or zip and run
17
- directly from within the unpacked source directory. The only
18
- requirement is that SSH functionality will be disabled unless the
19
- Net::SSH Ruby library is installed and available.
17
+ directly from within the unpacked source directory as long as the
18
+ MySQL Ruby library is available. SSH functionality will be disabled
19
+ unless the Net::SSH Ruby library is also installed and available.
20
20
 
21
21
  == USAGE
22
22
 
23
- RSQL is invoked from the comamnd line using:
23
+ RSQL is invoked from the command line using:
24
24
 
25
25
  rsql [<options>] <mysql_host> [<database>] [-e [<query>]]
26
26
 
@@ -40,7 +40,7 @@ RSQL is invoked from the comamnd line using:
40
40
  Override the maximum number of rows to process.
41
41
 
42
42
  -batch _field_separator_::
43
- Run in batch mode using the separator specifed (e.g. a /t will
43
+ Run in batch mode using the separator specified (e.g. a /t will
44
44
  separate fields with a tab character).
45
45
 
46
46
  -ssh _ssh_host_::
@@ -79,10 +79,10 @@ the colon and the at sign):
79
79
 
80
80
  Connect as the "readonly" user to the "internal.database.acme.com"
81
81
  host's MySQL server after establishing a SSH tunnel to the
82
- "external.acme.com" gateway. In this case, we are either expecting
83
- that our SSH configuration is set up with the right user name. Because
84
- we did not provide a password for MySQL, one will be obtained directly
85
- from the console (without echoing the characters typed):
82
+ "external.acme.com" gateway. In this case, we are expecting that our
83
+ SSH configuration is set up with the right user name. Because we did
84
+ not provide a password for MySQL, one will be obtained directly from
85
+ the console (without echoing the characters typed):
86
86
 
87
87
  rsql -ssh external.acme.com readonly@internal.database.acme.com
88
88
 
data/example.rsqlrc CHANGED
@@ -124,7 +124,7 @@ SELECT name, value FROM #{@rsql_table} WHERE #{val} <= value
124
124
  # So the command in our history is the recipe and not the query. To
125
125
  # see the query the EvalContext has a recipe ready for us:
126
126
  #
127
- # rsql> .last_query;
127
+ # rsql> .history;
128
128
  #
129
129
  register :bad_query, %q{
130
130
  SELECT name, value FROM #{@rsql_table} WHERE valu < 10000
@@ -222,6 +222,10 @@ end
222
222
  # serializes our object so that we may later decided to run some post
223
223
  # processing on the content.
224
224
  #
225
+ # Inspect the YAML content written out:
226
+ #
227
+ # rsql> .puts IO.read('myobj.yml');
228
+ #
225
229
  register :save_values, :desc => 'Save results from a query into a file.' do |fn|
226
230
  myobj = {}
227
231
  @results.each_hash do |row|
@@ -37,7 +37,6 @@ module RSQL
37
37
  @verbose = verbose
38
38
  @hexstr_limit = HEXSTR_LIMIT
39
39
  @results = nil
40
- @last_query = nil
41
40
 
42
41
  @loaded_fns = []
43
42
  @init_registrations = []
@@ -45,29 +44,29 @@ module RSQL
45
44
 
46
45
  @registrations = {
47
46
  :version => Registration.new('version', [], {},
48
- method(:version),
49
- 'version',
50
- 'RSQL version information.'),
47
+ method(:version),
48
+ 'version',
49
+ 'Version information about RSQL, the client, and the server.'),
51
50
  :reload => Registration.new('reload', [], {},
52
- method(:reload),
53
- 'reload',
54
- 'Reload the rsqlrc file.'),
51
+ method(:reload),
52
+ 'reload',
53
+ 'Reload the rsqlrc file.'),
55
54
  :desc => Registration.new('desc', [], {},
56
- method(:desc),
57
- 'desc',
58
- 'Describe the content of a recipe.'),
59
- :last_query => Registration.new('last_query', [], {},
60
- Proc.new{puts(@last_query)},
61
- 'last_query',
62
- 'Print the last query made from generated results.'),
55
+ method(:desc),
56
+ 'desc',
57
+ 'Describe the content of a recipe.'),
58
+ :history => Registration.new('history', [], {},
59
+ method(:history),
60
+ 'history(cnt=1)',
61
+ 'Print recent queries made (request a count or use :all for entire list).'),
63
62
  :set_max_rows => Registration.new('set_max_rows', [], {},
64
- Proc.new{|r| MySQLResults.max_rows = r},
65
- 'set_max_rows',
66
- 'Set the maximum number of rows to process.'),
63
+ Proc.new{|r| MySQLResults.max_rows = r},
64
+ 'set_max_rows',
65
+ 'Set the maximum number of rows to process.'),
67
66
  :max_rows => Registration.new('max_rows', [], {},
68
- Proc.new{MySQLResults.max_rows},
69
- 'max_rows',
70
- 'Get the maximum number of rows to process.'),
67
+ Proc.new{MySQLResults.max_rows},
68
+ 'max_rows',
69
+ 'Get the maximum number of rows to process.'),
71
70
  }
72
71
  end
73
72
 
@@ -176,8 +175,6 @@ module RSQL
176
175
  $stdout = orig_stdout if stdout
177
176
  end
178
177
 
179
- @last_query = value if String === value
180
-
181
178
  return value
182
179
  end
183
180
 
@@ -264,7 +261,10 @@ module RSQL
264
261
  return nil
265
262
  end
266
263
 
267
- def params(block)
264
+ # Attempt to locate the parameters of a given block by
265
+ # searching its source.
266
+ #
267
+ def params(name, block)
268
268
  params = ''
269
269
 
270
270
  if block.arity != 0 && block.arity != -1 &&
@@ -273,7 +273,7 @@ module RSQL
273
273
  lineno = $2.to_i
274
274
 
275
275
  if fn == '(eval)'
276
- $stderr.puts 'refusing to search an eval block'
276
+ $stderr.puts "refusing to search an eval block for :#{name}"
277
277
  return params
278
278
  end
279
279
 
@@ -288,7 +288,7 @@ module RSQL
288
288
  # give up if no start found within 20
289
289
  # lines
290
290
  break if lineno + 20 < i
291
- if m = line.match(/(\{|do)(.*)$/)
291
+ if m = line.match(/(\{|do\b)(.*)$/)
292
292
  # adjust line to be the remainder
293
293
  # after the start
294
294
  line = m[2]
@@ -308,7 +308,7 @@ module RSQL
308
308
  # this block doesn't have params...even
309
309
  # though arity says it should
310
310
  next if line.match(/^\s*$/)
311
- $stderr.puts 'unable to locate params'
311
+ $stderr.puts "unable to locate params for :#{name}"
312
312
  break
313
313
  end
314
314
  end
@@ -401,6 +401,13 @@ module RSQL
401
401
  MySQLResults.query(content, self, *args)
402
402
  end
403
403
 
404
+ def history(cnt=1)
405
+ if h = MySQLResults.history(cnt)
406
+ h.each{|q| puts '', q}
407
+ end
408
+ nil
409
+ end
410
+
404
411
  # Exactly like register below except in addition to registering as
405
412
  # a usable call for later, we will also use these as soon as we
406
413
  # have a connection to MySQL.
@@ -438,7 +445,7 @@ module RSQL
438
445
  args = []
439
446
  else
440
447
  source = nil
441
- usage << params(block)
448
+ usage << params(name, block)
442
449
  end
443
450
 
444
451
  @registrations[sym] = Registration.new(name, args, bangs, block, usage, desc, source)
@@ -37,7 +37,9 @@ module RSQL
37
37
  @@field_separator = ' '
38
38
  @@max_rows = 1000
39
39
  @@database_name = nil
40
- @@name_cache = {}
40
+ @@name_cache = {}
41
+ @@history = []
42
+ @@max_history = 10
41
43
 
42
44
  class MaxRowsException < RangeError
43
45
  def initialize(rows, max)
@@ -89,6 +91,24 @@ module RSQL
89
91
  #
90
92
  def database_name=(database); @@database_name = database; end
91
93
 
94
+ # Get a list of the most recent query strings.
95
+ #
96
+ def history(cnt=:all)
97
+ if Integer === cnt
98
+ @@history[-cnt,cnt]
99
+ else
100
+ @@history
101
+ end
102
+ end
103
+
104
+ # Get the maximum number of historical entries to retain.
105
+ #
106
+ def get_max_history; @@max_history; end
107
+
108
+ # Set the maximum number of historical entries to retain.
109
+ #
110
+ def set_max_history=(count); @@max_history = count; end
111
+
92
112
  # Get the list of databases available.
93
113
  #
94
114
  def databases
@@ -163,6 +183,9 @@ module RSQL
163
183
  # Get results from a query.
164
184
  #
165
185
  def query(sql, eval_context, raw=false, max_rows=@@max_rows)
186
+ @@history.shift if @@max_history <= @@history.size
187
+ @@history << sql
188
+
166
189
  start = Time.now.to_f
167
190
  results = @@conn.query(sql)
168
191
  elapsed = Time.now.to_f - start.to_f
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.1'
5
+ VERSION = '0.2.2'
6
6
 
7
7
  require 'rsql/mysql_results'
8
8
  require 'rsql/eval_context'
@@ -65,9 +65,9 @@ class TestEvalContext < Test::Unit::TestCase
65
65
  end
66
66
 
67
67
  def test_params
68
- val = @ctx.safe_eval('params(@registrations[:fill_table].block)', nil, nil)
68
+ val = @ctx.safe_eval('params("ft", @registrations[:fill_table].block)', nil, nil)
69
69
  assert_equal('', val)
70
- val = @ctx.safe_eval('params(@registrations[:save_values].block)', nil, nil)
70
+ val = @ctx.safe_eval('params("sv", @registrations[:save_values].block)', nil, nil)
71
71
  assert_equal('(fn)', val)
72
72
  end
73
73
 
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
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-24 00:00:00 Z
18
+ date: 2011-09-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: net-ssh