luislavena/sqlite3-ruby — Issue #60: method `method_missing' called on terminated object
Author: hirataya
Created: 2012-01-31 14:29:52+00:00
State: open

Ruby dies with error "method `method_missing' called on terminated object" at random timing in running ruby code as follows. At line 6, variable "value" seems to be pointing something wrong, what Ruby says "terminated object."

**Ruby code**

```ruby
require "sqlite3"

db = SQLite3::Database.new("ragnarok_items.db")
db.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
10000.times do |i|
$stderr.puts i
db.execute("select * from items where regex(name_iro, 'Battle Axe')") do |row|
p row
end
end
```

**Environment**

* Ruby version: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10] installed with MacPorts
* SQLite version: sqlite3 @3.7.10 installed with MacPorts
* sqlite3 gem version: sqlite3 (1.3.5)

**Full error message**

```
ro_sqlite3.rb:6:in `block in

': method `method_missing' called on terminated object (0x000001011a2618 flags=0x0 klass=0x0) (NotImplementedError)
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/sqlite3-1.3.5/lib/sqlite3/database.rb:140:in `block in execute'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:95:in `prepare'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:134:in `execute'
from ro_sqlite3.rb:15:in `block in

'
from ro_sqlite3.rb:13:in `times'
from ro_sqlite3.rb:13:in `

'
```