jrubysql 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/jrubysql.gemspec CHANGED
@@ -24,11 +24,11 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "guard"
25
25
  s.add_development_dependency "guard-test"
26
26
 
27
- s.add_runtime_dependency "jdbc-helper", '~> 0.7.4'
28
- s.add_runtime_dependency "insensitive_hash", '~> 0.3.0'
29
- s.add_runtime_dependency "tabularize", '~> 0.2.4'
30
- s.add_runtime_dependency "each_sql", '~> 0.3.1'
31
- s.add_runtime_dependency "highline", '~> 1.6.11'
32
- s.add_runtime_dependency "ansi", '~> 1.4.2'
27
+ s.add_runtime_dependency "jdbc-helper", '~> 0.8.0'
28
+ s.add_runtime_dependency "insensitive_hash", '~> 0.3.3'
29
+ s.add_runtime_dependency "tabularize", '~> 0.2.9'
30
+ s.add_runtime_dependency "each_sql", '~> 0.4.0'
31
+ s.add_runtime_dependency "highline", '~> 1.6.19'
32
+ s.add_runtime_dependency "ansi", '~> 1.4.3'
33
33
  s.add_runtime_dependency "erubis", '~> 2.7.0'
34
34
  end
@@ -160,6 +160,15 @@ private
160
160
  else
161
161
  @output.error m(:invalid_autocommit, params)
162
162
  end
163
+ when :display
164
+ params = params.downcase
165
+ if %w[table pairs].include? params
166
+ if @output.respond_to?(:display_mode=)
167
+ @output.display_mode = params.to_sym
168
+ end
169
+ else
170
+ @output.error m(:invalid_display)
171
+ end
163
172
  else
164
173
  # TODO
165
174
  @output.error m(:unknown_command)
@@ -6,5 +6,6 @@
6
6
  <SQL> Execute the SQL.
7
7
  autocommit [<on|off>] Show/enable/disable autocommit. (default: on)
8
8
  delimiter <DELIMITER> Change SQL delimiter.
9
+ display [table|pairs] Change display style.
9
10
  now Display current timestamp.
10
11
  exit Exit JRubySQL.
@@ -77,6 +77,8 @@ private
77
77
  { :autocommit => $1 }
78
78
  when 'now'
79
79
  { :now => nil }
80
+ when /^display (\S+)(#{Regexp.escape delimiter})?$/
81
+ { :display => $1 }
80
82
  when /^(exit|quit)(#{Regexp.escape delimiter})?$/
81
83
  { :quit => nil }
82
84
  else
@@ -19,6 +19,9 @@ file not found:
19
19
  both script and filename:
20
20
  Cannot specify both filename and script.
21
21
 
22
+ invalid display:
23
+ "Invalid display type: must be table or pairs"
24
+
22
25
  connecting:
23
26
  Connecting to the database ...
24
27
  connected:
@@ -18,7 +18,7 @@ class CTerm < Term
18
18
  File.join(
19
19
  File.dirname(__FILE__), "color_scheme/default.yml"))).merge(colors || {})
20
20
 
21
- @ccode = @colors.inject(Hash.new('')) { |h, pair|
21
+ @ccode = @colors.inject(Hash.new('')) { |h, pair|
22
22
  k, v = pair
23
23
  h[k.to_sym] = v.strip.split(/\s+/).map { |code| ANSI::Code.send(code) rescue '' }.join
24
24
  h
@@ -31,7 +31,7 @@ class CTerm < Term
31
31
 
32
32
  def cursor empty
33
33
  if empty
34
- wrap('jrubysql', @ccode[:prompt1]) +
34
+ wrap('jrubysql', @ccode[:prompt1]) +
35
35
  wrap('> ', @ccode[:prompt2])
36
36
  else
37
37
  wrap(' -', @ccode[:prompt3]) +
@@ -100,7 +100,7 @@ private
100
100
  def wrap text, color
101
101
  color + text + (color.empty? ? '' : reset)
102
102
  end
103
-
103
+
104
104
  end#CTerm
105
105
  end#Output
106
106
  end#JRubySQL
@@ -27,6 +27,7 @@ class Term
27
27
  [ terminal.getTerminalWidth, terminal.getTerminalHeight ]
28
28
  end
29
29
  }
30
+ self.display_mode = :table
30
31
  trap 'INT' do
31
32
  Thread.main.raise Interrupt
32
33
  end
@@ -76,7 +77,7 @@ class Term
76
77
 
77
78
  if ret[:set?]
78
79
  begin
79
- cnt = print_table ret[:result]
80
+ cnt = send(@printer, ret[:result])
80
81
  result m(:rows_returned, cnt, cnt > 1 ? 's' : '', elapsed)
81
82
  rescue Interrupt
82
83
  warn m(:interrupted)
@@ -90,13 +91,35 @@ class Term
90
91
  puts
91
92
  end
92
93
 
94
+ def display_mode= mode
95
+ @printer = "print_#{mode}".to_sym
96
+ end
97
+
93
98
  private
99
+ def print_pairs ret
100
+ cnt = 0
101
+ ret.each do |row|
102
+ labels = row.labels.map { |e| e + ': ' }
103
+ max_label_len = labels.map(&:length).max
104
+ pairs = labels.zip row.to_a
105
+ pairs.each_with_index do |pair, idx|
106
+ print (idx == 0) ? '- ' : ' '
107
+ l, v = pair
108
+ print l.ljust(max_label_len, ' ')
109
+ puts v.to_s
110
+ end
111
+ puts
112
+ cnt += 1
113
+ end
114
+ cnt
115
+ end
116
+
94
117
  def print_table ret, tabularize_opts = {}
95
118
  cnt = 0
96
119
  term_size = @get_terminal_size.call
97
- lines = [(term_size.call[1] rescue JRubySQL::Constants::MAX_SCREEN_ROWS) - 5,
120
+ lines = [(term_size[1] rescue JRubySQL::Constants::MAX_SCREEN_ROWS) - 5,
98
121
  JRubySQL::Constants::MIN_SCREEN_ROWS].max
99
- cols = (term_size.call[0] rescue nil)
122
+ cols = (term_size[0] rescue nil)
100
123
  ret.each_slice(lines) do |slice|
101
124
  cnt += slice.length
102
125
 
@@ -1,3 +1,3 @@
1
1
  module JRubySQL
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/test/bin_helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # encoding: utf-8
3
3
  # junegunn.c@gmail.com
4
4
 
5
- # DISCLAIMER:
5
+ # DISCLAIMER:
6
6
  # Not a real test!
7
7
  # Just a helper script for running scripts with local source
8
8
 
metadata CHANGED
@@ -1,264 +1,207 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jrubysql
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.7
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.8
6
6
  platform: ruby
7
- authors:
8
- - Junegunn Choi
9
- autorequire:
7
+ authors:
8
+ - Junegunn Choi
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: test-unit
16
- version_requirements: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ! '>='
19
- - !ruby/object:Gem::Version
20
- version: !binary |-
21
- MA==
22
- none: false
23
- requirement: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ! '>='
26
- - !ruby/object:Gem::Version
27
- version: !binary |-
28
- MA==
29
- none: false
30
- prerelease: false
31
- type: :development
32
- - !ruby/object:Gem::Dependency
33
- name: mocha
34
- version_requirements: !ruby/object:Gem::Requirement
35
- requirements:
36
- - - ~>
37
- - !ruby/object:Gem::Version
38
- version: 0.11.0
39
- none: false
40
- requirement: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- version: 0.11.0
45
- none: false
46
- prerelease: false
47
- type: :development
48
- - !ruby/object:Gem::Dependency
49
- name: guard
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: !binary |-
55
- MA==
56
- none: false
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: !binary |-
62
- MA==
63
- none: false
64
- prerelease: false
65
- type: :development
66
- - !ruby/object:Gem::Dependency
67
- name: guard-test
68
- version_requirements: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - ! '>='
71
- - !ruby/object:Gem::Version
72
- version: !binary |-
73
- MA==
74
- none: false
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ! '>='
78
- - !ruby/object:Gem::Version
79
- version: !binary |-
80
- MA==
81
- none: false
82
- prerelease: false
83
- type: :development
84
- - !ruby/object:Gem::Dependency
85
- name: jdbc-helper
86
- version_requirements: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ~>
89
- - !ruby/object:Gem::Version
90
- version: 0.7.4
91
- none: false
92
- requirement: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ~>
95
- - !ruby/object:Gem::Version
96
- version: 0.7.4
97
- none: false
98
- prerelease: false
99
- type: :runtime
100
- - !ruby/object:Gem::Dependency
101
- name: insensitive_hash
102
- version_requirements: !ruby/object:Gem::Requirement
103
- requirements:
104
- - - ~>
105
- - !ruby/object:Gem::Version
106
- version: 0.3.0
107
- none: false
108
- requirement: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ~>
111
- - !ruby/object:Gem::Version
112
- version: 0.3.0
113
- none: false
114
- prerelease: false
115
- type: :runtime
116
- - !ruby/object:Gem::Dependency
117
- name: tabularize
118
- version_requirements: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - ~>
121
- - !ruby/object:Gem::Version
122
- version: 0.2.4
123
- none: false
124
- requirement: !ruby/object:Gem::Requirement
125
- requirements:
126
- - - ~>
127
- - !ruby/object:Gem::Version
128
- version: 0.2.4
129
- none: false
130
- prerelease: false
131
- type: :runtime
132
- - !ruby/object:Gem::Dependency
133
- name: each_sql
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ~>
137
- - !ruby/object:Gem::Version
138
- version: 0.3.1
139
- none: false
140
- requirement: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - ~>
143
- - !ruby/object:Gem::Version
144
- version: 0.3.1
145
- none: false
146
- prerelease: false
147
- type: :runtime
148
- - !ruby/object:Gem::Dependency
149
- name: highline
150
- version_requirements: !ruby/object:Gem::Requirement
151
- requirements:
152
- - - ~>
153
- - !ruby/object:Gem::Version
154
- version: 1.6.11
155
- none: false
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - ~>
159
- - !ruby/object:Gem::Version
160
- version: 1.6.11
161
- none: false
162
- prerelease: false
163
- type: :runtime
164
- - !ruby/object:Gem::Dependency
165
- name: ansi
166
- version_requirements: !ruby/object:Gem::Requirement
167
- requirements:
168
- - - ~>
169
- - !ruby/object:Gem::Version
170
- version: 1.4.2
171
- none: false
172
- requirement: !ruby/object:Gem::Requirement
173
- requirements:
174
- - - ~>
175
- - !ruby/object:Gem::Version
176
- version: 1.4.2
177
- none: false
178
- prerelease: false
179
- type: :runtime
180
- - !ruby/object:Gem::Dependency
181
- name: erubis
182
- version_requirements: !ruby/object:Gem::Requirement
183
- requirements:
184
- - - ~>
185
- - !ruby/object:Gem::Version
186
- version: 2.7.0
187
- none: false
188
- requirement: !ruby/object:Gem::Requirement
189
- requirements:
190
- - - ~>
191
- - !ruby/object:Gem::Version
192
- version: 2.7.0
193
- none: false
194
- prerelease: false
195
- type: :runtime
12
+
13
+ date: 2013-09-12 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: test-unit
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: mocha
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.11.0
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: guard
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: guard-test
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: jdbc-helper
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 0.8.0
68
+ type: :runtime
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: insensitive_hash
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 0.3.3
79
+ type: :runtime
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: tabularize
83
+ prerelease: false
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.9
90
+ type: :runtime
91
+ version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
93
+ name: each_sql
94
+ prerelease: false
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ~>
99
+ - !ruby/object:Gem::Version
100
+ version: 0.4.0
101
+ type: :runtime
102
+ version_requirements: *id008
103
+ - !ruby/object:Gem::Dependency
104
+ name: highline
105
+ prerelease: false
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 1.6.19
112
+ type: :runtime
113
+ version_requirements: *id009
114
+ - !ruby/object:Gem::Dependency
115
+ name: ansi
116
+ prerelease: false
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: 1.4.3
123
+ type: :runtime
124
+ version_requirements: *id010
125
+ - !ruby/object:Gem::Dependency
126
+ name: erubis
127
+ prerelease: false
128
+ requirement: &id011 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 2.7.0
134
+ type: :runtime
135
+ version_requirements: *id011
196
136
  description: SQL client for any JDBC-compliant database. Written in JRuby.
197
- email:
198
- - junegunn.c@gmail.com
199
- executables:
200
- - jrubysql
137
+ email:
138
+ - junegunn.c@gmail.com
139
+ executables:
140
+ - jrubysql
201
141
  extensions: []
142
+
202
143
  extra_rdoc_files: []
203
- files:
204
- - .gitignore
205
- - CHANGELOG.md
206
- - Gemfile
207
- - Guardfile
208
- - LICENSE.txt
209
- - README.md
210
- - Rakefile
211
- - bin/jrubysql
212
- - jrubysql.gemspec
213
- - lib/jrubysql.rb
214
- - lib/jrubysql/config.rb
215
- - lib/jrubysql/constants.rb
216
- - lib/jrubysql/controller.rb
217
- - lib/jrubysql/doc/help.txt.erb
218
- - lib/jrubysql/input/console.rb
219
- - lib/jrubysql/input/input.rb
220
- - lib/jrubysql/input/script.rb
221
- - lib/jrubysql/messages.rb
222
- - lib/jrubysql/messages.yml
223
- - lib/jrubysql/option_parser.rb
224
- - lib/jrubysql/output/color_scheme/default.yml
225
- - lib/jrubysql/output/csv.rb
226
- - lib/jrubysql/output/cterm.rb
227
- - lib/jrubysql/output/term.rb
228
- - lib/jrubysql/rdbms.rb
229
- - lib/jrubysql/version.rb
230
- - test/bin_helper.rb
231
- - test/helper.rb
232
- - test/test_jrubysql.rb
233
- - test/test_option_parser.rb
144
+
145
+ files:
146
+ - .gitignore
147
+ - CHANGELOG.md
148
+ - Gemfile
149
+ - Guardfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - bin/jrubysql
154
+ - jrubysql.gemspec
155
+ - lib/jrubysql.rb
156
+ - lib/jrubysql/config.rb
157
+ - lib/jrubysql/constants.rb
158
+ - lib/jrubysql/controller.rb
159
+ - lib/jrubysql/doc/help.txt.erb
160
+ - lib/jrubysql/input/console.rb
161
+ - lib/jrubysql/input/input.rb
162
+ - lib/jrubysql/input/script.rb
163
+ - lib/jrubysql/messages.rb
164
+ - lib/jrubysql/messages.yml
165
+ - lib/jrubysql/option_parser.rb
166
+ - lib/jrubysql/output/color_scheme/default.yml
167
+ - lib/jrubysql/output/csv.rb
168
+ - lib/jrubysql/output/cterm.rb
169
+ - lib/jrubysql/output/term.rb
170
+ - lib/jrubysql/rdbms.rb
171
+ - lib/jrubysql/version.rb
172
+ - test/bin_helper.rb
173
+ - test/helper.rb
174
+ - test/test_jrubysql.rb
175
+ - test/test_option_parser.rb
234
176
  homepage: https://github.com/junegunn/jrubysql
235
177
  licenses: []
236
- post_install_message:
178
+
179
+ post_install_message:
237
180
  rdoc_options: []
238
- require_paths:
239
- - lib
240
- required_ruby_version: !ruby/object:Gem::Requirement
241
- requirements:
242
- - - ! '>='
243
- - !ruby/object:Gem::Version
244
- version: !binary |-
245
- MA==
181
+
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
246
185
  none: false
247
- required_rubygems_version: !ruby/object:Gem::Requirement
248
- requirements:
249
- - - ! '>='
250
- - !ruby/object:Gem::Version
251
- version: !binary |-
252
- MA==
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: "0"
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
253
191
  none: false
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: "0"
254
196
  requirements: []
197
+
255
198
  rubyforge_project: jrubysql
256
199
  rubygems_version: 1.8.24
257
- signing_key:
200
+ signing_key:
258
201
  specification_version: 3
259
202
  summary: SQL client for any JDBC-compliant database.
260
- test_files:
261
- - test/bin_helper.rb
262
- - test/helper.rb
263
- - test/test_jrubysql.rb
264
- - test/test_option_parser.rb
203
+ test_files:
204
+ - test/bin_helper.rb
205
+ - test/helper.rb
206
+ - test/test_jrubysql.rb
207
+ - test/test_option_parser.rb