upsert 0.1.1 → 0.1.2
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/lib/upsert/buffer/mysql2_client.rb +13 -1
- data/lib/upsert/version.rb +1 -1
- data/test/test_active_record_connection_adapter.rb +3 -3
- data/test/test_mysql2.rb +1 -1
- data/test/test_pg.rb +1 -1
- data/test/test_sqlite.rb +1 -1
- metadata +1 -1
@@ -90,8 +90,18 @@ class Upsert
|
|
90
90
|
[ insert_part, '(', all_value_sql.join('),('), ')', update_part ].join
|
91
91
|
end
|
92
92
|
|
93
|
+
# since setting an option like :as => :hash actually persists that option to the client, don't pass any options
|
93
94
|
def max_sql_bytesize
|
94
|
-
@max_sql_bytesize ||=
|
95
|
+
@max_sql_bytesize ||= begin
|
96
|
+
case (row = connection.query("SHOW VARIABLES LIKE 'max_allowed_packet'").first)
|
97
|
+
when Array
|
98
|
+
row[1]
|
99
|
+
when Hash
|
100
|
+
row['Value']
|
101
|
+
else
|
102
|
+
raise "Don't know what to do if connection.query returns a #{row.class}"
|
103
|
+
end.to_i
|
104
|
+
end
|
95
105
|
end
|
96
106
|
|
97
107
|
def quoted_value_bytesize(v)
|
@@ -110,6 +120,8 @@ class Upsert
|
|
110
120
|
v.to_s.bytesize
|
111
121
|
when String
|
112
122
|
v.bytesize + 2
|
123
|
+
when Symbol
|
124
|
+
v.to_s.bytesize + 2
|
113
125
|
when Time, DateTime
|
114
126
|
24 + 2
|
115
127
|
when Date
|
data/lib/upsert/version.rb
CHANGED
@@ -5,16 +5,16 @@ ActiveRecord::Base.establish_connection :adapter => 'mysql2', :username => 'root
|
|
5
5
|
|
6
6
|
describe "using an ActiveRecord connection adapter" do
|
7
7
|
before do
|
8
|
+
@opened_connections = []
|
8
9
|
ActiveRecord::Base.connection.drop_table(Pet.table_name) rescue nil
|
9
10
|
Pet.auto_upgrade!
|
10
|
-
@opened_connections = []
|
11
11
|
@connection = new_connection
|
12
12
|
end
|
13
13
|
after do
|
14
|
-
@opened_connections.
|
14
|
+
@opened_connections.clear
|
15
15
|
end
|
16
16
|
def new_connection
|
17
|
-
c =
|
17
|
+
c = Pet.connection
|
18
18
|
@opened_connections << c
|
19
19
|
c
|
20
20
|
end
|
data/test/test_mysql2.rb
CHANGED
@@ -6,9 +6,9 @@ ActiveRecord::Base.establish_connection :adapter => 'mysql2', :username => 'root
|
|
6
6
|
|
7
7
|
describe "upserting on mysql2" do
|
8
8
|
before do
|
9
|
+
@opened_connections = []
|
9
10
|
ActiveRecord::Base.connection.drop_table(Pet.table_name) rescue nil
|
10
11
|
Pet.auto_upgrade!
|
11
|
-
@opened_connections = []
|
12
12
|
@connection = new_connection
|
13
13
|
end
|
14
14
|
after do
|
data/test/test_pg.rb
CHANGED
@@ -7,9 +7,9 @@ ActiveRecord::Base.establish_connection :adapter => 'postgresql', :database => '
|
|
7
7
|
|
8
8
|
describe "upserting on postgresql" do
|
9
9
|
before do
|
10
|
+
@opened_connections = []
|
10
11
|
ActiveRecord::Base.connection.drop_table(Pet.table_name) rescue nil
|
11
12
|
Pet.auto_upgrade!
|
12
|
-
@opened_connections = []
|
13
13
|
@connection = new_connection
|
14
14
|
end
|
15
15
|
after do
|
data/test/test_sqlite.rb
CHANGED
@@ -8,9 +8,9 @@ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => db_p
|
|
8
8
|
|
9
9
|
describe "upserting on sqlite" do
|
10
10
|
before do
|
11
|
+
@opened_connections = []
|
11
12
|
ActiveRecord::Base.connection.drop_table(Pet.table_name) rescue nil
|
12
13
|
Pet.auto_upgrade!
|
13
|
-
@opened_connections = []
|
14
14
|
@connection = new_connection
|
15
15
|
end
|
16
16
|
after do
|