Skip to content

Commit

Permalink
Some small fixes for MySQL and for upcasing identifiers on JDBC
Browse files Browse the repository at this point in the history
This changes Dataset#upcase_identifiers? to lazily load the setting.
Previously, it was handled in Database#initialize, but on JDBC (and
other adapters that have subadapters), the method that provides the
default hasn't been included in the class when Database#initialize
tried to use it, so this would end up with identifiers being upcased
when using MySQL, PostgreSQL, or SQLite on JDBC.

This fixes Database#alter_table for MySQL, for the drop_index case,
and fixes the MySQL schema parser to handle the fact that the table
name provided to schema_parse_table is now a string instead of a
symbol.
  • Loading branch information
jeremyevans committed Nov 17, 2008
1 parent ace69a0 commit d407190
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/sequel_core/adapters/shared/mysql.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def alter_table_sql(table, op)
when :set_column_type when :set_column_type
"ALTER TABLE #{quote_schema_table(table)} CHANGE COLUMN #{quote_identifier(op[:name])} #{quote_identifier(op[:name])} #{type_literal(op)}" "ALTER TABLE #{quote_schema_table(table)} CHANGE COLUMN #{quote_identifier(op[:name])} #{quote_identifier(op[:name])} #{type_literal(op)}"
when :drop_index when :drop_index
"#{drop_index_sql(table, op)} ON #{quoted_table}" "#{drop_index_sql(table, op)} ON #{quote_schema_table(table)}"
else else
super(table, op) super(table, op)
end end
Expand Down Expand Up @@ -80,7 +80,7 @@ def upcase_identifiers_default


# Use the MySQL specific DESCRIBE syntax to get a table description. # Use the MySQL specific DESCRIBE syntax to get a table description.
def schema_parse_table(table_name, opts) def schema_parse_table(table_name, opts)
self["DESCRIBE ?", table_name].map do |row| self["DESCRIBE ?", SQL::Identifier.new(table_name)].map do |row|
row.delete(:Extra) row.delete(:Extra)
row[:allow_null] = row.delete(:Null) == 'YES' row[:allow_null] = row.delete(:Null) == 'YES'
row[:default] = row.delete(:Default) row[:default] = row.delete(:Default)
Expand Down
3 changes: 1 addition & 2 deletions lib/sequel_core/database.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def initialize(opts = {}, &block)
@opts = opts @opts = opts


@quote_identifiers = opts.include?(:quote_identifiers) ? opts[:quote_identifiers] : @@quote_identifiers @quote_identifiers = opts.include?(:quote_identifiers) ? opts[:quote_identifiers] : @@quote_identifiers
@upcase_identifiers = opts.include?(:upcase_identifiers) ? opts[:upcase_identifiers] : (@@upcase_identifiers.nil? ? upcase_identifiers_default : @@upcase_identifiers)
@single_threaded = opts.include?(:single_threaded) ? opts[:single_threaded] : @@single_threaded @single_threaded = opts.include?(:single_threaded) ? opts[:single_threaded] : @@single_threaded
@schemas = nil @schemas = nil
@prepared_statements = {} @prepared_statements = {}
Expand Down Expand Up @@ -475,7 +474,7 @@ def typecast_value(column_type, value)


# Returns true if the database upcases identifiers. # Returns true if the database upcases identifiers.
def upcase_identifiers? def upcase_identifiers?
@upcase_identifiers @upcase_identifiers ||= @opts.include?(:upcase_identifiers) ? @opts[:upcase_identifiers] : (@@upcase_identifiers.nil? ? upcase_identifiers_default : @@upcase_identifiers)
end end


# Returns the URI identifying the database. # Returns the URI identifying the database.
Expand Down

0 comments on commit d407190

Please sign in to comment.