struggle 2.3.8 → 2.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/struggle/sql.rb +21 -26
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c81c7d2477eae2412e578bf73326826fc7dc2c3e
|
4
|
+
data.tar.gz: 2a864ad7bc30bd6535330682c2ac54e89926601b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e74496d38feb6d22144704cfb8424b78039429442b0c635f210c0c6448959eee26aa3dfb24413ec982794ee221d48dc6aa74ee0a47e2894c3db345553355084
|
7
|
+
data.tar.gz: 4b0638b97d1aff7c773ca4516d5ee895bceaf5d80165c5f6c1d8d511ced0ddd549debab089bc887957f8982e6ddf3c5816322fb05962f6f232f4cb94323d7966
|
data/lib/struggle/sql.rb
CHANGED
@@ -16,33 +16,28 @@ module Struggle
|
|
16
16
|
# class_name is ActiveRecord; file is backup sql file
|
17
17
|
def dump(config)
|
18
18
|
config["file"] = config["file"].blank? ? "db.sql" : config["file"]
|
19
|
-
config["
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
19
|
+
File.open(config["file"], "w+") do |file|
|
20
|
+
config["class_name"].each do |class_name|
|
21
|
+
obj = eval(class_name)
|
22
|
+
obj.all.each do |o|
|
23
|
+
attrs = o.attributes
|
24
|
+
names = []
|
25
|
+
values = []
|
26
|
+
attrs.each do |k, v|
|
27
|
+
names << k
|
28
|
+
value = v
|
29
|
+
if v.class == Date
|
30
|
+
value = v.strftime("%Y-%m-%d")
|
31
|
+
value = "TO_DATE('#{value}', 'YYYY-MM-DD')" if config["adapter"] && config["adapter"].downcase == "oracle"
|
32
|
+
elsif v.class == ActiveSupport::TimeWithZone
|
33
|
+
value = v.strftime("%Y-%m-%d %H:%M:%S")
|
34
|
+
value = "TO_TIMESTAMP('#{value}', 'YYYY-MM-DD HH24:MI:SS.FF6')" if config["adapter"] && config["adapter"].downcase == "oracle"
|
35
|
+
else
|
36
|
+
value = "'#{v}'"
|
37
|
+
end
|
38
|
+
values << value
|
36
39
|
end
|
37
|
-
|
38
|
-
end
|
39
|
-
begin
|
40
|
-
f = File.new(config["file"], "w+")
|
41
|
-
f.write("INSERT INTO #{obj.table_name} (#{names.join(',')}) VALUES (#{values.join(',')});\r\n")
|
42
|
-
f.close
|
43
|
-
f = nil
|
44
|
-
rescue
|
45
|
-
return "#{$!}:#{config["file"]}"
|
40
|
+
file.puts "INSERT INTO #{obj.table_name} (#{names.join(',')}) VALUES (#{values.join(',')});\r\n"
|
46
41
|
end
|
47
42
|
end
|
48
43
|
end
|