Problems loading version 2.3 and undefined method `create' for DBI::Type::Timestamp:Class

47 views
Skip to first unread message

Cássio Marques

unread,
Dec 21, 2009, 12:37:13 PM12/21/09
to Rails SQLServer Adapter
Hello everybody,

This message in actually about two different (I guess) problems.

First, I'm trying to use the activerecord-sqlserver-adapter gem
version 2.3 but I keep getting this error message telling me it cannot
load the file when I try to run script/server

no such file to load -- activerecord-sqlserver-adapter

My environment.rb looks like this:

config.gem 'dbi', :version => '0.4.1'
config.gem 'dbd-odbc', :version => '0.2.4', :lib => 'dbd/ODBC'
config.gem 'activerecord-sqlserver-adapter', :version => '2.2.22'

My gems env:

RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.6 (2008-08-11 patchlevel 287) [universal-
darwin9.0]
- INSTALLATION DIRECTORY:
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/
Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-9
- GEM PATHS:
-
- /Users/cassiomarques/.gem/ruby/1.8
- /Library/Ruby/Gems/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gemcutter.org", "http://
gems.rubyforge.org/", "http://gems.github.com", "http://
gemcutter.org", "http://gems.github.com"]
- "gemcutter_key" => "31bf192bfd58ad85128672889089158d"
- REMOTE SOURCES:
- http://gemcutter.org
- http://gems.rubyforge.org/
- http://gems.github.com

My script/server script:

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'


The interesting thing is that when I change it to use the 2.2.22
version instead of the 2.3, it seems to work and I can access my
database normally.

Another problem I'm having is when searching the database using any
date field, it keeps giving me this error:

undefined method `create' for DBI::Type::Timestamp:Class

For instance, when doing something like this:

def self.find_all_by_date_and_office_code(date, code)
cond = ["CAST(FLOOR( CAST( dateatend AS FLOAT ) ) AS DATETIME) = ?
and id_office = ?", date, code]
find(:all, :conditions => cond)
end


Any ideas?

Thank you very much!

Cássio Marques

unread,
Dec 21, 2009, 12:38:36 PM12/21/09
to Rails SQLServer Adapter
Oh, sorry, in my last message when I pasted the code in my environment.rb I forgot to change the :version => "2.2.22" part to :version => "2.3"

2009/12/21 Cássio Marques <cass...@gmail.com>



--
Cássio Marques

Blog: http://cassiomarques.wordpress.com

If you're writing code and you're not testing it, the code is wrong. I don't care if it does the right thing, and people need to understand this. If it works by accident, you're still wrong.
Bryan Liles - Ruby Hoedown 2008

k...@metaskills.net

unread,
Dec 21, 2009, 1:26:01 PM12/21/09
to Rails SQLServer Adapter

OK, this is real odd. I did some changing in my environment.rb and
when I just switched to 2.3, I got a recursive load error with
messages saying that it could not load 2.2.22 because 2.3 was loaded.
If I removed the config.gem for 2.3 explicitly, it worked fine, which
is what I would have exptected because I know the internals of rails
connection specification file and how it actively tries to load
"activerecord-#{spec}-adapter" per say. But not having a way to
explicitly state what version could be an issue. After about a half
hour, here is what I came up with.

config.gem 'dbi', :version => '0.4.1'
config.gem 'dbd-odbc', :version =>
'0.2.4', :lib => 'dbd/ODBC'
config.gem 'activerecord-sqlserver-adapter', :version =>

'2.3', :lib => 'active_record/connection_adapters/
sqlserver_adapter'

>> ActiveRecord::Base.connection.sqlserver?
=> true
>> ActiveRecord::Base.connection.version
=> "2.3"

I just added the explicit load path and that works. I guess this
should have been there all along, but I have no idea how a change from
2.2.x to 2.3 could have made this blow up. Part of me thinks that
perhaps a rails 2.3.x version would have something to do with the
magic, but I saw nothing in the configuration specification that would
suggest that. Either way, I'll change the docs to reflect this...
after I do the 3.x changes and hopefully as people start to use the
gem bundler (rails3 way) then thisis moot too, but there is the
solution. Sorry I did not find this earlier, still have no idea what
is really happening.

- Ken

>      -http://gems.github.com

Cássio Marques

unread,
Dec 21, 2009, 1:34:38 PM12/21/09
to rails-sqlse...@googlegroups.com
Ok Ken, thank you for your attention, I'll try to config my environment.rb file like you did :)

About the 'undefined method `create' for DBI::Type::Timestamp:Class' error, do you have any ideas?

Thank you!

--

You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
To post to this group, send email to rails-sqlse...@googlegroups.com.
To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rails-sqlserver-adapter?hl=en.


Ken Collins

unread,
Dec 21, 2009, 1:40:38 PM12/21/09
to rails-sqlse...@googlegroups.com

Sure,

Can you tell me what class the "date" object and provide a stack trace?

 - Ken



Ok Ken, thank you for your attention, I'll try to config my environment.rb file like you did :)
About the 'undefined method `create' for DBI::Type::Timestamp:Class' error, do you have any ideas
Thank you!

Cássio Marques

unread,
Dec 21, 2009, 2:03:41 PM12/21/09
to rails-sqlse...@googlegroups.com
The code in my model looks something like this (there are some column names in portuguese, it's a legacy database, I didn'y wrote it! hehe )

class PatientSample < ActiveRecord::Base
  set_table_name 'TB_PACIENTE'  
  coerce_sqlserver_date :dataatend

  def self.find_all_by_date_and_office_code(date, code)         
    cond = ["CAST(FLOOR( CAST( dataatend AS FLOAT ) ) AS DATETIME) = ? and id_posto = ?", date, code]
    find(:all, :conditions => cond)
  end

end

And the stack trace:

Processing MinhasAmostrasController#lista (for 10.10.1.171 at 2009-12-21 16:58:40) [POST]
  Parameters: {"commit"=>"Enviar", "final"=>{"month"=>"12", "day"=>"21", "year"=>"2009"}, "authenticity_token"=>"aldYN5s2Ph4gMdSME6LtAQMLo7Ia7kQy2NwwnjAGZzU=", "inicio"=>{"month"=>"12", "day"=>"14", "year"=>"2009"}}

NoMethodError (undefined method `create' for DBI::Type::Timestamp:Class):
  /home/cassio/.gem/ruby/1.8/gems/dbd-odbc-0.2.5/lib/dbd/odbc/statement.rb:131:in `convert_row'
  /home/cassio/.gem/ruby/1.8/gems/dbd-odbc-0.2.5/lib/dbd/odbc/statement.rb:126:in `collect'
  /home/cassio/.gem/ruby/1.8/gems/dbd-odbc-0.2.5/lib/dbd/odbc/statement.rb:126:in `convert_row'
  /home/cassio/.gem/ruby/1.8/gems/dbd-odbc-0.2.5/lib/dbd/odbc/statement.rb:41:in `fetch'
  dbi (0.4.1) lib/dbi/handles/statement.rb:211:in `fetch'
  dbi (0.4.1) lib/dbi/handles/statement.rb:240:in `each'
  /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.2.22/lib/active_record/connection_adapters/sqlserver_adapter.rb:879:in `inject'
  /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.2.22/lib/active_record/connection_adapters/sqlserver_adapter.rb:879:in `handle_as_array'
  /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.2.22/lib/active_record/connection_adapters/sqlserver_adapter.rb:865:in `raw_select'
  /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/activerecord-sqlserver-adapter-2.2.22/lib/active_record/connection_adapters/sqlserver_adapter.rb:816:in `select'
  app/models/amostra_paciente.rb:112:in `find_all_por_intervalo_data_atendimento_e_codigo_do_posto'
  app/controllers/minhas_amostras_controller.rb:17:in `lista'

Any help would be greatly appreciated! I assume that I suck at SQLServer... had never worked with this database before, all my work is done using mainly PostgreSQL.

Thanks!

--

You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
To post to this group, send email to rails-sqlse...@googlegroups.com.
To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rails-sqlserver-adapter?hl=en.

Ken Collins

unread,
Dec 21, 2009, 3:42:53 PM12/21/09
to rails-sqlse...@googlegroups.com

Is their a column in that table for [dataatend]? If so can you show me this output?

PatientSample.columns_hash['dataatend']

Ken Collins

unread,
Dec 21, 2009, 3:43:21 PM12/21/09
to rails-sqlse...@googlegroups.com

Also, what version of SQL Server do you have?

 - Ken

Cássio Marques

unread,
Dec 22, 2009, 6:26:38 AM12/22/09
to rails-sqlse...@googlegroups.com
I'm afraid I can't... this is really strange! I can start script/console, but it gives me this message:

 /usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:101:in `specification':Gem::Exception: can't activate , already activated dbi-0.4.3

after that, I can't access the database: (AmostraPaciente refers to the PatientSample model from my last message)

>> AmostraPaciente.columns_hash['dataatend']
ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished

I left the activerecord-sqlserver-adapter version as 2.2.22 in my environment.rb, since trying to change it to 2.3 gives me another error:

/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:101:in `specification': can't activate , already activated activerecord-sqlserver-adapter-2.3 (Gem::Exception)

It's really driving me mad! 

Ken Collins

unread,
Dec 22, 2009, 6:28:34 AM12/22/09
to rails-sqlse...@googlegroups.com

Wait a minute, adding the lib option to the SQL Server's config.gem does not work for you???

 - Ken

Cássio Marques

unread,
Dec 22, 2009, 6:28:40 AM12/22/09
to rails-sqlse...@googlegroups.com
but with script/server (not console) and version 2.2.22 at least I can access the database, except for that method where Im getting an 'NoMethodError (undefined method `create' for DBI::Type::Timestamp:Class):' error 

2009/12/22 Cássio Marques <cass...@gmail.com>

Ken Collins

unread,
Dec 22, 2009, 6:29:11 AM12/22/09
to rails-sqlse...@googlegroups.com

BTW, I'm in the IRC room mentioned on the readme #rails-sqlserver if you want to chat.

 - Ken


On Dec 22, 2009, at 6:26 AM, Cássio Marques wrote:

Cássio Marques

unread,
Dec 22, 2009, 6:30:49 AM12/22/09
to rails-sqlse...@googlegroups.com
My environment.rb when trying to use 2.3

config.gem 'dbi', :version => '0.4.1'
config.gem 'dbd-odbc', :version => '0.2.5', :lib => 'dbd/ODBC'
config.gem 'activerecord-sqlserver-adapter', :lib => 'active_record/connection_adapters/sqlserver_adapter', :version => '2.2.3'            

$ rubyee script/server -e production
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:101:in `specification': can't activate , already activated activerecord-sqlserver-adapter-2.3 (Gem::Exception)


With 2.2.22 it loads just fine.

Cássio Marques

unread,
Dec 22, 2009, 6:31:16 AM12/22/09
to rails-sqlse...@googlegroups.com
ok, great :)

Joe Rafaniello

unread,
Dec 22, 2009, 8:41:54 PM12/22/09
to rails-sqlse...@googlegroups.com
I'm not sure if you guys already resolved this in IRC but this sounds like the notoriously bad rubygems "auto-add every stupid gem lib dir into the load path and ALWAYS load the newest version of a gem regardless of what the user wants in config.gem."

From my experience, if you have a gem activerecord-sqlserver-
adapter, at versions 2.2.3 and 2.3 installed in either the rubygems standard gem location or vendor/gems and you require rubygems in your code, you will never be able to load the gem 2.2.3 because 2.3 will always be activated via the gem method.  You can either uninstall the 2.3 gem, not use rubygems, use bundler, or do a clever hack: (although bundler sounds like a better longer time solution):
http://blog.behindlogic.com/2009/08/my-version-of-rubygems.html

Just my 2 cents.

Joe



2009/12/22 Cássio Marques <cass...@gmail.com>

Cássio Marques

unread,
Dec 22, 2009, 9:07:14 PM12/22/09
to rails-sqlse...@googlegroups.com
Hey Joe,

I've come to a 'half solution', since I managed to get my app running with a combination of versions for the dbi, dbd-odbc and sqlserver-adapter gems. However, that was not with the versions I wanted.

Anyway, yes, it's probably due to the terrible Rails gems system, but in conjunction to some problem at my gems env too. I think bundle would be a nice way to try to solve it.

Thanks!

Ken Collins

unread,
Dec 23, 2009, 10:07:20 AM12/23/09
to rails-sqlse...@googlegroups.com

Cássio's issue was mainly related to the way he had multiple versions of ruby installed and hence would have a gem installed but that gem env was not visible to a certain ruby install.

Joe, you are right tho and I know totally what your talking about. A while back ago I started organizing all my gems better using these two articles as a guide for best practices:


The adapter follows these conventions since a few months ago. Nothing for load path, requires changed between 2.2.22 and 2.3 and some voodoo could be related to what your talking about, but for the live of me I could not see it.

 - Ken

Adam Meehan

unread,
Jan 14, 2010, 8:42:33 PM1/14/10
to Rails SQLServer Adapter
I had the same gem loading issue in that I got the 'no such file to
load -- activerecord-sqlserver-adapter ' error, after updating to gem
v2.3.

To rectify it I just had to recreated the missing the file 'lib/
activerecord-sqlserver-adapter.rb' which existed in the 2.2.x
versions. The file is missing because it is no longer listed in the
gem spec as an included file so does not get packaged in the gem. Once
replaced everything works as normal.

I can also successfully switch versions of the gem with the version
option in config.gem. I have verified this in console and server.

Adam

On Dec 24 2009, 2:07 am, Ken Collins <k...@metaskills.net> wrote:
> Cássio's issue was mainly related to the way he had multiple versions of ruby installed and hence would have a gem installed but that gem env was not visible to a certain ruby install.
>
> Joe, you are right tho and I know totally what your talking about. A while back ago I started organizing all my gems better using these two articles as a guide for best practices:
>

> http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practiceshttp://yehudakatz.com/2009/07/24/rubygems-good-practice/


>
> The adapter follows these conventions since a few months ago. Nothing for load path, requires changed between 2.2.22 and 2.3 and some voodoo could be related to what your talking about, but for the live of me I could not see it.
>
>  - Ken
>
> On Dec 22, 2009, at 8:41 PM, Joe Rafaniello wrote:
>
> > I'm not sure if you guys already resolved this in IRC but this sounds like the notoriously bad rubygems "auto-add every stupid gem lib dir into the load path and ALWAYS load the newest version of a gem regardless of what the user wants in config.gem."
>
> > From my experience, if you have a gem activerecord-sqlserver-
> > adapter, at versions 2.2.3 and 2.3 installed in either the rubygems standard gem location or vendor/gems and you require rubygems in your code, you will never be able to load the gem 2.2.3 because 2.3 will always be activated via the gem method.  You can either uninstall the 2.3 gem, not use rubygems, use bundler, or do a clever hack: (although bundler sounds like a better longer time solution):
> >http://blog.behindlogic.com/2009/08/my-version-of-rubygems.html
>
> > Just my 2 cents.
>
> > Joe
>

> > 2009/12/22 Cássio Marques <cassio...@gmail.com>


> > My environment.rb when trying to use 2.3
>
> > config.gem 'dbi', :version => '0.4.1'
> > config.gem 'dbd-odbc', :version => '0.2.5', :lib => 'dbd/ODBC'
> > config.gem 'activerecord-sqlserver-adapter', :lib => 'active_record/connection_adapters/sqlserver_adapter', :version => '2.2.3'            
>
> > $ rubyee script/server -e production
> > => Booting Mongrel

> > => Rails 2.3.5 application starting onhttp://0.0.0.0:3000

> >>>> For more options, visit this group athttp://groups.google.com/group/rails-sqlserver-adapter?hl=en.


>
> >>>> --
> >>>> Cássio Marques
>
> >>>> Blog:http://cassiomarques.wordpress.com
>
> >>>> If you're writing code and you're not testing it, the code is wrong. I don't care if it does the right thing, and people need to understand this. If it works by accident, you're still wrong.
> >>>> Bryan Liles - Ruby Hoedown 2008
>
> >>>> --
>
> >>>> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> >>>> To post to this group, send email to rails-sqlse...@googlegroups.com.
> >>>> To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.

> >>>> For more options, visit this group athttp://groups.google.com/group/rails-sqlserver-adapter?hl=en.


>
> >>> --
>
> >>> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> >>> To post to this group, send email to rails-sqlse...@googlegroups.com.
> >>> To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.

> >>> For more options, visit this group athttp://groups.google.com/group/rails-sqlserver-adapter?hl=en.


>
> >> --
>
> >> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> >> To post to this group, send email to rails-sqlse...@googlegroups.com.
> >> To unsubscribe from this group, send email to rails-sqlserver-a...@googlegroups.com.

> >> For more options, visit this group athttp://groups.google.com/group/rails-sqlserver-adapter?hl=en.


>
> >> --
> >> Cássio Marques
>
> >> Blog:http://cassiomarques.wordpress.com
>
> >> If you're writing code and you're not testing it, the code is wrong. I don't care if it does the right thing, and people need to understand this. If it works by accident, you're still wrong.
> >> Bryan Liles - Ruby Hoedown 2008
>
> >> --
>
> >> You received this message because you are subscribed to the Google Groups "Rails SQLServer Adapter" group.
> >> To post to this group, send email to
>

> ...
>
> read more »

Ken Collins

unread,
Jan 15, 2010, 8:00:51 AM1/15/10
to rails-sqlse...@googlegroups.com

Wow, this is exactly what I needed to know. Will do something about this real soon and let you know back.

- Ken

Adam Meehan

unread,
Jan 15, 2010, 1:11:05 PM1/15/10
to rails-sqlse...@googlegroups.com
I should just add for clarification that this without the lib option in config.gem. 

Adam

nanda

unread,
Feb 2, 2010, 4:14:23 PM2/2/10
to Rails SQLServer Adapter
Did you guys figure out the undefined method `create' for
DBI::Type::Timestamp:Class issue.
I am having the same exact issue, in script/console when i do
model.first(:select => 'attributes_which_are_not_datetime'), it works
but as soon as i try to select a date_time field, it throws that
exception.

Any suggestions.
Here's the versions of gems used
activerecord-sqlserver-adapter (2.3.1)
rails (2.3.2)
dbd-odbc (0.2.5)
dbi (0.4.1)

Thanks
nanda

> >>> rails-sqlserver-a...@googlegroups.com<rails-sqlserver-adapter%2Bunsu...@googlegroups.com>

> >> rails-sqlserver-a...@googlegroups.com<rails-sqlserver-adapter%2Bunsu...@googlegroups.com>

> > rails-sqlserver-a...@googlegroups.com<rails-sqlserver-adapter%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages