sqlstmt 0.2.4 → 0.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2030ed99b53eecd0cef43bc033330a6dcfc5c13
4
- data.tar.gz: e30d532df77dfd93ee9a38b3b655ed867f81f1f2
3
+ metadata.gz: 98430baa411f71f5730952f97c9ccffda3872ee4
4
+ data.tar.gz: 3fd532738e1c3f4d337e21c9cabaf1c2bb0286af
5
5
  SHA512:
6
- metadata.gz: 31fd077c55962b88ca8c19a07dc6ab44f80912c8affe960631a77ce0389d44213742ca7ccd4054c3f14607b69ab602b7e4e5c8f20415af2ecee78a1353108f00
7
- data.tar.gz: facdfcbf5b2744153561f67adc5ac83c0a43c33878fef67f5552315757929aa4106c0e1f5d17f93ab526fc25c9f2a4712a0f923ceac3e775410cb2f7ea9f20ec
6
+ metadata.gz: fc948dcf7eda79d0eb54f168c47f74bb2a920f03b38e0adddb99aa7b1a9b09e8ee799e6ae2ce4aa679c086aec3d3f5a4064e1fdff60342dc49156e1eaa169d4e
7
+ data.tar.gz: cc247caaa97d7df7195533f8fcba869381c972c4a40521de4528c61d25c93c7f5a8500e47347e49c1b7c255ce76ce8497f5127a348dccbf64c62c364e805b97c
@@ -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
- @fields << field
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 @fields.empty?
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} (#{field_list}) "
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 ' : ''
@@ -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
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-01-19 00:00:00.000000000 Z
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