Hi Jeremy,

Thanks Jeremy. It passes the 12 unit tests related to Sequel in my
library.

Also, some more information on the Database#create_table bug with an
index.

I can work around it by explicitly calling #add_index on the Database
object and using String#lit instead of Symbol#identifier.

After taking a look at the code and doing some testing, it looks like
a bunch of methods that rely on #alter_table share the same bug. For
example, #add_column also fails with Symbol#identifier but works with
String#lit.

  # altering a table
  db.add_column :my__table.identifier, :description, :text

the above will fail but below will work:

  # altering a table
  db.add_column :my__table.to_s.lit, :description, :text

Here's the stack trace for #add_column with a Symbol#identifier:

 wrong number of arguments (0 for 1)
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/adapters/
shared/mysql.rb, line: 195, method: to_s »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/adapters/
shared/mysql.rb, line: 195, method: quoted_identifier »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/dataset/
sql.rb, line: 568, method: quote_identifier »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/schema/
sql.rb, line: 197, method: quote_identifier »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/adapters/
shared/mysql.rb, line: 17, method: alter_table_sql »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/schema/
sql.rb, line: 54, method: alter_table_sql_list »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/schema/
sql.rb, line: 54, method: map »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/schema/
sql.rb, line: 54, method: alter_table_sql_list »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/database/
schema.rb, line: 45, method: alter_table »
c:/ruby/lib/ruby/gems/1.8/gems/sequel-2.7.1/lib/sequel_core/database/
schema.rb, line: 11, method: add_column »

I appreciate the time you are spending on keeping the library clean.

Sunny

On Nov 5, 1:10 pm, Jeremy Evans <[EMAIL PROTECTED]> wrote:
> On Nov 5, 11:03 am, Sunny Hirai <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi Jeremy,
>
> > 2.7 does work better but I found a bug with Database#table_exists?.
> > Tried to look at the source but I think you'd probably be able to fix
> > it in 1% of the time it would take me.
>
> >   # FAILURE HERE
> >   #
> >   # table_exists does not work with identifier. This method call
> > incorrectly
> >   # returns false even though we just created the table.
> >   db.table_exists?( :my__table.identifier )
>
> >   # SOME INSIGHT HERE
> >   #
> >   # table_exists does work with #lit, but it probably shouldn't.
> >   db.table_exists?( 'my__table'.lit )
>
> It appears to be due to an optimization that doesn't work unless you
> give table_exists a String or Symbol.  Try this patch:
>
> diff --git a/lib/sequel_core/database.rb b/lib/sequel_core/database.rb
> index b70cce8..90dba15 100644
> --- a/lib/sequel_core/database.rb
> +++ b/lib/sequel_core/database.rb
> @@ -338,12 +338,8 @@ module Sequel
>      # Returns true if a table with the given name exists.
>      def table_exists?(name)
>        begin
> -        if respond_to?(:tables)
> -          tables.include?(name.to_sym)
> -        else
> -          from(name).first
> -          true
> -        end
> +        from(name).first
> +        true
>        rescue
>          false
>        end
>
> This makes a couple of specs fail, but those specs are relying on
> internal behavior and probably shouldn't exist.  Anyway, please test
> this patch.  If it works, I'll apply it and remove the offending
> specs.
>
> Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to