taps 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 15
2
+ :patch: 16
3
3
  :major: 0
4
4
  :minor: 2
@@ -120,6 +120,7 @@ class ClientSession
120
120
  count = table.count
121
121
  order = Taps::Utils.order_by(db, table_name)
122
122
  chunksize = self.default_chunksize
123
+ string_columns = Taps::Utils.incorrect_blobs(db, table_name)
123
124
 
124
125
  progress = ProgressBar.new(table_name.to_s, count)
125
126
 
@@ -127,7 +128,7 @@ class ClientSession
127
128
  loop do
128
129
  row_size = 0
129
130
  chunksize = Taps::Utils.calculate_chunksize(chunksize) do |c|
130
- rows = Taps::Utils.format_data(table.order(*order).limit(c, offset).all)
131
+ rows = Taps::Utils.format_data(table.order(*order).limit(c, offset).all, string_columns)
131
132
  break if rows == { }
132
133
 
133
134
  row_size = rows[:data].size
data/lib/taps/server.rb CHANGED
@@ -118,7 +118,8 @@ class Server < Sinatra::Default
118
118
  db = session.connection
119
119
  table = db[params[:table].to_sym]
120
120
  order = Taps::Utils.order_by(db, params[:table].to_sym)
121
- raw_data = Marshal.dump(Taps::Utils.format_data(table.order(*order).limit(chunk, offset).all))
121
+ string_columns = Taps::Utils.incorrect_blobs(db, params[:table].to_sym)
122
+ raw_data = Marshal.dump(Taps::Utils.format_data(table.order(*order).limit(chunk, offset).all, string_columns))
122
123
  gzip_data = Taps::Utils.gzip(raw_data)
123
124
  response['Taps-Checksum'] = Taps::Utils.checksum(gzip_data).to_s
124
125
  response['Content-Type'] = "application/octet-stream"
data/lib/taps/utils.rb CHANGED
@@ -31,15 +31,38 @@ module Utils
31
31
  data
32
32
  end
33
33
 
34
- def format_data(data)
34
+ def format_data(data, string_columns)
35
35
  return {} if data.size == 0
36
36
  header = data[0].keys
37
37
  only_data = data.collect do |row|
38
+ row = blobs_to_string(row, string_columns)
38
39
  header.collect { |h| row[h] }
39
40
  end
40
41
  { :header => header, :data => only_data }
41
42
  end
42
43
 
44
+ # mysql text and blobs fields are handled the same way internally
45
+ # this is not true for other databases so we must check if the field is
46
+ # actually text and manually convert it back to a string
47
+ def incorrect_blobs(db, table)
48
+ return [] unless db.class.to_s == "Sequel::MySQL::Database"
49
+
50
+ columns = []
51
+ db.schema[table].each do |data|
52
+ column, cdata = data
53
+ columns << column if cdata[:db_type] =~ /text/
54
+ end
55
+ columns
56
+ end
57
+
58
+ def blobs_to_string(row, columns)
59
+ return row if columns.size == 0
60
+ columns.each do |c|
61
+ row[c] = row[c].to_s if row[c].kind_of?(Sequel::SQL::Blob)
62
+ end
63
+ row
64
+ end
65
+
43
66
  def calculate_chunksize(old_chunksize)
44
67
  chunksize = old_chunksize
45
68
 
data/spec/utils_spec.rb CHANGED
@@ -16,7 +16,7 @@ describe Taps::Utils do
16
16
  end
17
17
 
18
18
  it "formats a data hash into one hash that contains an array of headers and an array of array of data" do
19
- Taps::Utils.format_data([ { :x => 1, :y => 1 }, { :x => 2, :y => 2 } ]).should == { :header => [ :x, :y ], :data => [ [1, 1], [2, 2] ] }
19
+ Taps::Utils.format_data([ { :x => 1, :y => 1 }, { :x => 2, :y => 2 } ], []).should == { :header => [ :x, :y ], :data => [ [1, 1], [2, 2] ] }
20
20
  end
21
21
 
22
22
  it "scales chunksize down slowly when the time delta of the block is just over a second" do
@@ -45,5 +45,16 @@ describe Taps::Utils do
45
45
  it "will reset the chunksize to a small value if we got a broken pipe exception" do
46
46
  Taps::Utils.calculate_chunksize(1000) { |c| raise Errno::EPIPE if c == 1000; c.should == 100 }.should == 200
47
47
  end
48
+
49
+ it "returns a list of columns that are text fields if the database is mysql" do
50
+ @db = mock("db")
51
+ @db.class.stubs(:to_s).returns("Sequel::MySQL::Database")
52
+ @db.stubs(:schema).returns(mock("schema"))
53
+ @db.schema.stubs(:[]).with(:mytable).returns([
54
+ [:id, { :db_type => "int" }],
55
+ [:mytext, { :db_type => "text" }]
56
+ ])
57
+ Taps::Utils.incorrect_blobs(@db, :mytable).should == [:mytext]
58
+ end
48
59
  end
49
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Chimal, Jr.
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-04-14 00:00:00 -07:00
13
+ date: 2009-04-28 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -89,18 +89,18 @@ files:
89
89
  - spec/client_session_spec.rb
90
90
  - spec/utils_spec.rb
91
91
  - lib/taps/progress_bar.rb
92
- - lib/taps/utils.rb
92
+ - lib/taps/adapter_hacks.rb
93
93
  - lib/taps/adapter_hacks/non_rails_schema_dump.rb
94
94
  - lib/taps/adapter_hacks/invalid_text_limit.rb
95
95
  - lib/taps/adapter_hacks/mysql_invalid_primary_key.rb
96
96
  - lib/taps/adapter_hacks/invalid_binary_limit.rb
97
- - lib/taps/client_session.rb
98
- - lib/taps/adapter_hacks.rb
97
+ - lib/taps/utils.rb
98
+ - lib/taps/server.rb
99
99
  - lib/taps/config.rb
100
100
  - lib/taps/cli.rb
101
101
  - lib/taps/schema.rb
102
- - lib/taps/server.rb
103
102
  - lib/taps/db_session.rb
103
+ - lib/taps/client_session.rb
104
104
  - README.rdoc
105
105
  - LICENSE
106
106
  - VERSION.yml