simple-sql 0.5.31 → 0.5.32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7490b50fc301d6e1a8c424e46a21f4a5cb97767ca2a99c7bdeed94b7c499a0d6
4
- data.tar.gz: 3e1ec456a008d2abee6260b84beb1c17ca4b5934c1b934f00298ad6263b0f849
3
+ metadata.gz: fb4af8eb0802b84e83370417d134ff18f82c812dbd9a053853739d9570f92a95
4
+ data.tar.gz: 0b023420320187d12f32cb6e1a4a093775a5bd2849015443768b0177392729fb
5
5
  SHA512:
6
- metadata.gz: 5c4ff2ac25d314393ff79a5f8ff3171508b05f30a99f37d1681a5b4af0fe3f07f247623321e235fc70de4d384d8e994935fc69eaf592c41b8459ceb0c875adf7
7
- data.tar.gz: e59f00c7d6a3f00d1f4c2ca101985e8a01b453cc80b774f5f95b867eebea3e1dddf70a341fd4bf8904e497b19738d58e2a66d20a08372a138bf2302d918af1cb
6
+ metadata.gz: 996461571d090b5cf7589dfc6f1d12925b11b54d047fc2ec2395bbb6a2d75e583a7f82d0cc92985982891d3254e3e26a83260f6a38be5bee0eac5872effb4609
7
+ data.tar.gz: 57decbf1a834422bdfc2987056c3fa37f04988de7059ed8c6eb8aa64ffc16c445a19f1dc9e91f880eac8a2ea7e8772dcfb8b1aeaf43b57ca7f13d4662ceaf177
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.31
1
+ 0.5.32
@@ -8,11 +8,27 @@ module Simple::SQL::Helpers::Encoder
8
8
 
9
9
  def encode_arg(connection, arg)
10
10
  return arg unless arg.is_a?(Array)
11
+ return "{}" if arg.empty?
11
12
 
12
- if arg.first.is_a?(String)
13
- "{#{arg.map { |a| "\"#{connection.escape(a)}\"" }.join(',')}}"
13
+ encoded_ary = encode_array(connection, arg)
14
+ "{" + encoded_ary.join(",") + "}"
15
+ end
16
+
17
+ def encode_array(connection, ary)
18
+ case ary.first
19
+ when String
20
+ ary.map do |str|
21
+ str = connection.escape(str)
22
+
23
+ # These fixes have been discovered during tests. see spec/simple/sql/conversion_spec.rb
24
+ str = str.gsub("\"", "\\\"")
25
+ str = str.gsub("''", "'")
26
+ "\"#{str}\""
27
+ end
28
+ when Integer
29
+ ary
14
30
  else
15
- "{#{arg.join(',')}}"
31
+ raise ArgumentError, "Don't know how to encode array of #{ary.first.class}"
16
32
  end
17
33
  end
18
34
  end
@@ -5,6 +5,7 @@ module Simple
5
5
 
6
6
  def version(name)
7
7
  spec = Gem.loaded_specs[name]
8
+ return "unreleased" unless spec
8
9
  version = spec.version.to_s
9
10
  version += "+unreleased" if unreleased?(spec)
10
11
  version
@@ -23,6 +23,7 @@ describe "Simple::SQL conversions" do
23
23
  expects "foo,\"bar}", "SELECT $1::varchar", "foo,\"bar}"
24
24
  expects ["one", "two", "3.5", "foo,\"bar}"], "SELECT ARRAY['one', 'two', '3.5', 'foo,\"bar}']"
25
25
  expects ["foo", "foo,bar}"], "SELECT $1::varchar[]", ["foo", "foo,bar}"]
26
+ expects "foo'bar", 'SELECT $1', "foo'bar"
26
27
  end
27
28
 
28
29
  it "parses JSON as expected" do
@@ -42,13 +43,15 @@ describe "Simple::SQL conversions" do
42
43
  it "converts hstore" do
43
44
  expects({ a: "1", b: "3" }, "SELECT 'a=>1,b=>3'::hstore")
44
45
  end
45
-
46
- xit "fails sometimes w/ malformed array literal, pt. 1" do
47
- expects 0, 'SELECT $1::varchar[]', [ "foo", 'foo,"bar}' ]
48
- end
49
-
50
- xit "fails sometimes w/ malformed array literal, pt. 2" do
51
- expects 0, 'SELECT $1::varchar[]', [ "foo", 'foo,"bar}' ]
46
+ end
47
+
48
+ describe "arra conversions" do
49
+ it "works with strings" do
50
+ expects [ "foo", "bar" ], 'SELECT $1::varchar[]', [ "foo", "bar" ]
51
+
52
+ # test escaping
53
+ expects [ "foo", "foo'bar\"baz" ], 'SELECT $1::varchar[]', [ "foo", "foo'bar\"baz" ]
54
+ expects [ ], 'SELECT $1::varchar[]', []
52
55
  end
53
56
  end
54
57
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.31
4
+ version: 0.5.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
8
8
  - mediapeers GmbH
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-09-04 00:00:00.000000000 Z
12
+ date: 2021-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser
@@ -185,6 +185,7 @@ extra_rdoc_files: []
185
185
  files:
186
186
  - ".gitignore"
187
187
  - ".rubocop.yml"
188
+ - ".ruby-version"
188
189
  - ".tm_properties"
189
190
  - Gemfile
190
191
  - Makefile
@@ -271,7 +272,7 @@ files:
271
272
  homepage: http://github.com/radiospiel/simple-sql
272
273
  licenses: []
273
274
  metadata: {}
274
- post_install_message:
275
+ post_install_message:
275
276
  rdoc_options: []
276
277
  require_paths:
277
278
  - lib
@@ -286,8 +287,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
287
  - !ruby/object:Gem::Version
287
288
  version: '0'
288
289
  requirements: []
289
- rubygems_version: 3.0.6
290
- signing_key:
290
+ rubygems_version: 3.1.4
291
+ signing_key:
291
292
  specification_version: 4
292
293
  summary: SQL with a simple interface
293
294
  test_files: