5 Replies - 3079 Views - Last Post: 06 February 2012 - 05:38 AM Rate Topic: -----

#1 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Sqlite3 require problems

Posted 05 February 2012 - 10:30 AM

I am trying to create an application which is going to use SQLite, but when I try to create a test databse I get a require error
test_db.rb:1:in `require': no such file to load -- sqlite3 (LoadError)
	from test_db.rb:1



My code looks like this:
 require 'sqlite3'

  db = SQLite3::Database.new( "test.db" )


And I have checked if SQlite is in my ruby path and for what I can tell it is:
56344ec6:gems tools$ pwd
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems
56344ec6:gems tools$ ls
builder-3.0.0		json-1.5.1		sqlite3-ruby-1.2.4
bundler-1.0.0		patron-0.4.11		thin-1.2.8
curb-0.7.12		pg-0.10.1		tilt-1.2.2
daemons-1.1.0		rack-1.2.1
eventmachine-0.12.10	sinatra-1.2.0
56344ec6:gems tools$ 



Can anyone tell me what is wrong ?

Is This A Good Question/Topic? 0
  • +

Replies To: Sqlite3 require problems

#2 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Sqlite3 require problems

Posted 05 February 2012 - 11:22 AM

Try

require 'rubygems'
require 'sqlite3'



That should work if you've done a $ gem install sqlite3

Edit: Note that this isn't required in ruby 1.9.x because rubygems get's auto-loaded by default.

This post has been edited by NotarySojac: 05 February 2012 - 11:29 AM

Was This Post Helpful? 1
  • +
  • -

#3 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: Sqlite3 require problems

Posted 05 February 2012 - 12:37 PM

Now I get this:
56344ec6:SQLITE_TEST tools$ ruby test_db.rb 
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- sqlite3 (LoadError)
	from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
	from test_db.rb:2


Was This Post Helpful? 0
  • +
  • -

#4 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Sqlite3 require problems

Posted 05 February 2012 - 10:32 PM

I'm not having any trouble when attempting to reproduce your bug. What version of ruby are you using? Maybe there's something up there.

sqlite_sample# ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-linux]

sqlite_sample# cat main.rb
require 'rubygems'
require 'sqlite3'


db = SQLite3::Database.new( "test.db" )

sqlite_sample# ls
main.rb

sqlite_sample# ruby main.rb

sqlite_sample# ls
main.rb  test.db




Also, do you get this kind of output when checking for the sqlite3 gem:

sqlite_sample# gem list |grep 'sqlite3'
sqlite3 (1.3.3)


This post has been edited by NotarySojac: 05 February 2012 - 10:34 PM

Was This Post Helpful? 0
  • +
  • -

#5 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: Sqlite3 require problems

Posted 06 February 2012 - 12:48 AM

I am using
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

Was This Post Helpful? 0
  • +
  • -

#6 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Re: Sqlite3 require problems

Posted 06 February 2012 - 05:38 AM

I have found a semi solution to the problem I need to have
#!/usr/bin/ruby


in all my classes

This post has been edited by lnc12: 06 February 2012 - 05:40 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1