muffinista / namey

Random name generator based on US Census data
http://muffinlabs.com/
MIT License
82 stars 13 forks source link

Sequel::DatabaseConnectionError: SQLite3::CantOpenException: unable to open database file #1

Closed OwenAR closed 10 years ago

OwenAR commented 11 years ago

Just gem install namey'd a minute ago and tried it out, but this is what happened:

[1] pry(main)> require 'namey'
=> true
[2] pry(main)> @g=Namey::Generator.new
=> #<Namey::Generator:0x39c0d08
 @db=
  #<Sequel::SQLite::Database: "sqlite://C:/Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/lib/../data/names.db">>
[3] pry(main)> @g.name
Sequel::DatabaseConnectionError: SQLite3::CantOpenException: unable to open database file
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/adapters/sqlite.rb:101:in `initialize'

Is what I'm doing wrong obvious from something in there, or...?

muffinista commented 11 years ago

That's strange, it appears to work fine for me. I see you're running Windows, is there any chance sqlite isn't installed properly?

OwenAR commented 11 years ago

Meaning the sqlite3 gem? I installed that a while back, and it's working fine as far as I can tell...

When I gem install namey'd, the only other gem that was installed with it was sequel.

(I just tried gem install sqlite but it said: ERROR: Could not find a valid gem 'sqlite' (>= 0) in any repository ERROR: Possible alternatives: sqlite3, slime, lite, polite, qlive)

Okay, so when I run this as a script (rather than in Pry):

require 'namey'
@g=Namey::Generator.new
puts @g.name

I get this:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/adapters/sqlite.rb:101:in `initialize': SQLite3::CantOpenException: unable to open database file (Sequel::DatabaseConnectionError)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/adapters/sqlite.rb:101:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/adapters/sqlite.rb:101:in `connect'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/connection_pool.rb:96:in `make_new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/connection_pool/threaded.rb:158:in `make_new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/connection_pool/threaded.rb:137:in `available'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/connection_pool/threaded.rb:127:in `block in acquire'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/connection_pool/threaded.rb:194:in `block in sync'
from <internal:prelude>:10:in `synchronize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/connection_pool/threaded.rb:194:in `sync'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/connection_pool/threaded.rb:126:in `acquire'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/connection_pool/threaded.rb:94:in `hold'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/database/connecting.rb:229:in `synchronize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/adapters/sqlite.rb:172:in `_execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/adapters/sqlite.rb:122:in `execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/dataset/actions.rb:794:in `execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/adapters/sqlite.rb:356:in `fetch_rows'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/dataset/actions.rb:144:in `each'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/dataset/actions.rb:584:in `single_record'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/dataset/actions.rb:592:in `single_value'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/dataset/actions.rb:251:in `get'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-4.0.0/lib/sequel/dataset/actions.rb:108:in `count'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/lib/namey/generator.rb:157:in `get_name'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/lib/namey/generator.rb:94:in `generate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/lib/namey/generator.rb:28:in `name'
from [DIR OF THE SCRIPT]/[SCRIPT NAME].rb:3:in `<main>'

So the problem is in the sqlite.rb script in sequel?

muffinista commented 11 years ago

I was actually wondering if you had installed the sqlite3 libraries themselves. If so, does

C:/Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/lib/data/names.db

exist, and are you able to open it?

OwenAR commented 11 years ago

Aha, no, under C:\Ruby193\lib\ruby\gems\1.9.1\gems\namey-0.0.8\lib I have namey.rb and a folder namey, which itself contains only three files: generator.rb parser.rb version.rb

Huh.

muffinista commented 11 years ago

Ooops, I meant

C:/Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/data/names.db

OwenAR commented 11 years ago

That file is there (only thing in the dir). It seems fine.

For instance,

require 'sqlite3'
Dir.chdir 'C:/Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/data/' 
db = SQLite3::Database.new 'names.db'
puts db.execute "select * from female where name like 'ANGELI%';"

Gets:

70.865
Angelina
71.781
Angeline
77.685
Angelia
77.822
Angelita
81.361
Angelique
81.555
Angelika
87.578
Angelic
87.891
muffinista commented 11 years ago

Does this work?

require 'namey'
@g=Namey::Generator.new("sqlite://C:/Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/data/names.db")
puts @g.name

And if not, does it work without the C: ?

OwenAR commented 11 years ago

It doesn't work with the C:, but it does work without it.

require 'namey'
@g=Namey::Generator.new("sqlite:///Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/data/names.db")
puts @g.name

Gets "Kimberly Alexander" etc.

So in C:\Ruby193\lib\ruby\gems\1.9.1\gems\namey-0.0.8\lib\namey\generator.rb, I replaced the line def initialize(dbname = nil) with def initialize(dbname = "sqlite:///Ruby193/lib/ruby/gems/1.9.1/gems/namey-0.0.8/data/names.db" ) and now

require 'namey'
@g=Namey::Generator.new
puts @g.name

works as expected.

Thanks. ^^