baza 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +14 -7
- data/Gemfile.lock +19 -14
- data/README.md +1 -1
- data/VERSION +1 -1
- data/baza.gemspec +24 -21
- data/include/cloner.rb +18 -0
- data/include/column.rb +9 -0
- data/include/db.rb +2 -2
- data/include/drivers/active_record/active_record.rb +14 -4
- data/include/drivers/mysql/mysql.rb +56 -36
- data/include/drivers/mysql/mysql_column.rb +1 -1
- data/include/drivers/mysql/mysql_index.rb +2 -10
- data/include/drivers/mysql/mysql_table.rb +11 -11
- data/include/drivers/mysql/mysql_tables.rb +5 -7
- data/include/drivers/sqlite3/sqlite3.rb +43 -23
- data/include/drivers/sqlite3/sqlite3_column.rb +1 -1
- data/include/drivers/sqlite3/sqlite3_index.rb +5 -8
- data/include/drivers/sqlite3/sqlite3_result_java.rb +1 -1
- data/include/drivers/sqlite3/sqlite3_table.rb +17 -18
- data/include/drivers/sqlite3/sqlite3_tables.rb +4 -7
- data/include/index.rb +9 -0
- data/include/model.rb +1 -1
- data/include/model_handler.rb +162 -162
- data/include/table.rb +9 -0
- data/lib/baza.rb +19 -1
- data/shippable.yml +4 -1
- data/spec/include/cloner_spec.rb +10 -0
- data/spec/info_active_record.rb +20 -8
- data/spec/info_active_record_shippable.rb +18 -7
- data/spec/info_mysql_shippable.rb +16 -7
- data/spec/info_sqlite3.rb +1 -1
- data/spec/support/driver_indexes_collection.rb +16 -2
- metadata +28 -25
- data/include/drivers/sqlite3/libknjdb_java_sqlite3.rb +0 -78
- data/include/drivers/sqlite3/libknjdb_sqlite3_ironruby.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5f47d6cdffb1dd17d2d21f48fb8f9c6b0839b87
|
4
|
+
data.tar.gz: 23363aeb34337a30ab40ac95a3e2f627e9daa84b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f96d264eb5a7b392e3772e6fe578c24192a2936aaafb2035f60f8347257e73da2be2ec012d840b4cf58e9d780f20054cf995be3f27f8bee52047f5039e690b2
|
7
|
+
data.tar.gz: 5be50aaefdf6c9fcab087547fa054f2ebe4295ee9347403c7b497b9b6e5e16c2bb6f24392a4e4cd27da84104e20dd48785e9d4648709a227f86410728c1d3728
|
data/Gemfile
CHANGED
@@ -3,11 +3,11 @@ source "http://rubygems.org"
|
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
|
6
|
-
gem "datet"
|
7
|
-
gem "wref"
|
8
|
-
gem "knjrbfw"
|
9
|
-
gem "array_enumerator"
|
10
|
-
gem "string-cases"
|
6
|
+
gem "datet", "~> 0.0.25"
|
7
|
+
gem "wref", "~> 0.0.8"
|
8
|
+
gem "knjrbfw", "~> 0.0.111"
|
9
|
+
gem "array_enumerator", "~> 0.0.7"
|
10
|
+
gem "string-cases", "~> 0.0.1"
|
11
11
|
|
12
12
|
# Add dependencies to develop your gem here.
|
13
13
|
# Include everything needed to run rake, tests, features, etc.
|
@@ -16,8 +16,15 @@ group :development do
|
|
16
16
|
gem "rdoc"
|
17
17
|
gem "bundler"
|
18
18
|
gem "jeweler"
|
19
|
-
|
20
|
-
|
19
|
+
|
20
|
+
if RUBY_ENGINE == "jruby"
|
21
|
+
gem "jdbc-sqlite3"
|
22
|
+
gem "activerecord-jdbc-adapter"
|
23
|
+
else
|
24
|
+
gem "sqlite3"
|
25
|
+
gem "mysql2"
|
26
|
+
end
|
27
|
+
|
21
28
|
gem "activerecord"
|
22
29
|
end
|
23
30
|
|
data/Gemfile.lock
CHANGED
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
tzinfo (~> 1.1)
|
17
17
|
addressable (2.3.6)
|
18
18
|
arel (5.0.1.20140414130214)
|
19
|
-
array_enumerator (0.0.
|
19
|
+
array_enumerator (0.0.7)
|
20
20
|
builder (3.2.2)
|
21
21
|
codeclimate-test-reporter (0.4.1)
|
22
22
|
simplecov (>= 0.7.1, < 1.0.0)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
oauth2
|
39
39
|
hashie (3.3.1)
|
40
40
|
highline (1.6.21)
|
41
|
-
http2 (0.0.
|
41
|
+
http2 (0.0.30)
|
42
42
|
string-cases
|
43
43
|
i18n (0.6.11)
|
44
44
|
jeweler (2.0.1)
|
@@ -51,22 +51,24 @@ GEM
|
|
51
51
|
rake
|
52
52
|
rdoc
|
53
53
|
json (1.8.1)
|
54
|
+
json (1.8.1-java)
|
54
55
|
jwt (1.0.0)
|
55
|
-
knjrbfw (0.0.
|
56
|
+
knjrbfw (0.0.111)
|
56
57
|
datet
|
57
58
|
http2
|
58
59
|
php4r
|
59
60
|
ruby_process
|
60
61
|
tsafe
|
61
|
-
wref
|
62
|
+
wref (>= 0.0.8)
|
62
63
|
mini_portile (0.6.0)
|
63
64
|
minitest (5.4.2)
|
64
65
|
multi_json (1.10.1)
|
65
66
|
multi_xml (0.5.5)
|
66
67
|
multipart-post (2.0.0)
|
67
|
-
mysql2 (0.3.
|
68
|
+
mysql2 (0.3.18)
|
68
69
|
nokogiri (1.6.3.1)
|
69
70
|
mini_portile (= 0.6.0)
|
71
|
+
nokogiri (1.6.3.1-java)
|
70
72
|
oauth2 (1.0.0)
|
71
73
|
faraday (>= 0.8, < 0.10)
|
72
74
|
jwt (~> 1.0)
|
@@ -93,7 +95,8 @@ GEM
|
|
93
95
|
rspec-mocks (3.1.3)
|
94
96
|
rspec-support (~> 3.1.0)
|
95
97
|
rspec-support (3.1.2)
|
96
|
-
ruby_process (0.0.
|
98
|
+
ruby_process (0.0.13)
|
99
|
+
string-cases
|
97
100
|
tsafe
|
98
101
|
wref
|
99
102
|
simplecov (0.9.1)
|
@@ -101,29 +104,31 @@ GEM
|
|
101
104
|
multi_json (~> 1.0)
|
102
105
|
simplecov-html (~> 0.8.0)
|
103
106
|
simplecov-html (0.8.0)
|
104
|
-
sqlite3 (1.3.
|
105
|
-
string-cases (0.0.
|
107
|
+
sqlite3 (1.3.10)
|
108
|
+
string-cases (0.0.1)
|
106
109
|
string-strtr (0.0.3)
|
107
110
|
thread_safe (0.3.4)
|
111
|
+
thread_safe (0.3.4-java)
|
108
112
|
tsafe (0.0.11)
|
109
113
|
tzinfo (1.2.2)
|
110
114
|
thread_safe (~> 0.1)
|
111
|
-
wref (0.0.
|
115
|
+
wref (0.0.8)
|
112
116
|
|
113
117
|
PLATFORMS
|
118
|
+
java
|
114
119
|
ruby
|
115
120
|
|
116
121
|
DEPENDENCIES
|
117
122
|
activerecord
|
118
|
-
array_enumerator
|
123
|
+
array_enumerator (~> 0.0.7)
|
119
124
|
bundler
|
120
125
|
codeclimate-test-reporter
|
121
|
-
datet
|
126
|
+
datet (~> 0.0.25)
|
122
127
|
jeweler
|
123
|
-
knjrbfw
|
128
|
+
knjrbfw (~> 0.0.111)
|
124
129
|
mysql2
|
125
130
|
rdoc
|
126
131
|
rspec
|
127
132
|
sqlite3
|
128
|
-
string-cases
|
129
|
-
wref
|
133
|
+
string-cases (~> 0.0.1)
|
134
|
+
wref (~> 0.0.8)
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.16
|
data/baza.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: baza 0.0.
|
5
|
+
# stub: baza 0.0.16 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "baza"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.16"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Kasper Johansen"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-05-27"
|
15
15
|
s.description = "A database abstraction layer, model framework and database framework."
|
16
16
|
s.email = "kj@gfish.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,8 @@ Gem::Specification.new do |s|
|
|
28
28
|
"Rakefile",
|
29
29
|
"VERSION",
|
30
30
|
"baza.gemspec",
|
31
|
+
"include/cloner.rb",
|
32
|
+
"include/column.rb",
|
31
33
|
"include/db.rb",
|
32
34
|
"include/dbtime.rb",
|
33
35
|
"include/driver.rb",
|
@@ -44,8 +46,6 @@ Gem::Specification.new do |s|
|
|
44
46
|
"include/drivers/mysql/mysql_sqlspecs.rb",
|
45
47
|
"include/drivers/mysql/mysql_table.rb",
|
46
48
|
"include/drivers/mysql/mysql_tables.rb",
|
47
|
-
"include/drivers/sqlite3/libknjdb_java_sqlite3.rb",
|
48
|
-
"include/drivers/sqlite3/libknjdb_sqlite3_ironruby.rb",
|
49
49
|
"include/drivers/sqlite3/sqlite3.rb",
|
50
50
|
"include/drivers/sqlite3/sqlite3_column.rb",
|
51
51
|
"include/drivers/sqlite3/sqlite3_columns.rb",
|
@@ -58,6 +58,7 @@ Gem::Specification.new do |s|
|
|
58
58
|
"include/drivers/sqlite3/sqlite3_tables.rb",
|
59
59
|
"include/dump.rb",
|
60
60
|
"include/idquery.rb",
|
61
|
+
"include/index.rb",
|
61
62
|
"include/model.rb",
|
62
63
|
"include/model_custom.rb",
|
63
64
|
"include/model_handler.rb",
|
@@ -66,8 +67,10 @@ Gem::Specification.new do |s|
|
|
66
67
|
"include/revision.rb",
|
67
68
|
"include/row.rb",
|
68
69
|
"include/sqlspecs.rb",
|
70
|
+
"include/table.rb",
|
69
71
|
"lib/baza.rb",
|
70
72
|
"shippable.yml",
|
73
|
+
"spec/include/cloner_spec.rb",
|
71
74
|
"spec/include/drivers/active_record_spec.rb",
|
72
75
|
"spec/include/drivers/mysql_spec.rb",
|
73
76
|
"spec/include/drivers/sqlite3_spec.rb",
|
@@ -86,18 +89,18 @@ Gem::Specification.new do |s|
|
|
86
89
|
]
|
87
90
|
s.homepage = "http://github.com/kaspernj/baza"
|
88
91
|
s.licenses = ["MIT"]
|
89
|
-
s.rubygems_version = "2.
|
92
|
+
s.rubygems_version = "2.2.2"
|
90
93
|
s.summary = "A database abstraction layer, model framework and database framework."
|
91
94
|
|
92
95
|
if s.respond_to? :specification_version then
|
93
96
|
s.specification_version = 4
|
94
97
|
|
95
98
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
96
|
-
s.add_runtime_dependency(%q<datet>, ["
|
97
|
-
s.add_runtime_dependency(%q<wref>, ["
|
98
|
-
s.add_runtime_dependency(%q<knjrbfw>, ["
|
99
|
-
s.add_runtime_dependency(%q<array_enumerator>, ["
|
100
|
-
s.add_runtime_dependency(%q<string-cases>, ["
|
99
|
+
s.add_runtime_dependency(%q<datet>, ["~> 0.0.25"])
|
100
|
+
s.add_runtime_dependency(%q<wref>, ["~> 0.0.8"])
|
101
|
+
s.add_runtime_dependency(%q<knjrbfw>, ["~> 0.0.111"])
|
102
|
+
s.add_runtime_dependency(%q<array_enumerator>, ["~> 0.0.7"])
|
103
|
+
s.add_runtime_dependency(%q<string-cases>, ["~> 0.0.1"])
|
101
104
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
102
105
|
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
103
106
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
@@ -106,11 +109,11 @@ Gem::Specification.new do |s|
|
|
106
109
|
s.add_development_dependency(%q<mysql2>, [">= 0"])
|
107
110
|
s.add_development_dependency(%q<activerecord>, [">= 0"])
|
108
111
|
else
|
109
|
-
s.add_dependency(%q<datet>, ["
|
110
|
-
s.add_dependency(%q<wref>, ["
|
111
|
-
s.add_dependency(%q<knjrbfw>, ["
|
112
|
-
s.add_dependency(%q<array_enumerator>, ["
|
113
|
-
s.add_dependency(%q<string-cases>, ["
|
112
|
+
s.add_dependency(%q<datet>, ["~> 0.0.25"])
|
113
|
+
s.add_dependency(%q<wref>, ["~> 0.0.8"])
|
114
|
+
s.add_dependency(%q<knjrbfw>, ["~> 0.0.111"])
|
115
|
+
s.add_dependency(%q<array_enumerator>, ["~> 0.0.7"])
|
116
|
+
s.add_dependency(%q<string-cases>, ["~> 0.0.1"])
|
114
117
|
s.add_dependency(%q<rspec>, [">= 0"])
|
115
118
|
s.add_dependency(%q<rdoc>, [">= 0"])
|
116
119
|
s.add_dependency(%q<bundler>, [">= 0"])
|
@@ -120,11 +123,11 @@ Gem::Specification.new do |s|
|
|
120
123
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
121
124
|
end
|
122
125
|
else
|
123
|
-
s.add_dependency(%q<datet>, ["
|
124
|
-
s.add_dependency(%q<wref>, ["
|
125
|
-
s.add_dependency(%q<knjrbfw>, ["
|
126
|
-
s.add_dependency(%q<array_enumerator>, ["
|
127
|
-
s.add_dependency(%q<string-cases>, ["
|
126
|
+
s.add_dependency(%q<datet>, ["~> 0.0.25"])
|
127
|
+
s.add_dependency(%q<wref>, ["~> 0.0.8"])
|
128
|
+
s.add_dependency(%q<knjrbfw>, ["~> 0.0.111"])
|
129
|
+
s.add_dependency(%q<array_enumerator>, ["~> 0.0.7"])
|
130
|
+
s.add_dependency(%q<string-cases>, ["~> 0.0.1"])
|
128
131
|
s.add_dependency(%q<rspec>, [">= 0"])
|
129
132
|
s.add_dependency(%q<rdoc>, [">= 0"])
|
130
133
|
s.add_dependency(%q<bundler>, [">= 0"])
|
data/include/cloner.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Baza::Cloner
|
2
|
+
def self.from_active_record_connection(connection)
|
3
|
+
if connection.class.name.include?('Mysql2Adapter')
|
4
|
+
config = connection.instance_variable_get(:@connection).instance_variable_get(:@query_options)
|
5
|
+
|
6
|
+
Baza::Db.new(
|
7
|
+
type: :mysql,
|
8
|
+
subtype: :mysql2,
|
9
|
+
host: config[:host],
|
10
|
+
user: config[:username],
|
11
|
+
pass: config[:password],
|
12
|
+
db: config[:database]
|
13
|
+
)
|
14
|
+
else
|
15
|
+
raise "Unsupported adapter: #{connection.class.name}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/include/column.rb
ADDED
data/include/db.rb
CHANGED
@@ -97,9 +97,9 @@ class Baza::Db
|
|
97
97
|
end
|
98
98
|
|
99
99
|
if RUBY_PLATFORM == "java"
|
100
|
-
@opts[:subtype]
|
100
|
+
@opts[:subtype] ||= :java
|
101
101
|
elsif @opts[:type] == "sqlite3" && RUBY_PLATFORM.index("mswin32") != nil
|
102
|
-
@opts[:subtype]
|
102
|
+
@opts[:subtype] ||= :ironruby
|
103
103
|
end
|
104
104
|
|
105
105
|
@type_cc = StringCases.snake_to_camel(@opts[:type])
|
@@ -90,8 +90,8 @@ class Baza::Driver::ActiveRecord::Result
|
|
90
90
|
|
91
91
|
def enum
|
92
92
|
@enum ||= Enumerator.new do |y|
|
93
|
-
|
94
|
-
y <<
|
93
|
+
each do |data|
|
94
|
+
y << data
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -104,8 +104,18 @@ class Baza::Driver::ActiveRecord::Result
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
def each
|
108
|
-
|
107
|
+
def each(&blk)
|
108
|
+
return unless @res
|
109
|
+
|
110
|
+
if RUBY_ENGINE == "jruby"
|
111
|
+
@res.each do |result|
|
112
|
+
yield result.symbolize_keys
|
113
|
+
end
|
114
|
+
else
|
115
|
+
@res.each(as: :hash) do |result|
|
116
|
+
yield result.symbolize_keys
|
117
|
+
end
|
118
|
+
end
|
109
119
|
end
|
110
120
|
end
|
111
121
|
|
@@ -29,14 +29,27 @@ class Baza::Driver::Mysql
|
|
29
29
|
}
|
30
30
|
}
|
31
31
|
}
|
32
|
+
elsif args[:object].class.name == "Java::ComMysqlJdbc::JDBC4Connection"
|
33
|
+
return {
|
34
|
+
type: :success,
|
35
|
+
args: {
|
36
|
+
type: :mysql,
|
37
|
+
subtype: :java,
|
38
|
+
conn: args[:object],
|
39
|
+
query_args: {
|
40
|
+
as: :hash,
|
41
|
+
symbolize_keys: true
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
32
45
|
end
|
33
46
|
|
34
47
|
return nil
|
35
48
|
end
|
36
49
|
|
37
|
-
def initialize(
|
38
|
-
@
|
39
|
-
@opts = @
|
50
|
+
def initialize(baza)
|
51
|
+
@baza = baza
|
52
|
+
@opts = @baza.opts
|
40
53
|
@sep_table = "`"
|
41
54
|
@sep_col = "`"
|
42
55
|
@sep_val = "'"
|
@@ -50,22 +63,22 @@ class Baza::Driver::Mysql
|
|
50
63
|
@encoding = "utf8"
|
51
64
|
end
|
52
65
|
|
53
|
-
if @
|
54
|
-
@port = @
|
66
|
+
if @baza.opts.key?(:port)
|
67
|
+
@port = @baza.opts[:port].to_i
|
55
68
|
else
|
56
69
|
@port = 3306
|
57
70
|
end
|
58
71
|
|
59
72
|
@java_rs_data = {}
|
60
|
-
@subtype = @
|
61
|
-
@subtype
|
62
|
-
|
73
|
+
@subtype = @baza.opts[:subtype]
|
74
|
+
@subtype ||= :mysql
|
75
|
+
reconnect
|
63
76
|
end
|
64
77
|
|
65
78
|
#This method handels the closing of statements and results for the Java MySQL-mode.
|
66
79
|
def java_mysql_resultset_killer(id)
|
67
80
|
data = @java_rs_data[id]
|
68
|
-
return nil
|
81
|
+
return nil unless data
|
69
82
|
|
70
83
|
data[:res].close
|
71
84
|
data[:stmt].close
|
@@ -74,7 +87,7 @@ class Baza::Driver::Mysql
|
|
74
87
|
|
75
88
|
#Cleans the wref-map holding the tables.
|
76
89
|
def clean
|
77
|
-
|
90
|
+
tables.clean if tables
|
78
91
|
end
|
79
92
|
|
80
93
|
#Respawns the connection to the MySQL-database.
|
@@ -82,16 +95,16 @@ class Baza::Driver::Mysql
|
|
82
95
|
@mutex.synchronize do
|
83
96
|
case @subtype
|
84
97
|
when :mysql
|
85
|
-
@conn = Mysql.real_connect(@
|
98
|
+
@conn = Mysql.real_connect(@baza.opts[:host], @baza.opts[:user], @baza.opts[:pass], @baza.opts[:db], @port)
|
86
99
|
when :mysql2
|
87
100
|
require "rubygems"
|
88
101
|
require "mysql2"
|
89
102
|
|
90
103
|
args = {
|
91
|
-
host: @
|
92
|
-
username: @
|
93
|
-
password: @
|
94
|
-
database: @
|
104
|
+
host: @baza.opts[:host],
|
105
|
+
username: @baza.opts[:user],
|
106
|
+
password: @baza.opts[:pass],
|
107
|
+
database: @baza.opts[:db],
|
95
108
|
port: @port,
|
96
109
|
symbolize_keys: true,
|
97
110
|
cache_rows: false
|
@@ -99,11 +112,11 @@ class Baza::Driver::Mysql
|
|
99
112
|
|
100
113
|
#Symbolize keys should also be given here, else table-data wont be symbolized for some reason - knj.
|
101
114
|
@query_args = {symbolize_keys: true}
|
102
|
-
@query_args.merge!(@
|
115
|
+
@query_args.merge!(@baza.opts[:query_args]) if @baza.opts[:query_args]
|
103
116
|
|
104
117
|
pos_args = [:as, :async, :cast_booleans, :database_timezone, :application_timezone, :cache_rows, :connect_flags, :cast]
|
105
118
|
pos_args.each do |key|
|
106
|
-
args[key] = @
|
119
|
+
args[key] = @baza.opts[key] if @baza.opts.key?(key)
|
107
120
|
end
|
108
121
|
|
109
122
|
args[:as] = :array if @opts[:result] == "array"
|
@@ -111,8 +124,8 @@ class Baza::Driver::Mysql
|
|
111
124
|
tries = 0
|
112
125
|
begin
|
113
126
|
tries += 1
|
114
|
-
if @
|
115
|
-
@conn = @
|
127
|
+
if @baza.opts[:conn]
|
128
|
+
@conn = @baza.opts[:conn]
|
116
129
|
else
|
117
130
|
@conn = Mysql2::Client.new(args)
|
118
131
|
end
|
@@ -128,14 +141,20 @@ class Baza::Driver::Mysql
|
|
128
141
|
raise e
|
129
142
|
end
|
130
143
|
when :java
|
131
|
-
|
132
|
-
require "java"
|
133
|
-
require "/usr/share/java/mysql-connector-java.jar" if File.exists?("/usr/share/java/mysql-connector-java.jar")
|
134
|
-
import "com.mysql.jdbc.Driver"
|
144
|
+
if @baza.opts[:conn]
|
135
145
|
@jdbc_loaded = true
|
146
|
+
@conn = @baza.opts[:conn]
|
147
|
+
else
|
148
|
+
unless @jdbc_loaded
|
149
|
+
require "java"
|
150
|
+
require "/usr/share/java/mysql-connector-java.jar" if File.exists?("/usr/share/java/mysql-connector-java.jar")
|
151
|
+
import "com.mysql.jdbc.Driver"
|
152
|
+
@jdbc_loaded = true
|
153
|
+
end
|
154
|
+
|
155
|
+
@conn = java.sql::DriverManager.getConnection("jdbc:mysql://#{@baza.opts[:host]}:#{@port}/#{@baza.opts[:db]}?user=#{@baza.opts[:user]}&password=#{@baza.opts[:pass]}&populateInsertRowWithDefaultValues=true&zeroDateTimeBehavior=round&characterEncoding=#{@encoding}&holdResultsOpenOverStatementClose=true")
|
136
156
|
end
|
137
157
|
|
138
|
-
@conn = java.sql::DriverManager.getConnection("jdbc:mysql://#{@baza_db.opts[:host]}:#{@port}/#{@baza_db.opts[:db]}?user=#{@baza_db.opts[:user]}&password=#{@baza_db.opts[:pass]}&populateInsertRowWithDefaultValues=true&zeroDateTimeBehavior=round&characterEncoding=#{@encoding}&holdResultsOpenOverStatementClose=true")
|
139
158
|
query("SET SQL_MODE = ''")
|
140
159
|
else
|
141
160
|
raise "Unknown subtype: #{@subtype} (#{@subtype.class.name})"
|
@@ -162,7 +181,7 @@ class Baza::Driver::Mysql
|
|
162
181
|
when :java
|
163
182
|
stmt = conn.create_statement
|
164
183
|
|
165
|
-
if str.match(/^\s*(delete|update|create|drop|insert\s+into|alter)\s+/i)
|
184
|
+
if str.match(/^\s*(delete|update|create|drop|insert\s+into|alter|truncate)\s+/i)
|
166
185
|
begin
|
167
186
|
stmt.execute(str)
|
168
187
|
ensure
|
@@ -175,7 +194,7 @@ class Baza::Driver::Mysql
|
|
175
194
|
|
176
195
|
begin
|
177
196
|
res = stmt.execute_query(str)
|
178
|
-
ret = Baza::Driver::Mysql::ResultJava.new(@
|
197
|
+
ret = Baza::Driver::Mysql::ResultJava.new(@baza, @opts, res)
|
179
198
|
id = ret.__id__
|
180
199
|
|
181
200
|
#If ID is being reused we have to free the result.
|
@@ -189,7 +208,8 @@ class Baza::Driver::Mysql
|
|
189
208
|
rescue => e
|
190
209
|
res.close if res
|
191
210
|
stmt.close
|
192
|
-
@java_rs_data.delete(id) if ret
|
211
|
+
@java_rs_data.delete(id) if ret && id
|
212
|
+
|
193
213
|
raise e
|
194
214
|
end
|
195
215
|
end
|
@@ -221,7 +241,7 @@ class Baza::Driver::Mysql
|
|
221
241
|
@conn.query_with_result = false
|
222
242
|
return Baza::Driver::Mysql::ResultUnbuffered.new(@conn, @opts, @conn.query(str))
|
223
243
|
when :mysql2
|
224
|
-
return Baza::Driver::Mysql::
|
244
|
+
return Baza::Driver::Mysql::ResultMysql2.new(@conn.query(str, @query_args.merge(stream: true)))
|
225
245
|
when :java
|
226
246
|
if str.match(/^\s*(delete|update|create|drop|insert\s+into)\s+/i)
|
227
247
|
stmt = @conn.createStatement
|
@@ -239,7 +259,7 @@ class Baza::Driver::Mysql
|
|
239
259
|
|
240
260
|
begin
|
241
261
|
res = stmt.executeQuery(str)
|
242
|
-
ret = Baza::Driver::Mysql::ResultJava.new(@
|
262
|
+
ret = Baza::Driver::Mysql::ResultJava.new(@baza, @opts, res)
|
243
263
|
|
244
264
|
#Save reference to result and statement, so we can close them when they are garbage collected.
|
245
265
|
@java_rs_data[ret.__id__] = {res: res, stmt: stmt}
|
@@ -323,7 +343,7 @@ class Baza::Driver::Mysql
|
|
323
343
|
#Destroyes the connection.
|
324
344
|
def destroy
|
325
345
|
@conn = nil
|
326
|
-
@
|
346
|
+
@baza = nil
|
327
347
|
@mutex = nil
|
328
348
|
@subtype = nil
|
329
349
|
@encoding = nil
|
@@ -369,7 +389,7 @@ class Baza::Driver::Mysql
|
|
369
389
|
sql << ","
|
370
390
|
end
|
371
391
|
|
372
|
-
sql << @
|
392
|
+
sql << @baza.sqlval(val)
|
373
393
|
end
|
374
394
|
else
|
375
395
|
hash.each do |key, val|
|
@@ -379,7 +399,7 @@ class Baza::Driver::Mysql
|
|
379
399
|
sql << ","
|
380
400
|
end
|
381
401
|
|
382
|
-
sql << @
|
402
|
+
sql << @baza.sqlval(val)
|
383
403
|
end
|
384
404
|
end
|
385
405
|
end
|
@@ -410,13 +430,13 @@ class Baza::Driver::Mysql
|
|
410
430
|
|
411
431
|
#Starts a transaction, yields the database and commits at the end.
|
412
432
|
def transaction
|
413
|
-
@
|
433
|
+
@baza.q("START TRANSACTION")
|
414
434
|
|
415
435
|
begin
|
416
|
-
yield @
|
417
|
-
@
|
436
|
+
yield @baza
|
437
|
+
@baza.q("COMMIT")
|
418
438
|
rescue
|
419
|
-
@
|
439
|
+
@baza.q("ROLLBACK")
|
420
440
|
raise
|
421
441
|
end
|
422
442
|
end
|