sbfaulkner-rsql 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rsql/odbc.rb +7 -4
- data/lib/rsql/rsql.rb +13 -2
- data/rsql.gemspec +1 -1
- metadata +1 -1
data/lib/rsql/odbc.rb
CHANGED
@@ -38,7 +38,6 @@ module ODBC
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def print(aliases = nil)
|
41
|
-
|
42
41
|
# get the column names, etc.
|
43
42
|
displayed_columns = columns(true)
|
44
43
|
|
@@ -58,6 +57,8 @@ module ODBC
|
|
58
57
|
# TODO: handle huge result sets better... maybe paginate or base column width on initial n-record set
|
59
58
|
resultset = fetch_all
|
60
59
|
|
60
|
+
return 0 if resultset.nil? || resultset.empty?
|
61
|
+
|
61
62
|
case self.class.mode
|
62
63
|
when 'column'
|
63
64
|
# determine the column widths (might be realy slow with large result sets)
|
@@ -68,7 +69,7 @@ module ODBC
|
|
68
69
|
c.width = value.length if value.length > c.width
|
69
70
|
end
|
70
71
|
end
|
71
|
-
end
|
72
|
+
end
|
72
73
|
|
73
74
|
# prepare the horizontal rule for header and footer
|
74
75
|
rule = "+-" + displayed_columns.collect { |c| '-' * c.width }.join("-+-") + "-+"
|
@@ -80,7 +81,7 @@ module ODBC
|
|
80
81
|
# output each row
|
81
82
|
resultset.each do |r|
|
82
83
|
puts "| " + displayed_columns.collect { |c| r[c.index].to_s.ljust(c.width, ' ') }.join(" | ") + " |"
|
83
|
-
end
|
84
|
+
end
|
84
85
|
|
85
86
|
# output footer
|
86
87
|
puts rule
|
@@ -90,8 +91,10 @@ module ODBC
|
|
90
91
|
# output each row
|
91
92
|
resultset.each do |r|
|
92
93
|
puts displayed_columns.collect { |c| r[c.index].to_s }.to_csv(:force_quotes => true)
|
93
|
-
end
|
94
|
+
end
|
94
95
|
end
|
96
|
+
|
97
|
+
return resultset.size
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
data/lib/rsql/rsql.rb
CHANGED
@@ -47,7 +47,18 @@ module RSQL
|
|
47
47
|
begin
|
48
48
|
@database.run(command) do |result|
|
49
49
|
begin
|
50
|
-
result.
|
50
|
+
if result.ncols > 0
|
51
|
+
case nrows = result.print
|
52
|
+
when 0
|
53
|
+
puts "Empty set" unless OPTIONS[:quiet]
|
54
|
+
when 1
|
55
|
+
puts "1 row in set" unless OPTIONS[:quiet]
|
56
|
+
else
|
57
|
+
puts "#{nrows} rows in set" unless OPTIONS[:quiet]
|
58
|
+
end
|
59
|
+
else
|
60
|
+
puts "#{result.nrows} #{result.nrows == 1 ? 'row' : 'rows'} affected" unless OPTIONS[:quiet]
|
61
|
+
end
|
51
62
|
rescue
|
52
63
|
raise
|
53
64
|
ensure
|
@@ -267,7 +278,7 @@ module RSQL
|
|
267
278
|
# quiet-mode wins over verbose-mode
|
268
279
|
OPTIONS.delete :verbose if OPTIONS[:quiet]
|
269
280
|
|
270
|
-
puts "#{COMMAND} v0.9.
|
281
|
+
puts "#{COMMAND} v0.9.9 - Copyright (c) 2007-2008 unwwwired.net" unless OPTIONS[:quiet]
|
271
282
|
|
272
283
|
begin
|
273
284
|
# use dsn if provided
|
data/rsql.gemspec
CHANGED