Sha256: 5cc2b90d19edd772701285780ae44cc03bce4b0c7f951d9b431435bb62699da6

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 KB

Contents

require 'sequel_core/adapters/shared/mysql'

module Sequel
  module JDBC
    # Database and Dataset instance methods for MySQL specific
    # support via JDBC.
    module MySQL
      # Database instance methods for MySQL databases accessed via JDBC.
      module DatabaseMethods
        include Sequel::MySQL::DatabaseMethods
        
        # Return instance of Sequel::JDBC::MySQL::Dataset with the given opts.
        def dataset(opts=nil)
          Sequel::JDBC::MySQL::Dataset.new(self, opts)
        end
        
        private
        
        # The database name for the given database.  Need to parse it out
        # of the connection string, since the JDBC does no parsing on the
        # given connection string by default.
        def database_name
          u = URI.parse(uri.sub(/\Ajdbc:/, ''))
          (m = /\/(.*)/.match(u.path)) && m[1]
        end
        
        # Get the last inserted id using LAST_INSERT_ID().
        def last_insert_id(conn, opts={})
          stmt = conn.createStatement
          begin
            rs = stmt.executeQuery('SELECT LAST_INSERT_ID()')
            rs.next
            rs.getInt(1)
          ensure
            stmt.close
          end
        end
      end
      
      # Dataset class for MySQL datasets accessed via JDBC.
      class Dataset < JDBC::Dataset
        include Sequel::MySQL::DatasetMethods
        
        # Use execute_insert to execute the insert_sql.
        def insert(*values)
          execute_insert(insert_sql(*values))
        end
        
        # Use execute_insert to execute the replace_sql.
        def replace(*args)
          execute_insert(replace_sql(*args))
        end
        
        private
        
        # Call execute_insert on the database.
        def execute_insert(sql, opts={})
          @db.execute_insert(sql, {:server=>@opts[:server] || :default}.merge(opts))
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sequel-2.5.0 lib/sequel_core/adapters/jdbc/mysql.rb
sequel-2.7.0 lib/sequel_core/adapters/jdbc/mysql.rb
sequel-2.4.0 lib/sequel_core/adapters/jdbc/mysql.rb
sequel-2.8.0 lib/sequel_core/adapters/jdbc/mysql.rb
sequel-2.6.0 lib/sequel_core/adapters/jdbc/mysql.rb
sequel-2.7.1 lib/sequel_core/adapters/jdbc/mysql.rb
sequel-2.9.0 lib/sequel_core/adapters/jdbc/mysql.rb