believer 0.2.18 → 0.2.19

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.
@@ -11,16 +11,12 @@ module Believer
11
11
  # @param value [Object] the value to convert
12
12
  def to_cql_literal(value)
13
13
  return 'NULL' if value.nil?
14
- return "'#{value}'" if value.is_a?(String)
14
+ return "'#{escape_special_chars(value)}'" if value.is_a?(String)
15
15
  return "'#{value}'" if value.is_a?(Symbol)
16
16
  return "#{value}" if value.is_a?(Numeric)
17
17
  return "'#{value.strftime(CQL_TIMESTAMP_FORMAT)}'" if value.is_a?(Time) || value.is_a?(DateTime)
18
18
  #return "#{value.to_i * 1000}" if value.is_a?(Time) || value.is_a?(DateTime)
19
19
 
20
- if value.is_a?(Counter)
21
-
22
- end
23
-
24
20
  # Set
25
21
  if value.is_a?(Set)
26
22
  return "{#{value.map {|v| to_cql_literal(v)}.join(',')}}"
@@ -45,11 +41,12 @@ module Believer
45
41
  v = properties[k]
46
42
  v_s = nil
47
43
  if v.is_a?(Hash)
44
+ v.each {|k, val| v[k] = escape_special_chars(val) if val.is_a?(String)}
48
45
  v_s = v.to_json.gsub(/\"/) { |m| "'" }
49
46
  elsif v.is_a?(String)
50
- v_s = "'#{v}'"
47
+ v_s = "'#{escape_special_chars(v)}'"
51
48
  else
52
- v_s = v.to_s
49
+ v_s = escape_special_chars(v.to_s)
53
50
  end
54
51
  "#{k} = #{v_s}"
55
52
  }.join("\nAND ")
@@ -57,5 +54,9 @@ module Believer
57
54
  props_s
58
55
  end
59
56
 
57
+ def escape_special_chars(v)
58
+ v.gsub("'", "''")
59
+ end
60
+
60
61
  end
61
62
  end
@@ -94,7 +94,7 @@ module Believer
94
94
  def load_config_from_file(config_file)
95
95
  return nil if config_file.nil?
96
96
  cfg = HashWithIndifferentAccess.new(YAML::load(File.open(config_file.to_s)))
97
- puts "Loaded config from file #{config_file.to_s}: #{cfg}"
97
+ #puts "Loaded config from file #{config_file.to_s}: #{cfg}"
98
98
  cfg
99
99
  end
100
100
 
@@ -1,5 +1,5 @@
1
1
  module Believer
2
2
  module Version
3
- VERSION = '0.2.18'
3
+ VERSION = '0.2.19'
4
4
  end
5
5
  end
@@ -24,6 +24,12 @@ describe Believer::Query do
24
24
 
25
25
  end
26
26
 
27
+ it 'should escape string literals' do
28
+ q = Believer::Query.new(:record_class => Test::Album)
29
+ q = q.select(:name).where(:name => "'quote!")
30
+ expect(q.to_cql).to eql "SELECT name FROM albums WHERE name = '''quote!'"
31
+ end
32
+
27
33
  it 'create simple statement' do
28
34
  q = Believer::Query.new(:record_class => Test::Album)
29
35
  q = q.select(:name).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: believer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-26 00:00:00.000000000 Z
12
+ date: 2014-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel