-
-
Save hirataya/1703990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ruby ragnarok_items.rb > log.txt | |
ragnarok_items.rb:14:in `block in initialize': NotImplementedError: method `method_missing' called on terminated object (0x00000100d93018 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:37:in `search' | |
from ragnarok_items.rb:48:in `block in <main>' | |
from ragnarok_items.rb:46:in `times' | |
from ragnarok_items.rb:46:in `<main>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
if not value.is_a?(String) then | |
$stderr.puts value.class | |
end | |
if not regex.is_a?(String) then | |
$stderr.puts regex.class | |
end | |
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