# Baffled by error

**URL:** <https://www.ruby-forum.com/t/baffled-by-error/48024>\
**Category:** Ruby\
**Created:** [November 16, 2005, 12:38am UTC](https://www.ruby-forum.com/t/baffled-by-error/48024 "2005-11-16T00:38:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![candiazoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@candiazoo](https://www.ruby-forum.com/u/candiazoo)\
**Post date:** [November 16, 2005, 12:38am UTC](https://www.ruby-forum.com/t/baffled-by-error/48024/1 "2005-11-16T00:38:44Z")

</div>

I am playing around… I am a ruby newbie. I am encountering an error  
I can’t figure out. Probably something very silly I am doing wrong…

I have a class called “Artist” (I’ll attach it below) that tries to  
open an SQLite3 database and load a row into itself.

As I code I keep a “test.rb” around to try things out. In the test.rb  
I require, open and execute a query successfully. I add a reference to  
my class and try its load method and get this:

Mitchs-iMac-G5:~/Desktop/Projects/ArtManagerRuby mike$ ruby test.rb  
1  
Painting  
Landscape  
Oil  
Canvas  
Farmlands  
This is a comment  
3  
Painting  
Landscape  
Watercolor  
Paper  
She kicks ASS!  
Not only is her artwork the best, she is my wife!  
4  
Sketch  
Landscape  
Crayon  
Paper  
Loves the beach!  
This guy can color with crayola crayons like nobody I have ever seen!  
“stuff”  
“done!”  
“nope”  
true  
“yah baby!”  
“this is a catenated string”  
/opt/local/lib/ruby/vendor\_ruby/1.8/sqlite3/database.rb:619:in  
`const_get': uninitialized constant SQLite3::Driver::Native (NameError) from /opt/local/lib/ruby/vendor_ruby/1.8/sqlite3/database.rb:619:in`load\_driver’  
from  
/opt/local/lib/ruby/vendor\_ruby/1.8/sqlite3/database.rb:616:in `each' from /opt/local/lib/ruby/vendor_ruby/1.8/sqlite3/database.rb:616:in`load\_driver’  
from  
/opt/local/lib/ruby/vendor\_ruby/1.8/sqlite3/database.rb:107:in  
`initialize' from ./artist.rb:100:in`new’  
from ./artist.rb:100:in `load’  
from test.rb:41

* * *

(The output at first is the successful accessing of the database, the  
error is when I call the load method of my class)

Here is the test.rb file:

require ‘sqlite3’  
require ‘db\_base’  
require ‘artist’

db = SQLite3::Database.new( DB\_Base::DB\_DATA )

db.execute( “select \* from artists” ) do |row|  
puts row  
end

db.close

class Foo  
def bar(gibberish=nil)  
p gibberish  
rescue  
p ‘Ppppffftt!’  
ensure  
p ‘done!’  
end  
end

foo = Foo.new  
foo.bar(‘stuff’)

some\_val = nil  
if !some\_val  
p “nope”  
else  
p “yep!”  
end

some\_val = “y”  
some\_other\_val = “y”  
p (some\_val == some\_other\_val)  
p “yah baby!” if some\_val == some\_other\_val  
p 'this is a ’ +  
‘catenated string’

a = Artist.new()  
a.load(1)  
puts a.to\_s

* * *

Here is the Artist class in artist.rb:

require ‘sqlite3’  
require ‘db\_base’

class Artist  
# Define our class constants here. Class constants are  
# immutable variables accessible by every instance of this  
# class.

```
QRY_SELECT = 'select form, category, media, mediasupport,' +
             'topic, comments from artists were id = ?'

QRY_INSERT = 'insert into artists(form, category, media,' +
             'mediasupport, topic, comments) ' +
             'values(?, ?, ?, ?, ?, ?)'

QRY_UPDATE = 'update artists set form = ?, category = ?, ' +
             'media = ?, mediasupport = ?, topic = ?, comments = ? ' 

```

- 

```
           'where id = ?'

```

QRY\_DELETE = ‘delete from artists where id = ?’

# These are our accessors. They define our

# class data and their visibility. In this

# case we are declaring the ability of these

# items to be read.

attr\_reader :id, :form, :category, :media  
attr\_reader :media\_support, :topic, :comments  
attr\_accessor :dirty, :added

# Only the class itself can reference these.

protected :dirty, :added

# Our constructor takes all arguments. It also

# determines whether or not this item is new or

# existing.

def initialize(id=nil, form=nil, category=nil, media=nil,  
media\_support=nil, topic=nil, comments=nil)  
@dirty = false  
@added = false

```
  @form = form
  @category = category
  @media = media
  @media_support = media_support
  @topic = topic
  @comments = comments

  @added = true if !id

```

end

# We manually program our writers (class values)

# because we need to check whether or not our values

# have actually changed. If they do, we mark our

# class object as “dirty”.

def id=(id)  
@dirty = true if id != @id  
@id = id  
end

def form=(form)  
@dirty = true if form != @form  
@form = form  
end

def category=(category)  
@dirty = true if category != @category  
@category = category  
end

def media=(media)  
@dirty = true if media != @media  
@media = media  
end

def media\_support=(media\_support)  
@dirty = true if media\_support != @media\_support  
@media\_support = media\_support  
end

def topic=(topic)  
@dirty = true if topic != @topic  
@topic = topic  
end

def comments=(comments)  
@dirty = true if comments != @comments  
@comments = comments  
end

# The rest of these are our methods for loading,

# saving and clearing out our object.

def load(id)  
db = SQLite3::Database.new(DB\_Base::DB\_DATA)  
db.execute(QRY\_SELECT, id) do |row|  
@form = row[0]  
@category = row[1]  
@media = row[2]  
@media\_support = row[3]  
@topic = row[4]  
@comments = row[5]  
end  
@id = id  
@dirty = false  
@added = false  
db.close  
end

def store  
if @dirty or @added  
db = SQLite3::Database.new(DB\_Base::DB\_DATA)

```
      if @added
          db.execute(QRY_INSERT,
                     @form, @category, @media, @media_support,
                     @topic, @comments )
          @id = db.last_insert_row_id
          @added = false
      elsif @dirty
          db.execute(QRY_UPDATE,
                     @form, @category, @media, @media_support,
                     @topic, @comments, @id )
          @dirty = false
      end
  end

```

ensure  
db.close unless db.closed?  
end

def kill  
db = SQLite3::Database.new(DB\_Base::DB\_DATA)  
db.execute(QRY\_DELETE, @id)  
ensure  
db.close unless db.closed?  
end

def to\_s  
“Form : #{@form}\nMedia: #{@media}/#{@media\_support}”  
end  
end

* * *

This is db\_base.rb…

module DB\_Base  
# Base database info. Keeps constants that identify  
# our databases.

```
DB_DATA = '/Library/Application Support/ArtManager/ArtManager.db'
DB_IMAGES = '/Library/Application Support/ArtManager/Images.db'

```

end

---

<div class="post-metadata">

**Author:** ![candiazoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2acd7d/32.png) [@candiazoo](https://www.ruby-forum.com/u/candiazoo)\
**Post date:** [November 16, 2005, 4:24am UTC](https://www.ruby-forum.com/t/baffled-by-error/48024/2 "2005-11-16T04:24:28Z")

</div>

Nevermind. I did a little Googling and found another example of the  
error, and the solution was to upgrade my version of ruby-sqlite3 from  
…9 to 1.1.
