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.
Here's some sample code with the bug and some insight onto the cause
of the bug.
db = Sequel.connect( 'mysql://root:[EMAIL PROTECTED]/test' )
# this works properly now
db.create_table :my__table.identifier do
primary_key :id
column :name, :varchar
end
# 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 )
# getting a dataset from the database with an identifier does work
dataset = db[ :my__table.identifier ]
# looks like the dataset methods work properly
dataset.insert( :name => 'john' )
dataset.filter( :name => 'john' ).update( :name => 'jonathon' )
dataset.first
# dropping a table with the identifier does work
db.drop_table( :my__table.identifier )
Thanks Jeremy.
Sunny
On Nov 4, 10:20 pm, Jeremy Evans <[EMAIL PROTECTED]> wrote:
> On Nov 4, 6:26 pm, Sunny Hirai <[EMAIL PROTECTED]> wrote:
>
> > Thanks for the offer to help Jeremy.
>
> > Okay, I've got it working in Sequel 2.6 but it is a little
> > inconsistent in the way I got it to work. Notably, I need to use
> > String#lit when calling Database#create_table, Database#drop_table or
> > Database#table_exists? on the Sequel::Database object but I need to
> > use Symbol#identifier when creating a dataset from a Database object.
>
> There were a lot of improvements in 2.7 that may help, I would
> recommend trying that.
>
>
>
> > My working sample code looks like this:
>
> > @raw_table_name = 'double__underscores'
>
> > db = Sequel.connect( 'mysql://root:[EMAIL PROTECTED]/test' )
> > db.drop_table @raw_table_name.lit if db.table_exists?
> > ( @raw_table_name.lit )
> > db.create_table @raw_table_name.lit do
> > primary_key :id
> > column :name, :varchar
> > end
> > dataset = db[ @raw_table_name.to_sym.identifier ]
> > dataset.insert( :name => 'alpha' )
> > dataset.insert( :name => 'bravo' )
> > dataset.insert( :name => 'charlie' )
> > dataset.all
>
> > Note that I need to convert the @raw_table_name to a Symbol and then
> > to an identifier when creating the dataset from @db.
>
> > Ultimately, I can work around it now that I know how it works but I'm
> > wondering if this was by design or just an accident. It would make
> > code cleaner to not have to do transformations after generating the
> > table name and instead just generate a single #lit or #identifier
> > object.
>
> Using identifier should work, as that is what it is designed to do.
> Places where it is not working are probably bugs. If you give me
> examples, I will try to fix them. It's better to improve the
> framework than fight it or work around it. If you want to work on
> patches yourself, know that it's not hard to get patches accepted in
> Sequel. If they look good, come with specs, and don't introduce
> regressions, I generally apply them (sometimes with modifications).
>
> 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
-~----------~----~----~----~------~----~------~--~---