sql_query_executor 0.5.4 → 0.5.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85f5db8b826ddf206caa93d7898facf5d76b1e9a
|
4
|
+
data.tar.gz: fc6bb235313fc23899480fbbd173d715fdc50a4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da73194a3eba45142e6f0962005686403682b53029ae28fa9c5c6714c03554c5067936c5a9fc68ba8012e73d8b60dca2aadd172082dc0ad0a0749ec5bfae54a3
|
7
|
+
data.tar.gz: 3871cba563d907419574c950f2a7ed93b795a09662ca576d96e360461909df9fc5631812daa5748d2cc6da9777eb8b985f9195df641f0487169927c529a02aea
|
@@ -68,19 +68,6 @@ module SqlQueryExecutor #:nodoc:
|
|
68
68
|
@collection = collection
|
69
69
|
end
|
70
70
|
|
71
|
-
def convert_collection(collection=[])
|
72
|
-
@collection = []
|
73
|
-
collection.each do |object|
|
74
|
-
attributes = object.is_a?(Hash) ? object : object.attributes
|
75
|
-
register = OpenStruct.new(attributes)
|
76
|
-
@collection << register
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def conforming_collection?(collection)
|
81
|
-
collection.first.respond_to?(:attributes)
|
82
|
-
end
|
83
|
-
|
84
71
|
def check_query
|
85
72
|
return if @query.empty?
|
86
73
|
|
@@ -15,7 +15,14 @@ module SqlQueryExecutor
|
|
15
15
|
def logic(is_hash=false)
|
16
16
|
initialize_attributes(true)
|
17
17
|
|
18
|
-
|
18
|
+
field = field(is_hash)
|
19
|
+
value = @value || 'nil'
|
20
|
+
|
21
|
+
if value.is_a?(String) && is_a_number?(value.gsub(/[\"|\']/, ''))
|
22
|
+
"#{field} #{@operator} (#{field}.is_a?(Fixnum) ? #{value}.to_i : #{value})"
|
23
|
+
else
|
24
|
+
"#{field} #{@operator} #{value}"
|
25
|
+
end
|
19
26
|
end
|
20
27
|
|
21
28
|
protected
|
@@ -44,22 +51,26 @@ module SqlQueryExecutor
|
|
44
51
|
end
|
45
52
|
|
46
53
|
def convert_value(value, logic=false)
|
54
|
+
real_value = value.dup
|
47
55
|
value.gsub!(/[\(\)\'\"]/, "")
|
48
|
-
return value.to_i if is_a_number?(value)
|
49
|
-
return value.to_f if is_a_number?(value, true)
|
50
|
-
return eval(value) if ['true', 'false'].include?(value)
|
51
56
|
|
52
57
|
methods = {3 => "convert_date", 7 => "convert_time"}
|
53
58
|
|
54
59
|
array = split(value)
|
55
60
|
|
56
61
|
if methods.keys.include?(array.size)
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
date_value = send(methods[array.size], array, logic)
|
63
|
+
|
64
|
+
return date_value if date_value
|
65
|
+
end
|
66
|
+
|
67
|
+
unless logic && ["'", '"'].include?(real_value[0])
|
68
|
+
return value.to_i if is_a_number?(value)
|
69
|
+
return value.to_f if is_a_number?(value, true)
|
70
|
+
return eval(value) if ['true', 'false'].include?(value)
|
60
71
|
end
|
61
72
|
|
62
|
-
value
|
73
|
+
logic ? "'#{value}'" : value
|
63
74
|
end
|
64
75
|
|
65
76
|
private
|
@@ -16,9 +16,14 @@ module SqlQueryExecutor
|
|
16
16
|
|
17
17
|
private
|
18
18
|
def get_value(logic=false)
|
19
|
-
|
19
|
+
values = []
|
20
|
+
value = @array.last.gsub(SqlQueryExecutor::Base::STRING_SPACE, ' ')
|
20
21
|
|
21
|
-
value.
|
22
|
+
value.split(',').each do |val|
|
23
|
+
values.push(convert_value(val, logic))
|
24
|
+
end
|
25
|
+
|
26
|
+
values
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|