baza 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +157 -0
  3. data/Gemfile +11 -9
  4. data/Gemfile.lock +41 -9
  5. data/README.md +1 -1
  6. data/Rakefile +19 -16
  7. data/VERSION +1 -1
  8. data/baza.gemspec +31 -7
  9. data/config/best_project_practice_rubocop.yml +2 -0
  10. data/config/best_project_practice_rubocop_todo.yml +157 -0
  11. data/lib/baza/base_sql_driver.rb +79 -20
  12. data/lib/baza/cloner.rb +2 -2
  13. data/lib/baza/column.rb +6 -0
  14. data/lib/baza/database.rb +33 -0
  15. data/lib/baza/database_model.rb +26 -0
  16. data/lib/baza/database_model_functionality.rb +10 -0
  17. data/lib/baza/database_model_name.rb +16 -0
  18. data/lib/baza/db.rb +210 -413
  19. data/lib/baza/dbtime.rb +20 -20
  20. data/lib/baza/driver.rb +3 -3
  21. data/lib/baza/drivers/active_record/columns.rb +1 -1
  22. data/lib/baza/drivers/active_record/indexes.rb +1 -1
  23. data/lib/baza/drivers/active_record/result.rb +3 -5
  24. data/lib/baza/drivers/active_record/tables.rb +2 -2
  25. data/lib/baza/drivers/active_record.rb +30 -16
  26. data/lib/baza/drivers/mysql/column.rb +51 -48
  27. data/lib/baza/drivers/mysql/columns.rb +8 -8
  28. data/lib/baza/drivers/mysql/database.rb +28 -0
  29. data/lib/baza/drivers/mysql/databases.rb +35 -0
  30. data/lib/baza/drivers/mysql/index.rb +32 -22
  31. data/lib/baza/drivers/mysql/result.rb +24 -24
  32. data/lib/baza/drivers/mysql/sqlspecs.rb +1 -1
  33. data/lib/baza/drivers/mysql/table.rb +80 -91
  34. data/lib/baza/drivers/mysql/tables.rb +30 -32
  35. data/lib/baza/drivers/mysql/unbuffered_result.rb +5 -5
  36. data/lib/baza/drivers/mysql.rb +127 -220
  37. data/lib/baza/drivers/mysql2/database.rb +2 -0
  38. data/lib/baza/drivers/mysql2/databases.rb +2 -0
  39. data/lib/baza/drivers/mysql2/result.rb +3 -5
  40. data/lib/baza/drivers/mysql2.rb +21 -106
  41. data/lib/baza/drivers/mysql_java/database.rb +2 -0
  42. data/lib/baza/drivers/mysql_java/databases.rb +2 -0
  43. data/lib/baza/drivers/mysql_java.rb +16 -12
  44. data/lib/baza/drivers/sqlite3/column.rb +33 -33
  45. data/lib/baza/drivers/sqlite3/columns.rb +6 -6
  46. data/lib/baza/drivers/sqlite3/database.rb +2 -0
  47. data/lib/baza/drivers/sqlite3/databases.rb +25 -0
  48. data/lib/baza/drivers/sqlite3/index.rb +20 -6
  49. data/lib/baza/drivers/sqlite3/result.rb +16 -17
  50. data/lib/baza/drivers/sqlite3/sqlspecs.rb +1 -1
  51. data/lib/baza/drivers/sqlite3/table.rb +99 -100
  52. data/lib/baza/drivers/sqlite3/tables.rb +30 -23
  53. data/lib/baza/drivers/sqlite3/unbuffered_result.rb +2 -2
  54. data/lib/baza/drivers/sqlite3.rb +27 -14
  55. data/lib/baza/drivers/sqlite3_java/database.rb +2 -0
  56. data/lib/baza/drivers/sqlite3_java/unbuffered_result.rb +2 -2
  57. data/lib/baza/drivers/sqlite3_java.rb +12 -10
  58. data/lib/baza/drivers/sqlite3_rhodes.rb +9 -7
  59. data/lib/baza/dump.rb +55 -55
  60. data/lib/baza/errors.rb +5 -0
  61. data/lib/baza/idquery.rb +25 -25
  62. data/lib/baza/index.rb +6 -0
  63. data/lib/baza/jdbc_driver.rb +6 -8
  64. data/lib/baza/jdbc_result.rb +1 -1
  65. data/lib/baza/model.rb +299 -309
  66. data/lib/baza/model_custom.rb +74 -72
  67. data/lib/baza/model_handler.rb +244 -255
  68. data/lib/baza/model_handler_sqlhelper.rb +122 -132
  69. data/lib/baza/mysql_base_driver.rb +112 -0
  70. data/lib/baza/query_buffer.rb +23 -23
  71. data/lib/baza/result_base.rb +2 -2
  72. data/lib/baza/revision.rb +67 -67
  73. data/lib/baza/row.rb +82 -84
  74. data/lib/baza/sqlspecs.rb +1 -1
  75. data/lib/baza/table.rb +31 -0
  76. data/lib/baza.rb +43 -10
  77. data/shippable.yml +1 -0
  78. data/spec/cloner_spec.rb +4 -4
  79. data/spec/drivers/active_record_mysql2_spec.rb +3 -3
  80. data/spec/drivers/active_record_mysql_spec.rb +2 -2
  81. data/spec/drivers/active_record_sqlite3_spec.rb +2 -2
  82. data/spec/drivers/mysql2_spec.rb +1 -0
  83. data/spec/drivers/mysql_spec.rb +1 -0
  84. data/spec/drivers/sqlite3_spec.rb +4 -5
  85. data/spec/info_active_record_example.rb +4 -6
  86. data/spec/info_active_record_mysql.rb +6 -7
  87. data/spec/info_active_record_mysql2.rb +2 -4
  88. data/spec/info_active_record_mysql2_shippable.rb +2 -4
  89. data/spec/info_active_record_mysql_shippable.rb +2 -4
  90. data/spec/info_active_record_sqlite3.rb +5 -6
  91. data/spec/info_mysql2_example.rb +1 -1
  92. data/spec/info_mysql2_shippable.rb +1 -1
  93. data/spec/info_mysql_example.rb +1 -1
  94. data/spec/info_mysql_shippable.rb +1 -1
  95. data/spec/info_sqlite3.rb +4 -3
  96. data/spec/model_handler_spec.rb +102 -115
  97. data/spec/spec_helper.rb +5 -5
  98. data/spec/support/driver_collection.rb +98 -95
  99. data/spec/support/driver_columns_collection.rb +18 -22
  100. data/spec/support/driver_databases_collection.rb +29 -0
  101. data/spec/support/driver_indexes_collection.rb +7 -6
  102. data/spec/support/driver_tables_collection.rb +38 -26
  103. metadata +49 -3
@@ -1,220 +1,127 @@
1
- class Baza::Driver::Mysql < Baza::BaseSqlDriver
2
- path = "#{File.dirname(__FILE__)}/mysql"
3
-
4
- autoload :Table, "#{path}/table"
5
- autoload :Tables, "#{path}/tables"
6
- autoload :Column, "#{path}/column"
7
- autoload :Columns, "#{path}/columns"
8
- autoload :Index, "#{path}/index"
9
- autoload :Indexes, "#{path}/indexes"
10
- autoload :Result, "#{path}/result"
11
- autoload :UnbufferedResult, "#{path}/unbuffered_result"
12
- autoload :Sqlspecs, "#{path}/sqlspecs"
13
-
14
- attr_reader :conn
15
-
16
- def self.from_object(args)
17
- raise 'Mysql does not support auth extraction' if args[:object].class.name == 'Mysql'
18
- end
19
-
20
- def initialize(baza)
21
- super
22
-
23
- @opts = @baza.opts
24
-
25
- require 'monitor'
26
- @mutex = Monitor.new
27
-
28
- if baza.opts[:conn]
29
- @conn = baza.opts[:conn]
30
- else
31
- if @opts[:encoding]
32
- @encoding = @opts[:encoding]
33
- else
34
- @encoding = 'utf8'
35
- end
36
-
37
- if @baza.opts.key?(:port)
38
- @port = @baza.opts[:port].to_i
39
- else
40
- @port = 3306
41
- end
42
-
43
- reconnect
44
- end
45
- end
46
-
47
- #This method handels the closing of statements and results for the Java MySQL-mode.
48
- def java_mysql_resultset_killer(id)
49
- data = @java_rs_data[id]
50
- return nil unless data
51
-
52
- data[:res].close
53
- data[:stmt].close
54
- @java_rs_data.delete(id)
55
- end
56
-
57
- #Cleans the wref-map holding the tables.
58
- def clean
59
- tables.clean if tables
60
- end
61
-
62
- #Respawns the connection to the MySQL-database.
63
- def reconnect
64
- @mutex.synchronize do
65
- require 'mysql' unless ::Object.const_defined?(:Mysql)
66
- @conn = ::Mysql.real_connect(@baza.opts[:host], @baza.opts[:user], @baza.opts[:pass], @baza.opts[:db], @port)
67
- query("SET NAMES '#{self.esc(@encoding)}'") if @encoding
68
- end
69
- end
70
-
71
- #Executes a query and returns the result.
72
- def query(str)
73
- str = str.to_s
74
- str = str.force_encoding("UTF-8") if @encoding == "utf8" and str.respond_to?(:force_encoding)
75
- tries = 0
76
-
77
- begin
78
- tries += 1
79
- @mutex.synchronize do
80
- return Baza::Driver::Mysql::Result.new(self, @conn.query(str))
81
- end
82
- rescue => e
83
- if tries <= 3
84
- if e.message == "MySQL server has gone away" || e.message == "closed MySQL connection" or e.message == "Can't connect to local MySQL server through socket"
85
- sleep 0.5
86
- reconnect
87
- retry
88
- elsif e.message.include?("No operations allowed after connection closed") or e.message == "This connection is still waiting for a result, try again once you have the result" or e.message == "Lock wait timeout exceeded; try restarting transaction"
89
- reconnect
90
- retry
91
- end
92
- end
93
-
94
- raise e
95
- end
96
- end
97
-
98
- #Executes an unbuffered query and returns the result that can be used to access the data.
99
- def query_ubuf(str)
100
- @mutex.synchronize do
101
- @conn.query_with_result = false
102
- return Baza::Driver::Mysql::UnbufferedResult.new(@conn, @opts, @conn.query(str))
103
- end
104
- end
105
-
106
- #Escapes a string to be safe to use in a query.
107
- def escape_alternative(string)
108
- return @conn.escape_string(string.to_s)
109
- end
110
-
111
- #Returns the last inserted ID for the connection.
112
- def last_id
113
- @mutex.synchronize { return @conn.insert_id.to_i }
114
- end
115
-
116
- #Closes the connection threadsafe.
117
- def close
118
- @mutex.synchronize { @conn.close }
119
- end
120
-
121
- #Destroyes the connection.
122
- def destroy
123
- @conn = nil
124
- @baza = nil
125
- @mutex = nil
126
- @subtype = nil
127
- @encoding = nil
128
- @query_args = nil
129
- @port = nil
130
- end
131
-
132
- #Inserts multiple rows in a table. Can return the inserted IDs if asked to in arguments.
133
- def insert_multi(tablename, arr_hashes, args = nil)
134
- sql = "INSERT INTO `#{tablename}` ("
135
-
136
- first = true
137
- if args && args[:keys]
138
- keys = args[:keys]
139
- elsif arr_hashes.first.is_a?(Hash)
140
- keys = arr_hashes.first.keys
141
- else
142
- raise "Could not figure out keys."
143
- end
144
-
145
- keys.each do |col_name|
146
- sql << "," unless first
147
- first = false if first
148
- sql << "`#{self.esc_col(col_name)}`"
149
- end
150
-
151
- sql << ") VALUES ("
152
-
153
- first = true
154
- arr_hashes.each do |hash|
155
- if first
156
- first = false
157
- else
158
- sql << "),("
159
- end
160
-
161
- first_key = true
162
- if hash.is_a?(Array)
163
- hash.each do |val|
164
- if first_key
165
- first_key = false
166
- else
167
- sql << ","
168
- end
169
-
170
- sql << @baza.sqlval(val)
171
- end
172
- else
173
- hash.each do |key, val|
174
- if first_key
175
- first_key = false
176
- else
177
- sql << ","
178
- end
179
-
180
- sql << @baza.sqlval(val)
181
- end
182
- end
183
- end
184
-
185
- sql << ")"
186
-
187
- return sql if args && args[:return_sql]
188
-
189
- self.query(sql)
190
-
191
- if args && args[:return_id]
192
- first_id = self.last_id
193
- raise "Invalid ID: #{first_id}" if first_id.to_i <= 0
194
- ids = [first_id]
195
- 1.upto(arr_hashes.length - 1) do |count|
196
- ids << first_id + count
197
- end
198
-
199
- ids_length = ids.length
200
- arr_hashes_length = arr_hashes.length
201
- raise "Invalid length (#{ids_length}, #{arr_hashes_length})." unless ids_length == arr_hashes_length
202
-
203
- return ids
204
- else
205
- return nil
206
- end
207
- end
208
-
209
- def transaction
210
- @baza.q("START TRANSACTION")
211
-
212
- begin
213
- yield @baza
214
- @baza.q("COMMIT")
215
- rescue
216
- @baza.q("ROLLBACK")
217
- raise
218
- end
219
- end
220
- end
1
+ class Baza::Driver::Mysql < Baza::MysqlBaseDriver
2
+ path = "#{File.dirname(__FILE__)}/mysql"
3
+
4
+ autoload :Database, "#{path}/database"
5
+ autoload :Databases, "#{path}/databases"
6
+ autoload :Table, "#{path}/table"
7
+ autoload :Tables, "#{path}/tables"
8
+ autoload :Column, "#{path}/column"
9
+ autoload :Columns, "#{path}/columns"
10
+ autoload :Index, "#{path}/index"
11
+ autoload :Indexes, "#{path}/indexes"
12
+ autoload :Result, "#{path}/result"
13
+ autoload :UnbufferedResult, "#{path}/unbuffered_result"
14
+ autoload :Sqlspecs, "#{path}/sqlspecs"
15
+
16
+ attr_reader :conn
17
+
18
+ def self.from_object(args)
19
+ raise "Mysql does not support auth extraction" if args[:object].class.name == "Mysql"
20
+ end
21
+
22
+ def initialize(baza)
23
+ super
24
+
25
+ @opts = @baza.opts
26
+
27
+ require "monitor"
28
+ @mutex = Monitor.new
29
+
30
+ if baza.opts[:conn]
31
+ @conn = baza.opts[:conn]
32
+ else
33
+ if @opts[:encoding]
34
+ @encoding = @opts[:encoding]
35
+ else
36
+ @encoding = "utf8"
37
+ end
38
+
39
+ if @baza.opts.key?(:port)
40
+ @port = @baza.opts[:port].to_i
41
+ else
42
+ @port = 3306
43
+ end
44
+
45
+ reconnect
46
+ end
47
+ end
48
+
49
+ # Cleans the wref-map holding the tables.
50
+ def clean
51
+ tables.clean if tables
52
+ end
53
+
54
+ # Respawns the connection to the MySQL-database.
55
+ def reconnect
56
+ @mutex.synchronize do
57
+ require "mysql" unless ::Object.const_defined?(:Mysql)
58
+ @conn = ::Mysql.real_connect(@baza.opts[:host], @baza.opts[:user], @baza.opts[:pass], @baza.opts[:db], @port)
59
+ query("SET NAMES '#{esc(@encoding)}'") if @encoding
60
+ end
61
+ end
62
+
63
+ # Executes a query and returns the result.
64
+ def query(str)
65
+ str = str.to_s
66
+ str = str.force_encoding("UTF-8") if @encoding == "utf8" && str.respond_to?(:force_encoding)
67
+ tries = 0
68
+
69
+ begin
70
+ tries += 1
71
+ @mutex.synchronize do
72
+ return Baza::Driver::Mysql::Result.new(self, @conn.query(str))
73
+ end
74
+ rescue => e
75
+ if tries <= 3
76
+ if e.message == "MySQL server has gone away" || e.message == "closed MySQL connection" || e.message == "Can't connect to local MySQL server through socket"
77
+ sleep 0.5
78
+ reconnect
79
+ retry
80
+ elsif e.message.include?("No operations allowed after connection closed") || e.message == "This connection is still waiting for a result, try again once you have the result" || e.message == "Lock wait timeout exceeded; try restarting transaction"
81
+ reconnect
82
+ retry
83
+ end
84
+ end
85
+
86
+ raise e
87
+ end
88
+ end
89
+
90
+ # Executes an unbuffered query and returns the result that can be used to access the data.
91
+ def query_ubuf(str)
92
+ @mutex.synchronize do
93
+ @conn.query_with_result = false
94
+ return Baza::Driver::Mysql::UnbufferedResult.new(@conn, @opts, @conn.query(str))
95
+ end
96
+ end
97
+
98
+ # Escapes a string to be safe to use in a query.
99
+ def escape_alternative(string)
100
+ @conn.escape_string(string.to_s)
101
+ end
102
+
103
+ # Returns the last inserted ID for the connection.
104
+ def last_id
105
+ @mutex.synchronize { return @conn.insert_id.to_i }
106
+ end
107
+
108
+ # Closes the connection threadsafe.
109
+ def close
110
+ @mutex.synchronize { @conn.close }
111
+ end
112
+
113
+ # Destroyes the connection.
114
+ def destroy
115
+ @conn = nil
116
+ @baza = nil
117
+ @mutex = nil
118
+ @subtype = nil
119
+ @encoding = nil
120
+ @query_args = nil
121
+ @port = nil
122
+ end
123
+
124
+ def supports_multiple_databases?
125
+ true
126
+ end
127
+ end
@@ -0,0 +1,2 @@
1
+ class Baza::Driver::Mysql2::Database < Baza::Driver::Mysql::Database
2
+ end
@@ -0,0 +1,2 @@
1
+ class Baza::Driver::Mysql2::Databases < Baza::Driver::Mysql::Databases
2
+ end
@@ -8,11 +8,9 @@ class Baza::Driver::Mysql2::Result < Baza::ResultBase
8
8
 
9
9
  # Returns a single result.
10
10
  def fetch
11
- begin
12
- return to_enum.next
13
- rescue StopIteration
14
- return false
15
- end
11
+ return to_enum.next
12
+ rescue StopIteration
13
+ return false
16
14
  end
17
15
 
18
16
  # Loops over every single result yielding it.
@@ -1,6 +1,10 @@
1
- class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
1
+ Baza.load_driver("mysql")
2
+
3
+ class Baza::Driver::Mysql2 < Baza::MysqlBaseDriver
2
4
  path = "#{File.dirname(__FILE__)}/mysql2"
3
5
 
6
+ autoload :Database, "#{path}/database"
7
+ autoload :Databases, "#{path}/databases"
4
8
  autoload :Table, "#{path}/table"
5
9
  autoload :Tables, "#{path}/tables"
6
10
  autoload :Column, "#{path}/column"
@@ -13,7 +17,7 @@ class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
13
17
 
14
18
  attr_reader :conn, :conns
15
19
 
16
- #Helper to enable automatic registering of database using Baza::Db.from_object
20
+ # Helper to enable automatic registering of database using Baza::Db.from_object
17
21
  def self.from_object(args)
18
22
  if args[:object].class.name == "Mysql2::Client"
19
23
  return {
@@ -28,7 +32,7 @@ class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
28
32
  }
29
33
  end
30
34
 
31
- return nil
35
+ nil
32
36
  end
33
37
 
34
38
  def initialize(baza)
@@ -54,12 +58,12 @@ class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
54
58
  reconnect
55
59
  end
56
60
 
57
- #Cleans the wref-map holding the tables.
61
+ # Cleans the wref-map holding the tables.
58
62
  def clean
59
63
  tables.clean if tables
60
64
  end
61
65
 
62
- #Respawns the connection to the MySQL-database.
66
+ # Respawns the connection to the MySQL-database.
63
67
  def reconnect
64
68
  @mutex.synchronize do
65
69
  args = {
@@ -72,8 +76,8 @@ class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
72
76
  cache_rows: false
73
77
  }
74
78
 
75
- #Symbolize keys should also be given here, else table-data wont be symbolized for some reason - knj.
76
- @query_args = {symbolize_keys: true,}
79
+ # Symbolize keys should also be given here, else table-data wont be symbolized for some reason - knj.
80
+ @query_args = {symbolize_keys: true}
77
81
  @query_args[:cast] = false unless @baza.opts[:type_translation]
78
82
  @query_args.merge!(@baza.opts[:query_args]) if @baza.opts[:query_args]
79
83
 
@@ -109,7 +113,7 @@ class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
109
113
  end
110
114
  end
111
115
 
112
- #Executes a query and returns the result.
116
+ # Executes a query and returns the result.
113
117
  def query(str)
114
118
  str = str.to_s
115
119
  str = str.force_encoding("UTF-8") if @encoding == "utf8" && str.respond_to?(:force_encoding)
@@ -122,11 +126,11 @@ class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
122
126
  end
123
127
  rescue => e
124
128
  if tries <= 3
125
- if e.message == "MySQL server has gone away" || e.message == "closed MySQL connection" or e.message == "Can't connect to local MySQL server through socket"
129
+ if e.message == "MySQL server has gone away" || e.message == "closed MySQL connection" || e.message == "Can't connect to local MySQL server through socket"
126
130
  sleep 0.5
127
131
  reconnect
128
132
  retry
129
- elsif e.message.include?("No operations allowed after connection closed") or e.message == "This connection is still waiting for a result, try again once you have the result" or e.message == "Lock wait timeout exceeded; try restarting transaction"
133
+ elsif e.message.include?("No operations allowed after connection closed") || e.message == "This connection is still waiting for a result, try again once you have the result" || e.message == "Lock wait timeout exceeded; try restarting transaction"
130
134
  reconnect
131
135
  retry
132
136
  end
@@ -136,29 +140,29 @@ class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
136
140
  end
137
141
  end
138
142
 
139
- #Executes an unbuffered query and returns the result that can be used to access the data.
140
- def query_ubuf(str)
143
+ # Executes an unbuffered query and returns the result that can be used to access the data.
144
+ def query_ubuf(str, _args = nil, &_blk)
141
145
  @mutex.synchronize do
142
146
  return Baza::Driver::Mysql2::Result.new(self, @conn.query(str, @query_args.merge(stream: true)))
143
147
  end
144
148
  end
145
149
 
146
- #Escapes a string to be safe to use in a query.
150
+ # Escapes a string to be safe to use in a query.
147
151
  def escape(string)
148
- return @conn.escape(string.to_s)
152
+ @conn.escape(string.to_s)
149
153
  end
150
154
 
151
- #Returns the last inserted ID for the connection.
155
+ # Returns the last inserted ID for the connection.
152
156
  def last_id
153
157
  @mutex.synchronize { return @conn.last_id.to_i }
154
158
  end
155
159
 
156
- #Closes the connection threadsafe.
160
+ # Closes the connection threadsafe.
157
161
  def close
158
162
  @mutex.synchronize { @conn.close }
159
163
  end
160
164
 
161
- #Destroyes the connection.
165
+ # Destroyes the connection.
162
166
  def destroy
163
167
  @conn = nil
164
168
  @baza = nil
@@ -167,93 +171,4 @@ class Baza::Driver::Mysql2 < Baza::BaseSqlDriver
167
171
  @query_args = nil
168
172
  @port = nil
169
173
  end
170
-
171
- #Inserts multiple rows in a table. Can return the inserted IDs if asked to in arguments.
172
- def insert_multi(tablename, arr_hashes, args = nil)
173
- sql = "INSERT INTO `#{tablename}` ("
174
-
175
- first = true
176
- if args && args[:keys]
177
- keys = args[:keys]
178
- elsif arr_hashes.first.is_a?(Hash)
179
- keys = arr_hashes.first.keys
180
- else
181
- raise "Could not figure out keys."
182
- end
183
-
184
- keys.each do |col_name|
185
- sql << "," unless first
186
- first = false if first
187
- sql << "`#{self.esc_col(col_name)}`"
188
- end
189
-
190
- sql << ") VALUES ("
191
-
192
- first = true
193
- arr_hashes.each do |hash|
194
- if first
195
- first = false
196
- else
197
- sql << "),("
198
- end
199
-
200
- first_key = true
201
- if hash.is_a?(Array)
202
- hash.each do |val|
203
- if first_key
204
- first_key = false
205
- else
206
- sql << ","
207
- end
208
-
209
- sql << @baza.sqlval(val)
210
- end
211
- else
212
- hash.each do |key, val|
213
- if first_key
214
- first_key = false
215
- else
216
- sql << ","
217
- end
218
-
219
- sql << @baza.sqlval(val)
220
- end
221
- end
222
- end
223
-
224
- sql << ")"
225
-
226
- return sql if args && args[:return_sql]
227
-
228
- query(sql)
229
-
230
- if args && args[:return_id]
231
- first_id = self.last_id
232
- raise "Invalid ID: #{first_id}" if first_id.to_i <= 0
233
- ids = [first_id]
234
- 1.upto(arr_hashes.length - 1) do |count|
235
- ids << first_id + count
236
- end
237
-
238
- ids_length = ids.length
239
- arr_hashes_length = arr_hashes.length
240
- raise "Invalid length (#{ids_length}, #{arr_hashes_length})." if ids_length != arr_hashes_length
241
-
242
- return ids
243
- else
244
- return nil
245
- end
246
- end
247
-
248
- def transaction
249
- @baza.q("START TRANSACTION")
250
-
251
- begin
252
- yield @baza
253
- @baza.q("COMMIT")
254
- rescue
255
- @baza.q("ROLLBACK")
256
- raise
257
- end
258
- end
259
174
  end
@@ -0,0 +1,2 @@
1
+ class Baza::Driver::Mysqljava::Database < Baza::Database
2
+ end
@@ -0,0 +1,2 @@
1
+ class Baza::Driver::Mysqljava::Databases < Baza::Driver::Mysql::Databases
2
+ end