-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable almost full support for MySQL using JDBC
As much as it pained me, I did the necessary work splitting the MySQL adapter into shared and native parts, and adding the necessary JDBC support. There are still three spec failures, one in the integration specs and two in the MySQL specific specs. One notable feature not working is that MySQL via JDBC does not support the convert_tinyint_to_boolean option. I don't plan to improve the MySQL JDBC situation further, but I'll accept patches to do so. Now that the PostgreSQL, SQLite, and MySQL adapters have been split, I don't plan to add support for other JDBC adapters. It should be fairly easy to add support for the remaining adapters using JDBC, since all of the remaining adapters are fairly small. If you get another adapter working with JDBC, be sure to send a patch/pull request. There were a few related changes made to enable this that are worth mentioning. First is that JDBC::Database got a default transaction method, which hopefully should work on most databases (it appears to work with both SQLite and MySQL). Second is that Dataset#multi_insert now uses execute_dui instead of execute.
- Loading branch information
1 parent
abd1251
commit 33d3cf1
Showing
9 changed files
with
402 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
require 'sequel_core/adapters/shared/mysql' | |||
|
|||
module Sequel | |||
module JDBC | |||
module MySQL | |||
module DatabaseMethods | |||
include Sequel::MySQL::DatabaseMethods | |||
|
|||
def dataset(opts=nil) | |||
Sequel::JDBC::MySQL::Dataset.new(self, opts) | |||
end | |||
|
|||
def execute_insert(sql) | |||
begin | |||
log_info(sql) | |||
@pool.hold do |conn| | |||
stmt = conn.createStatement | |||
begin | |||
stmt.executeUpdate(sql) | |||
rs = stmt.executeQuery('SELECT LAST_INSERT_ID()') | |||
rs.next | |||
rs.getInt(1) | |||
rescue NativeException, JavaSQL::SQLException => e | |||
raise Error, e.message | |||
ensure | |||
stmt.close | |||
end | |||
end | |||
rescue NativeException, JavaSQL::SQLException => e | |||
raise Error, "#{sql}\r\n#{e.message}" | |||
end | |||
end | |||
|
|||
private | |||
|
|||
def database_name | |||
u = URI.parse(uri.sub(/\Ajdbc:/, '')) | |||
(m = /\/(.*)/.match(u.path)) && m[1] | |||
end | |||
end | |||
|
|||
class Dataset < JDBC::Dataset | |||
include Sequel::MySQL::DatasetMethods | |||
|
|||
def insert(*values) | |||
@db.execute_insert(insert_sql(*values)) | |||
end | |||
|
|||
def replace(*args) | |||
@db.execute_insert(replace_sql(*args)) | |||
end | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.