sqlstmt 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sqlstmt/sqlstmt.rb +11 -4
- data/test/insert_select_test.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98430baa411f71f5730952f97c9ccffda3872ee4
|
4
|
+
data.tar.gz: 3fd532738e1c3f4d337e21c9cabaf1c2bb0286af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc948dcf7eda79d0eb54f168c47f74bb2a920f03b38e0adddb99aa7b1a9b09e8ee799e6ae2ce4aa679c086aec3d3f5a4064e1fdff60342dc49156e1eaa169d4e
|
7
|
+
data.tar.gz: cc247caaa97d7df7195533f8fcba869381c972c4a40521de4528c61d25c93c7f5a8500e47347e49c1b7c255ce76ce8497f5127a348dccbf64c62c364e805b97c
|
data/lib/sqlstmt/sqlstmt.rb
CHANGED
@@ -104,7 +104,11 @@ class SqlStmt
|
|
104
104
|
|
105
105
|
def set(field, value)
|
106
106
|
raise "trying to include field #{field} again" if @fields.include?(field)
|
107
|
-
|
107
|
+
# this is to support the special case of INSERT INTO table SELECT * FROM ...
|
108
|
+
# where * specified with no matching insert field list specified
|
109
|
+
if field
|
110
|
+
@fields << field
|
111
|
+
end
|
108
112
|
value = value.is_a?(String) ? value : value.to_sql
|
109
113
|
@values << value
|
110
114
|
return self
|
@@ -229,7 +233,7 @@ private
|
|
229
233
|
end
|
230
234
|
|
231
235
|
if ['update','insert'].include?(@stmt_type)
|
232
|
-
raise SqlStmtError, "unable to build sql - must call :set or :setq" if @
|
236
|
+
raise SqlStmtError, "unable to build sql - must call :set or :setq" if @values.empty?
|
233
237
|
raise SqlStmtError, "unable to build sql - must not call :get" if @called_get
|
234
238
|
end
|
235
239
|
|
@@ -268,9 +272,12 @@ private
|
|
268
272
|
end
|
269
273
|
|
270
274
|
keyword = @replace ? 'REPLACE' : 'INSERT'
|
271
|
-
field_list = @fields.join(',')
|
272
275
|
value_list = @values.join(',')
|
273
|
-
start_str = "#{keyword} #{@ignore}INTO #{@into_table}
|
276
|
+
start_str = "#{keyword} #{@ignore}INTO #{@into_table} "
|
277
|
+
if !@fields.empty?
|
278
|
+
field_list = @fields.join(',')
|
279
|
+
start_str += "(#{field_list}) "
|
280
|
+
end
|
274
281
|
|
275
282
|
if @rows.empty?
|
276
283
|
distinct_str = @distinct ? 'DISTINCT ' : ''
|
data/test/insert_select_test.rb
CHANGED
@@ -12,6 +12,10 @@ class TestInsertSelect < Minitest::Test
|
|
12
12
|
assert_equal('INSERT INTO target (blah) SELECT blee FROM source WHERE source_id = 1', SqlStmt.new.insert.into('target').table('source').set('blah', 'blee').where('source_id = 1').to_s)
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_star
|
16
|
+
assert_equal('INSERT INTO target SELECT * FROM source', SqlStmt.new.insert.into('target').table('source').set(nil, '*').no_where.to_s)
|
17
|
+
end
|
18
|
+
|
15
19
|
def test_dup
|
16
20
|
shared_builder = SqlStmt.new.insert.into('target')
|
17
21
|
first_builder = shared_builder
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlstmt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makani Mason
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: build SQL statements in a modular fashion, one piece at a time; only
|
15
15
|
used/tested with MySQL so far
|