jrubysql 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ test/test.db
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ JRubySQL Changelog
2
+ ==================
3
+
4
+ 0.1.3
5
+ -----
6
+ * SQLite type support
7
+ * There are issues with autocommit though
8
+ * Tests
9
+ * --execute option
10
+ * Bug fix: line comment parsing error
11
+ * Bug fix: Invalid autocommit value can be set
12
+
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :test do
5
+ #watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
6
+ watch(%r{^test/test_.+\.rb$})
7
+ end
data/README.md CHANGED
@@ -14,8 +14,8 @@ Usage
14
14
 
15
15
  ```
16
16
  usage: jrubysql [options]
17
- jrubysql -t DBMS_TYPE -h HOSTNAME [-u USERNAME -p [PASSWORD] [-d DATABASE]] [-f FILENAME]
18
- jrubysql -c CLASSNAME -j JDBC_URL [-u USERNAME -p [PASSWORD] [-d DATABASE]] [-f FILENAME]
17
+ jrubysql -t DBMS_TYPE -h HOSTNAME [-u USERNAME] [-p [PASSWORD]] [-d DATABASE]
18
+ jrubysql -c CLASSNAME -j JDBC_URL [-u USERNAME] [-p [PASSWORD]] [-d DATABASE]
19
19
 
20
20
  -t, --type DBMS_TYPE Database type: mysql/oracle/postgres/sqlserver
21
21
  -h, --host HOST DBMS host address
@@ -28,6 +28,7 @@ usage: jrubysql [options]
28
28
  -d, --database DATABASE Name of the database (optional)
29
29
 
30
30
  -f, --filename FILENAME SQL script file
31
+ -e, --execute SQLSCRIPT SQL script
31
32
  -o, --output OUTPUT_TYPE Output type: cterm|term|csv (default: cterm)
32
33
 
33
34
  --help Show this message
@@ -47,20 +48,27 @@ export CLASSPATH=$CLASSPATH:~/lib/mysql-connector-java-5.1.17-bin.jar:~/lib/ojdb
47
48
  ### With type (-t) and hostname (-h)
48
49
 
49
50
  ```
50
- # Supports MySQL/Oracle/PostgreSQL/MSSQL
51
+ # Supports MySQL/Oracle/PostgreSQL/MSSQL/SQLite
51
52
 
52
53
  jrubysql -t mysql -h localhost -d test -u user -p
53
54
  jrubysql -t oracle -h localhost:1521/orcl -u user -p password
54
55
  jrubysql -t postgres -h localhost -u root
55
- jrubysql -t sqlserver -h 192.168.62.26 -u user -p password
56
+ jrubysql -t sqlserver -h localhost -u user -p password
57
+ jrubysql -t sqlite -h my.db
58
+ # In case of SQLite, Host = DB file
56
59
  ```
57
60
 
58
61
  ### Connect with class name of JDBC driver (-c) and JDBC URL (-j)
59
62
 
60
63
  ```
61
64
  # You can connect to any database with its JDBC driver
65
+ # SQLite
66
+ bin/jrubysql -c org.sqlite.JDBC -j jdbc:sqlite:my.db
62
67
 
68
+ # PostgreSQL
63
69
  bin/jrubysql -corg.postgresql.Driver -jjdbc:postgresql://localhost/test
70
+
71
+ # MySQL
64
72
  bin/jrubysql -ccom.mysql.jdbc.Driver -jjdbc:mysql://localhost/test -uuser -p
65
73
  ```
66
74
 
@@ -68,10 +76,6 @@ Screenshot
68
76
  ----------
69
77
  ![](https://github.com/junegunn/jrubysql/raw/master/screenshots/simpsons.png)
70
78
 
71
- TODO
72
- ----
73
- TESTS!!!
74
-
75
79
  Copyright
76
80
  ---------
77
81
  Copyright (c) 2012 Junegunn Choi. See LICENSE.txt for
data/jrubysql.gemspec CHANGED
@@ -20,6 +20,9 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  s.add_development_dependency "test-unit"
23
+ s.add_development_dependency "mocha"
24
+ s.add_development_dependency "guard"
25
+ s.add_development_dependency "guard-test"
23
26
 
24
27
  s.add_runtime_dependency "jdbc-helper", '~> 0.7.2'
25
28
  s.add_runtime_dependency "insensitive_hash", '~> 0.2.3'
@@ -4,9 +4,8 @@ require 'fileutils'
4
4
  module JRubySQL
5
5
  # A simple key-value config in YAML
6
6
  class Config
7
- DEFAULT_PATH = File.join(ENV['HOME'], '.jrubysqlrc')
8
7
 
9
- def initialize path = DEFAULT_PATH
8
+ def initialize path = JRubySQL::Constants::DEFAULT_RC_PATH
10
9
  @path = path
11
10
  if @path && File.exists?(@path)
12
11
  @yaml = YAML.load(File.read(@path))
@@ -1,13 +1,14 @@
1
1
  module JRubySQL
2
2
  module Constants
3
- SUPPORTED_DBMS_TYPES = [ :mysql, :oracle, :postgres, :sqlserver ]
3
+ SUPPORTED_DBMS_TYPES = [ :mysql, :oracle, :postgres, :sqlserver, :sqlite ]
4
4
 
5
5
  # .jrubysqlrc
6
- MAX_COMMAND_HISTORY = 100
6
+ DEFAULT_RC_PATH = File.join(ENV['HOME'], '.jrubysqlrc')
7
7
  MAX_CONNECTION_HISTORY = 10
8
+ # MAX_COMMAND_HISTORY = 100
8
9
 
9
10
  # Terminal (TBD)
10
- MAX_COLUMN_WIDTH = 80
11
+ # MAX_COLUMN_WIDTH = 80
11
12
  MIN_SCREEN_ROWS = 10
12
13
  MAX_SCREEN_ROWS = 50
13
14
 
@@ -20,7 +20,7 @@ class Controller
20
20
  puts "[#{idx + 1}] #{history.first}"
21
21
  end
22
22
  print '> '
23
- select = $stdin.gets
23
+ select = JRubySQL::Controller.get_console_input
24
24
  select = select && select.chomp
25
25
  if (1..(histories.length)).include?(select.to_i)
26
26
  history = histories[select.to_i - 1]
@@ -40,7 +40,9 @@ class Controller
40
40
 
41
41
  # Setting up input: file or console (and more?)
42
42
  if @options[:filename]
43
- @input = JRubySQL::Input::File.new(self, @options[:filename])
43
+ @input = JRubySQL::Input::Script.new(self, ::File.read(@options[:filename]))
44
+ elsif @options[:script]
45
+ @input = JRubySQL::Input::Script.new(self, @options[:script])
44
46
  else
45
47
  @input = JRubySQL::Input::Console.new(self)
46
48
  end
@@ -101,6 +103,10 @@ class Controller
101
103
  end
102
104
 
103
105
  private
106
+ def self.get_console_input
107
+ $stdin.gets
108
+ end
109
+
104
110
  def output result
105
111
  @output.print_result result
106
112
  end
@@ -120,7 +126,7 @@ private
120
126
  when :autocommit
121
127
  if params.nil?
122
128
  @output.info m(:current_autocommit, @rdbms.autocommit ? 'on' : 'off')
123
- elsif %[on off].include?(params.downcase)
129
+ elsif %w[on off].include?(params.downcase)
124
130
  @rdbms.autocommit = params.downcase == 'on'
125
131
  @output.info m(:turn_autocommit, params.downcase)
126
132
  else
@@ -26,7 +26,7 @@ class Console
26
26
  { :commands => [cmd].compact }
27
27
  # Line with delimiters
28
28
  elsif line.include?(@esql.delimiter)
29
- @esql << line + ' '
29
+ @esql << line + $/
30
30
  result = @esql.shift
31
31
  result[:sqls].each do |sql|
32
32
  Readline::HISTORY << sql + @esql.delimiter
@@ -34,7 +34,7 @@ class Console
34
34
  { :sqls => result[:sqls] }
35
35
  # SQL without delimiter
36
36
  else
37
- @esql << line + ' '
37
+ @esql << line + $/
38
38
  empty_response
39
39
  end
40
40
  )
@@ -2,10 +2,9 @@ require 'each_sql'
2
2
 
3
3
  module JRubySQL
4
4
  module Input
5
- class File
6
- def initialize controller, file_path
5
+ class Script
6
+ def initialize controller, script
7
7
  @controller = controller
8
- script = ::File.read(file_path)
9
8
  sqls = EachSQL(script, JRubySQL::Input.get_each_sql_type(@controller.db_type))
10
9
  @ret = { :sqls => sqls }
11
10
  end
@@ -14,6 +14,8 @@ invalid output:
14
14
  Invalid output type.
15
15
  file not found:
16
16
  "File not found: $$"
17
+ both script and filename:
18
+ Cannot specify both filename and script.
17
19
 
18
20
  connecting:
19
21
  Connecting to the database ...
@@ -13,12 +13,12 @@ module OptionParser
13
13
  opts.banner =
14
14
  [
15
15
  "usage: jrubysql [options]",
16
- " jrubysql -t DBMS_TYPE -h HOSTNAME [-u USERNAME -p [PASSWORD] [-d DATABASE]] [-f FILENAME]",
17
- " jrubysql -c CLASSNAME -j JDBC_URL [-u USERNAME -p [PASSWORD] [-d DATABASE]] [-f FILENAME]"
16
+ " jrubysql -t DBMS_TYPE -h HOSTNAME [-u USERNAME] [-p [PASSWORD]] [-d DATABASE]",
17
+ " jrubysql -c CLASSNAME -j JDBC_URL [-u USERNAME] [-p [PASSWORD]] [-d DATABASE]"
18
18
  ].join($/)
19
19
  opts.separator ''
20
20
 
21
- opts.on('-t', '--type DBMS_TYPE', 'Database type: mysql/oracle/postgres/sqlserver') do |v|
21
+ opts.on('-t', '--type DBMS_TYPE', 'Database type: mysql/oracle/postgres/sqlserver/sqlite') do |v|
22
22
  options[:type] = v.downcase.to_sym
23
23
  end
24
24
 
@@ -56,6 +56,10 @@ module OptionParser
56
56
  options[:filename] = v
57
57
  end
58
58
 
59
+ opts.on('-e', '--execute SQLSCRIPT', 'SQL script') do |v|
60
+ options[:script] = v
61
+ end
62
+
59
63
  opts.on('-o', '--output OUTPUT_TYPE', 'Output type: cterm|term|csv (default: cterm)') do |v|
60
64
  options[:output] = v
61
65
  end
@@ -96,6 +100,10 @@ private
96
100
  raise ArgumentError.new m(:invalid_output)
97
101
  end
98
102
 
103
+ if opts[:script] && opts[:filename]
104
+ raise ArgumentError.new m(:both_script_and_filename)
105
+ end
106
+
99
107
  if (!opts[:type] && !opts[:driver]) || (opts[:type] && opts[:driver])
100
108
  raise ArgumentError.new m(:invalid_connection)
101
109
  end
@@ -25,9 +25,6 @@ class CSV
25
25
  def print_cursor empty; end
26
26
 
27
27
  def print_result ret
28
- # Footer
29
- elapsed = "(#{'%.2f' % ret[:elapsed]} sec)"
30
-
31
28
  if ret[:set?]
32
29
  ret[:result].each_with_index do |row, idx|
33
30
  puts ::CSV.generate_line(row.labels) if idx == 0
@@ -14,6 +14,8 @@ class RDBMS
14
14
  :postgres
15
15
  when /sqlserver/
16
16
  :sqlserver
17
+ when /sqlite/
18
+ :sqlite
17
19
  else
18
20
  :unknown
19
21
  end
@@ -40,6 +42,15 @@ class RDBMS
40
42
  when :sqlserver
41
43
  JDBCHelper::SqlServerConnector.connect(
42
44
  options[:host], options[:user], options[:password], options[:database])
45
+ when :sqlite
46
+ JDBCHelper::Connection.new(
47
+ {
48
+ :driver => 'org.sqlite.JDBC',
49
+ :url => "jdbc:sqlite:#{options[:host]}",
50
+ :user => options[:user],
51
+ :password => options[:password]
52
+ }.reject { |k, v| v.nil? }
53
+ )
43
54
  end
44
55
  elsif options[:driver]
45
56
  JDBCHelper::Connection.new(
@@ -48,7 +59,7 @@ class RDBMS
48
59
  :url => options[:url],
49
60
  :user => options[:user],
50
61
  :password => options[:password]
51
- }.reject { |k, v| v.nil? }
62
+ }.reject { |k, v| v.nil? }
52
63
  )
53
64
  else
54
65
  raise ArgumentError.new m(:invalid_connection)
@@ -1,3 +1,3 @@
1
1
  module JRubySQL
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/jrubysql.rb CHANGED
@@ -12,7 +12,7 @@ require 'jrubysql/rdbms'
12
12
  require 'jrubysql/option_parser'
13
13
  require 'jrubysql/input/input'
14
14
  require 'jrubysql/input/console'
15
- require 'jrubysql/input/file'
15
+ require 'jrubysql/input/script'
16
16
  require 'jrubysql/output/csv'
17
17
  require 'jrubysql/output/term'
18
18
  require 'jrubysql/output/cterm'
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ ENV['BUNDLE_GEMFILE'] = File.join(File.dirname(__FILE__), '..', 'Gemfile')
4
+ Bundler.setup(:default, :development)
5
+ require 'test/unit'
6
+ require 'mocha'
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ require 'jrubysql'
9
+
10
+ module JRubySQLTestHelper
11
+ JRubySQL::Constants.const_set :DEFAULT_RC_PATH, '/tmp/.jrubysqlrc'
12
+
13
+ def capture &block
14
+ begin
15
+ $stdout = StringIO.new
16
+ $stderr = StringIO.new
17
+
18
+ begin
19
+ ret = block.call
20
+ rescue SystemExit => x
21
+ ret = x.status
22
+ end
23
+
24
+ return {
25
+ :stdout => $stdout.string,
26
+ :stderr => $stderr.string,
27
+ :return => ret
28
+ }
29
+ ensure
30
+ $stdout = STDOUT
31
+ $stderr = STDERR
32
+ end
33
+ end
34
+ end
@@ -1,9 +1,214 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- ENV['BUNDLE_GEMFILE'] = File.join(File.dirname(__FILE__), '..', 'Gemfile')
4
- Bundler.setup(:default, :development)
5
- require 'test/unit'
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ require 'helper'
7
2
 
3
+ # Acceptance test
8
4
  class TestJRubySQL < Test::Unit::TestCase
5
+ include JRubySQLTestHelper
6
+
7
+ def test_help
8
+ queue "
9
+ help
10
+ exit
11
+ "
12
+ ret = capture { launch }
13
+ assert_equal 0, ret[:return]
14
+ assert_match /Display this message/, ret[:stdout]
15
+ assert_match /Goodbye!/, ret[:stdout]
16
+
17
+ assert_prev_conn
18
+ end
19
+
20
+ def test_delimiter
21
+ queue "
22
+ select 1 from dual where 1 = 0;
23
+ delimiter //
24
+ select 1 -- //
25
+ from /* // */ dual
26
+ where 1 = 0 //
27
+ //
28
+ //
29
+ //
30
+ delimiter ;
31
+ select 1 from dual where 1 = 0;
32
+ exit
33
+ "
34
+ ret = capture { launch }
35
+
36
+ assert_equal 3, ret[:stdout].scan(/0 row/).length
37
+ assert_match /Goodbye!/, ret[:stdout]
38
+
39
+ assert_prev_conn
40
+ end
41
+
42
+ def test_autocommit
43
+ queue "
44
+ drop table if exists jrubysql;
45
+ create table if not exists jrubysql (a int) engine=innodb;
46
+ autocommit
47
+
48
+ insert
49
+ into /* ;;; */
50
+ jrubysql
51
+ values (1);
52
+
53
+ autocommit off
54
+
55
+ insert into -- ;;;
56
+ jrubysql values (2);
57
+
58
+ insert into jrubysql values (3);
59
+ select count(*) from jrubysql;
60
+ rollback;
61
+ select count(*) from jrubysql;
62
+ autocommit
63
+ autocommit on
64
+ autocommit
65
+ drop table jrubysql;
66
+ exit
67
+ "
68
+ # ANSI codes make it difficult to test
69
+ ret = capture { launch [ '-o', 'term' ] }
70
+
71
+ assert_equal %w[0 0 1 1 1 0 0], ret[:stdout].scan(/([0-9]+) rows? affected/).map(&:first)
72
+ assert_equal %w[on off on], ret[:stdout].scan(/Current autocommit: (on|off)/).map(&:first)
73
+ assert_equal %w[off on], ret[:stdout].scan(/Turning autocommit (on|off)/).map(&:first)
74
+ assert_equal %w[3 1], ret[:stdout].scan(/^\| ([0-9]+)/).map(&:first)
75
+
76
+ assert_prev_conn /-o term/
77
+ end
78
+
79
+ def test_now
80
+ queue "
81
+ now
82
+ now
83
+ now
84
+ exit
85
+ "
86
+ ret = capture { launch }
87
+ ymd = %r|#{Time.now.strftime('%Y/%m/%d %H')}:[0-9]{2}:[0-9]{2}.[0-9]{3}|
88
+ assert_equal 3, ret[:stdout].scan(ymd).count
89
+
90
+ assert_prev_conn
91
+ end
92
+
93
+ def test_csv
94
+ queue "
95
+ drop table if exists jrubysql;
96
+ create table if not exists jrubysql (a int, b varchar(100), c varchar(100), d varchar(100));
97
+ insert into jrubysql values (100, 'abc', 'def', 'ghi');
98
+ insert into jrubysql values (200, 'x,y,z', null, '');
99
+ select * from jrubysql order by a;
100
+ drop table jrubysql;
101
+ drop table jrubysql;
102
+ exit
103
+ "
104
+ ret = capture { launch [ '-ocsv' ] }
105
+
106
+ assert_equal [
107
+ 'a,b,c,d',
108
+ '100,abc,def,ghi',
109
+ '200,"x,y,z",,""' ], ret[:stdout].lines.map(&:chomp)
110
+ # CSV prints error messages to STDERR
111
+ assert_match /Unknown table/, ret[:stderr]
112
+
113
+ assert_prev_conn /-ocsv/
114
+ end
115
+
116
+ def test_plural
117
+ queue "
118
+ drop table if exists jrubysql;
119
+ create table if not exists jrubysql (a int);
120
+ update jrubysql set a = 0;
121
+ insert into jrubysql values (1);
122
+ update jrubysql set a = 2;
123
+ insert into jrubysql values (3);
124
+ update jrubysql set a = 4;
125
+ drop table jrubysql;
126
+ exit;
127
+ "
128
+ ret = capture { launch }
129
+
130
+ assert_equal [
131
+ '0 row',
132
+ '0 row',
133
+ '0 row',
134
+ '1 row',
135
+ '1 row',
136
+ '1 row',
137
+ '2 rows',
138
+ '0 row'
139
+ ], ret[:stdout].scan(/([0-9]+ rows?) affected/).map(&:first)
140
+
141
+ assert_prev_conn
142
+ end
143
+
144
+ def test_file
145
+ require 'tempfile'
146
+ tf = Tempfile.new('jrubysql')
147
+ tf << "select 1 from dual where 1 = 0"
148
+ tf.flush
149
+
150
+ ret = capture { launch ['-f', tf.path] }
151
+ assert_equal 1, ret[:stdout].scan(/0 row/).count
152
+
153
+ assert_prev_conn /-f/
154
+ end
155
+
156
+ def test_script
157
+ ret = capture { launch ['-e', "select 1 from dual where 1 = 0; select 1 from dual where 1 = 0"] }
158
+ assert_equal 2, ret[:stdout].scan(/0 row/).count
159
+
160
+ assert_prev_conn /-e/
161
+ end
162
+
163
+ def test_using_connection_history
164
+ queue "
165
+ drop table if exists jrubysql;
166
+ create table if not exists jrubysql (a int);
167
+ insert into jrubysql values (999);
168
+ exit
169
+ "
170
+ capture { launch ['-ocsv'] }
171
+
172
+ # FIXME: private static method
173
+ JRubySQL::Controller.expects(:get_console_input).returns('1')
174
+ queue "
175
+ select * from jrubysql;
176
+ drop table jrubysql;
177
+ exit
178
+ "
179
+ ret = capture { JRubySQL.launch [] }
180
+ assert_equal '999', ret[:stdout].lines.map(&:chomp)[-1]
181
+
182
+ assert_prev_conn /csv/
183
+ end
184
+
185
+ def test_interrupt
186
+ pend do
187
+ assert false, 'Need to test interrupt signal handling'
188
+ end
189
+ end
190
+
191
+ private
192
+ def assert_prev_conn command = nil
193
+ prev_conn = JRubySQL::Config.new['connections'].first
194
+ # assert_equal :sqlite, prev_conn.last[:type]
195
+ # assert_match 'test.db', prev_conn.last[:host]
196
+ assert_equal :mysql, prev_conn.last[:type]
197
+ assert_match 'localhost', prev_conn.last[:host]
198
+
199
+ if command
200
+ assert_match command, prev_conn.first
201
+ end
202
+ end
203
+
204
+ def queue str
205
+ lines = str.strip.lines.map { |s| s.strip }
206
+ Readline.expects(:readline).times(lines.length).returns(*lines)
207
+ end
208
+
209
+ def launch argv = []
210
+ # db = File.join( File.dirname(__FILE__), 'test.db' )
211
+ # JRubySQL.launch ['-tsqlite', '-h', db ] + argv
212
+ JRubySQL.launch %w[-tmysql -hlocalhost -dtest] + argv
213
+ end
9
214
  end
@@ -0,0 +1,122 @@
1
+ require 'helper'
2
+
3
+ class TestOptionParser < Test::Unit::TestCase
4
+ include JRubySQLTestHelper
5
+
6
+ def test_dbms_type
7
+ # No host
8
+ assert_error /Invalid connection/, parse(%w[-t mysql])
9
+ assert_error /Invalid connection/, parse(%w[--type mysql])
10
+
11
+ # No type
12
+ assert_error /Invalid connection/, parse(%w[-h localhost])
13
+ assert_error /Invalid connection/, parse(%w[--host localhost])
14
+
15
+ # Invalid type
16
+ assert_error /not supported/, parse(%w[-t yoursql -h localhost])
17
+
18
+ # Optional options
19
+ opts = parse(%w[-t MySQL -h localhost])
20
+ assert_equal :mysql, opts[:type]
21
+ assert_equal 'localhost', opts[:host]
22
+
23
+ opts = parse(%w[-t MySQL -h localhost -uroot])
24
+ assert_equal :mysql, opts[:type]
25
+ assert_equal 'localhost', opts[:host]
26
+ assert_equal 'root', opts[:user]
27
+
28
+ opts = parse(%w[-t MySQL -h localhost -uroot -dtest])
29
+ assert_equal :mysql, opts[:type]
30
+ assert_equal 'localhost', opts[:host]
31
+ assert_equal 'root', opts[:user]
32
+ assert_equal 'test', opts[:database]
33
+
34
+ [
35
+ %w[-t mysql -h localhost -u username -p password -d database -o csv],
36
+ %w[--type mysql --host localhost --user username --password password --database database --output csv]
37
+ ].each do |argv|
38
+ opts = parse(argv)
39
+ assert_equal :mysql, opts[:type]
40
+ assert_equal 'localhost', opts[:host]
41
+ assert_equal 'username', opts[:user]
42
+ assert_equal 'password', opts[:password]
43
+ assert_equal 'database', opts[:database]
44
+ assert_equal 'csv', opts[:output]
45
+ end
46
+ end
47
+
48
+ def test_class_name
49
+ # No JDBC URL
50
+ assert_error /Invalid connection/, parse(%w[-c com.mysql.jdbc.Driver])
51
+ assert_error /Invalid connection/, parse(%w[--class-name com.mysql.jdbc.Driver])
52
+
53
+ # No class name
54
+ assert_error /Invalid connection/, parse(%w[-j jdbc:mysql://localhost/test])
55
+ assert_error /Invalid connection/, parse(%w[--jdbc-url jdbc:mysql://localhost/test])
56
+
57
+ [
58
+ %w[-c com.mysql.jdbc.Driver -j jdbc:mysql://localhost -u username -p password -d database -o cterm],
59
+ %w[--class-name com.mysql.jdbc.Driver --jdbc-url jdbc:mysql://localhost
60
+ --user username --password password --database database --output cterm]
61
+ ].each do |argv|
62
+ opts = parse(argv)
63
+ assert_equal 'com.mysql.jdbc.Driver', opts[:driver]
64
+ assert_equal 'jdbc:mysql://localhost', opts[:url]
65
+ assert_equal 'username', opts[:user]
66
+ assert_equal 'password', opts[:password]
67
+ assert_equal 'database', opts[:database]
68
+ assert_equal 'cterm', opts[:output]
69
+ end
70
+ end
71
+
72
+ def test_invalid_output
73
+ assert_error /Invalid output/, parse(%w[-t mysql -h localhost -o xml])
74
+ end
75
+
76
+ def test_invalid_combination
77
+ assert_error /Invalid connection/, parse(%w[-t mysql -j jdbc:mysql://localhost])
78
+ assert_error /Invalid connection/, parse(%w[-c com.mysql.jdbc.Driver -h localhost])
79
+
80
+ assert_error /both filename and script/, parse(%w[-f aaa -e bbb])
81
+ end
82
+
83
+ def test_filename
84
+ assert_error /File not found/, parse(%w[-t mysql -h localhost -f no-such-file.sql])
85
+
86
+ opts = parse(%w[-t mysql -h localhost -f] + [__FILE__])
87
+ assert_equal __FILE__, opts[:filename]
88
+
89
+ opts = parse(%w[-t mysql -h localhost --filename] + [__FILE__])
90
+ assert_equal __FILE__, opts[:filename]
91
+ end
92
+
93
+ def test_script
94
+ opts = parse(%w[-t mysql -h localhost -e commit])
95
+ assert_equal 'commit', opts[:script]
96
+
97
+ opts = parse(%w[-t mysql -h localhost --execute commit])
98
+ assert_equal 'commit', opts[:script]
99
+ end
100
+
101
+ def test_password_input
102
+ # FIXME: ask_password is a private method. any better way?
103
+ JRubySQL::OptionParser.expects(:ask_password).returns('password')
104
+ opts = parse(%w[-t mysql -h localhost -p])
105
+ assert_equal 'password', opts[:password]
106
+ end
107
+
108
+ def parse argv
109
+ parse_with_output(argv)[:return]
110
+ end
111
+
112
+ def parse_with_output argv
113
+ capture { JRubySQL::OptionParser.parse(argv) }
114
+ end
115
+
116
+ def assert_error msg, argv
117
+ ret = parse_with_output argv
118
+ assert_equal 1, ret[:return]
119
+ assert msg, ret[:stdout] =~ msg
120
+ end
121
+ end
122
+
metadata CHANGED
@@ -1,206 +1,204 @@
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.1
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.3
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: 2012-03-15 00:00:00.000000000Z
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: '0'
21
- none: false
22
- requirement: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- none: false
28
- prerelease: false
29
- type: :development
30
- - !ruby/object:Gem::Dependency
31
- name: jdbc-helper
32
- version_requirements: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - ~>
35
- - !ruby/object:Gem::Version
36
- version: 0.7.2
37
- none: false
38
- requirement: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- version: 0.7.2
43
- none: false
44
- prerelease: false
45
- type: :runtime
46
- - !ruby/object:Gem::Dependency
47
- name: insensitive_hash
48
- version_requirements: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - ~>
51
- - !ruby/object:Gem::Version
52
- version: 0.2.3
53
- none: false
54
- requirement: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ~>
57
- - !ruby/object:Gem::Version
58
- version: 0.2.3
59
- none: false
60
- prerelease: false
61
- type: :runtime
62
- - !ruby/object:Gem::Dependency
63
- name: tabularize
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: 0.1.1
69
- none: false
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ~>
73
- - !ruby/object:Gem::Version
74
- version: 0.1.1
75
- none: false
76
- prerelease: false
77
- type: :runtime
78
- - !ruby/object:Gem::Dependency
79
- name: each_sql
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ~>
83
- - !ruby/object:Gem::Version
84
- version: 0.3.1
85
- none: false
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ~>
89
- - !ruby/object:Gem::Version
90
- version: 0.3.1
91
- none: false
92
- prerelease: false
93
- type: :runtime
94
- - !ruby/object:Gem::Dependency
95
- name: highline
96
- version_requirements: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - ~>
99
- - !ruby/object:Gem::Version
100
- version: 1.6.11
101
- none: false
102
- requirement: !ruby/object:Gem::Requirement
103
- requirements:
104
- - - ~>
105
- - !ruby/object:Gem::Version
106
- version: 1.6.11
107
- none: false
108
- prerelease: false
109
- type: :runtime
110
- - !ruby/object:Gem::Dependency
111
- name: ansi
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ~>
115
- - !ruby/object:Gem::Version
116
- version: 1.4.2
117
- none: false
118
- requirement: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - ~>
121
- - !ruby/object:Gem::Version
122
- version: 1.4.2
123
- none: false
124
- prerelease: false
125
- type: :runtime
126
- - !ruby/object:Gem::Dependency
127
- name: erubis
128
- version_requirements: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - ~>
131
- - !ruby/object:Gem::Version
132
- version: 2.7.0
133
- none: false
134
- requirement: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ~>
137
- - !ruby/object:Gem::Version
138
- version: 2.7.0
139
- none: false
140
- prerelease: false
141
- type: :runtime
12
+
13
+ date: 2012-03-28 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"
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.7.2
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.2.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.1.1
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.3.1
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.11
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.2
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
142
136
  description: An SQL client for any JDBC-compliant database. Written in JRuby.
143
- email:
144
- - junegunn.c@gmail.com
145
- executables:
146
- - jrubysql
137
+ email:
138
+ - junegunn.c@gmail.com
139
+ executables:
140
+ - jrubysql
147
141
  extensions: []
142
+
148
143
  extra_rdoc_files: []
149
- files:
150
- - .gitignore
151
- - Gemfile
152
- - LICENSE.txt
153
- - README.md
154
- - Rakefile
155
- - bin/jrubysql
156
- - jrubysql.gemspec
157
- - lib/jrubysql.rb
158
- - lib/jrubysql/config.rb
159
- - lib/jrubysql/constants.rb
160
- - lib/jrubysql/controller.rb
161
- - lib/jrubysql/doc/help.txt.erb
162
- - lib/jrubysql/input/console.rb
163
- - lib/jrubysql/input/file.rb
164
- - lib/jrubysql/input/input.rb
165
- - lib/jrubysql/messages.rb
166
- - lib/jrubysql/messages.yml
167
- - lib/jrubysql/option_parser.rb
168
- - lib/jrubysql/output/csv.rb
169
- - lib/jrubysql/output/cterm.rb
170
- - lib/jrubysql/output/term.rb
171
- - lib/jrubysql/rdbms.rb
172
- - lib/jrubysql/version.rb
173
- - test/test_cterm.rb
174
- - test/test_jrubysql.rb
175
- - test/test_option_parser.rb
176
- - test/test_term_output.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/csv.rb
167
+ - lib/jrubysql/output/cterm.rb
168
+ - lib/jrubysql/output/term.rb
169
+ - lib/jrubysql/rdbms.rb
170
+ - lib/jrubysql/version.rb
171
+ - test/helper.rb
172
+ - test/test_jrubysql.rb
173
+ - test/test_option_parser.rb
177
174
  homepage: https://github.com/junegunn/jrubysql
178
175
  licenses: []
179
- post_install_message:
176
+
177
+ post_install_message:
180
178
  rdoc_options: []
181
- require_paths:
182
- - lib
183
- required_ruby_version: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ! '>='
186
- - !ruby/object:Gem::Version
187
- version: '0'
179
+
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
188
183
  none: false
189
- required_rubygems_version: !ruby/object:Gem::Requirement
190
- requirements:
191
- - - ! '>='
192
- - !ruby/object:Gem::Version
193
- version: '0'
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: "0"
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
189
  none: false
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: "0"
195
194
  requirements: []
195
+
196
196
  rubyforge_project: jrubysql
197
- rubygems_version: 1.8.18
198
- signing_key:
197
+ rubygems_version: 1.8.21
198
+ signing_key:
199
199
  specification_version: 3
200
200
  summary: An SQL client for any JDBC-compliant database.
201
- test_files:
202
- - test/test_cterm.rb
203
- - test/test_jrubysql.rb
204
- - test/test_option_parser.rb
205
- - test/test_term_output.rb
206
- ...
201
+ test_files:
202
+ - test/helper.rb
203
+ - test/test_jrubysql.rb
204
+ - test/test_option_parser.rb
data/test/test_cterm.rb DELETED
File without changes
File without changes