Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.map with mysql, when using .field syntax inside map block #175

Closed
jeremyevans opened this issue May 1, 2011 · 4 comments
Closed

.map with mysql, when using .field syntax inside map block #175

jeremyevans opened this issue May 1, 2011 · 4 comments
Assignees

Comments

@jeremyevans
Copy link
Owner

Event.select(:time).limit(2).map{|s| s}
I, [2008-02-09T03:28:30.453212 #3652] INFO -- : SELECT time FROM events ORDER BY id
LIMIT 2
=> [#<Event:0xb732f8cc @primary_key=:id, @changed_columns=[], @new=false,
@values={:time=>Fri Jan 18 19:41:18 +0000 2008}>, #<Event:0xb732f4bc @primary_key=:id,
@changed_columns=[], @new=false, @values={:time=>Fri Jan 18 19:41:21 +0000 2008}>]

That works just fine. But if I try to use one of the fields inside my map block:

Event.select(:time).limit(2).map{|s| s.time}
I, [2008-02-09T03:29:36.677697 #3652] INFO -- : SELECT time FROM events ORDER BY id
LIMIT 2
I, [2008-02-09T03:29:36.678618 #3652] INFO -- : SELECT * FROM events ORDER BY id LIMIT
1
Mysql::Error: Commands out of sync; you can't run this command now
from /usr/local/lib/ruby/gems/1.8/gems/sequel_core-
1.0.5/lib/sequel_core/adapters/mysql.rb:132:in query' from /usr/local/lib/ruby/gems/1.8/gems/sequel_core- 1.0.5/lib/sequel_core/adapters/mysql.rb:132:inexecute_select'

Using a plain dataset, or the hash syntax with models has no issues:

Event.select(:time).limit(2).map{|s| s[:time]}
I, [2008-02-09T03:31:41.327187 #3652] INFO -- : SELECT time FROM events ORDER BY id
LIMIT 2
=> [Fri Jan 18 19:41:18 +0000 2008, Fri Jan 18 19:41:21 +0000 2008]

Sounds like method_missing in the model calls .columns, which tries issuing the new query and
fails? Maybe can just check @values.keys instead?

Google Code Info:
Issue #: 150
Author: themaste...@gmail.com
Created On: 2008-02-09T03:34:34.000Z
Closed On: 2008-02-09T22:12:14.000Z

@ghost ghost assigned jeremyevans May 1, 2011
@jeremyevans
Copy link
Owner Author

I can't recreate the problem. Can you supply a piece of code that recreates the error?

Google Code Info:
Author: cico...@gmail.com
Created On: 2008-02-09T07:00:06.000Z

@jeremyevans
Copy link
Owner Author

require 'sequel'
DB = Sequel('mysql://agp:sequel++@sql.mit.edu/agp+sequel')

require 'logger'
DB.logger = Logger.new($stdout)

class Test < Sequel::Model(:tests)
set_schema do
primary_key :id
varchar :name
end
end

Test.create_table

Test.create :name => 'bob'
Test.create :name => 'adam'

Test.select(:name).map{|s| s.name}

only seems to happen when I use the .select() on the model.

Google Code Info:
Author: themaste...@gmail.com
Created On: 2008-02-09T21:28:51.000Z

@jeremyevans
Copy link
Owner Author

confirmed broken with latest trunk

Google Code Info:
Author: themaste...@gmail.com
Created On: 2008-02-09T21:53:45.000Z

@jeremyevans
Copy link
Owner Author

That was a bit tricky to solve and required relaxing the rules a bit for checking for
valid columns inside Model#method_missing. Fixed in the trunk.

Google Code Info:
Author: cico...@gmail.com
Created On: 2008-02-09T22:12:14.000Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant