the sqlite3 gem uses a native C extension which needs to compiled for your system. (usually done when installed via rubygems)
The installation will fail if you use macgem, probably due to some IO issues and the lack of support of C extension.

Someone should look into writing a wrapper for macruby using an obj-c driver. That can't be that hard and that would be very useful. I've been thinking about porting the DataObject and the DO SQlite3 driver to MacRuby but I didn't have time yet (and I didn't really need it either).  DataObject is the uniform API used by DataMapper to talk to its drivers.
If someone is interested in working on that, I can put him/her in contact with the DM team.

- Matt



2009/3/31 Tim Rand <timrandg@gmail.com>
Can any kind macruby experts help me get sqlite3 gem working with macruby?

sqlite3-ruby-1.2.4 ruby gem works in ruby 1.9.0. So I think it should work in macruby also...

From macirb I added the path to the gem:

$: << "path/to/the/sqlite3-ruby-1.2.4/lib"

require 'sqlite3.rb'  # => true

$db = SQLite3::Database.new("/path/to/x.db.rsd")

RuntimeError: no driver for sqlite3 found
the error comes from the load_driver method near line 621 of the sqlite3/database.rb file.

   def load_driver( driver )
      case driver
        when Class
          # do nothing--use what was given
        when Symbol, String
          require "sqlite3/driver/#{driver.to_s.downcase}/driver"
          driver = SQLite3::Driver.const_get( driver )::Driver
        else
          [ "Native", "DL" ].each do |d|
            begin
              require "sqlite3/driver/#{d.downcase}/driver"
              driver = SQLite3::Driver.const_get( d )::Driver
              break
            rescue SyntaxError
              raise
            rescue ScriptError, Exception, NameError
            end
          end
          raise "no driver for sqlite3 found" unless driver
      end

      @driver = driver.new
    end
    private :load_driver

Macruby enters the method with driver set to NSNull, and the driver fails to load. In ruby (1.9.0) the driver loads via the Native driver.

irb19 session:
>> db = SQLite3::Database.new("/Users/Tim/Desktop/newdb")
=> #<SQLite3::Database:0x5cba48 @driver=#<SQLite3::Driver::Native::Driver:0x5c4784 @callback_data={}, @authorizer={}, @busy_handler={}, @trace={}>, @statement_factory=SQLite3::Statement, @handle=#<SWIG::TYPE_p_sqlite3:0x5c470c>, @closed=false, @results_as_hash=false, @type_translation=false, @translator=nil, @transaction_active=false>

Can anyone offer an idea about how they might try to patch this to work with macruby?  I know an alternative would be CoreData--but it is too cumbersome for me.
Thanks,
Tim

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel