Skip to content

Instantly share code, notes, and snippets.

@hirataya
Created January 29, 2012 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirataya/1699459 to your computer and use it in GitHub Desktop.
Save hirataya/1699459 to your computer and use it in GitHub Desktop.
Ruby dies with "method `method_missing' called on terminated object"
% ruby ragnarok_items.rb > log.txt
ragnarok_items.rb:14:in `block in initialize': NotImplementedError: method `method_missing' called on terminated object (0x00000101cf7018 flags=0x0 klass=0x0): SELECT "items".* FROM "items" WHERE (regex(name_iro, 'Battle Axe')) (ActiveRecord::StatementInvalid)
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:321:in `call'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:321:in `block in create_function'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/statement.rb:108:in `call'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/statement.rb:108:in `step'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/statement.rb:108:in `block in each'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/statement.rb:107:in `loop'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/statement.rb:107:in `each'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/sqlite_adapter.rb:253:in `to_a'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/sqlite_adapter.rb:253:in `block in exec_query'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activesupport-3.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/sqlite_adapter.rb:247:in `exec_query'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/sqlite_adapter.rb:465:in `select'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:16:in `select_all'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/querying.rb:38:in `block in find_by_sql'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/explain.rb:38:in `logging_query_plan'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/querying.rb:37:in `find_by_sql'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/relation.rb:170:in `exec_queries'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/relation.rb:159:in `block in to_a'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/explain.rb:38:in `logging_query_plan'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/relation.rb:158:in `to_a'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/relation/finder_methods.rb:159:in `all'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/relation/finder_methods.rb:105:in `find'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/relation/finder_methods.rb:101:in `find'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/activerecord-3.2.0/lib/active_record/querying.rb:5:in `find'
from ragnarok_items.rb:29:in `search'
from ragnarok_items.rb:40:in `block in <main>'
from ragnarok_items.rb:38:in `times'
from ragnarok_items.rb:38:in `<main>'
% ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10]
require "active_record"
require "sqlite3"
conn = ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => "ragnarok_items.db"
)
class ActiveRecord::ConnectionAdapters::SQLite3Adapter
def initialize(conn, logger, config)
super
conn.create_function("regex", 2, :numeric) do |func, value, regex|
if value and regex then
value.force_encoding("utf-8")
regex.force_encoding("utf-8")
func.result = (value =~ /#{regex}/i)? 1: 0
else
func.result = 0
end
end
end
end
class RagnarokItem < ActiveRecord::Base
self.table_name = "items"
end
def search(regex)
RagnarokItem.find(
:all,
:conditions => [
"regex(name_iro, :regex)",
{regex: regex}
]
)
end
10000.times do |i|
puts i
p search("Battle Axe")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment