# \[ANN\] SQLite3/Ruby 1.1.0

**URL:** <https://rubytalk.org/t/ann-sqlite3-ruby-1-1-0/16496>\
**Category:** ruby-talk\
**Created:** [15 February 2005 15:44 UTC](https://rubytalk.org/t/ann-sqlite3-ruby-1-1-0/16496 "2005-02-15T15:44:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jamis\_Buck3](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@Jamis\_Buck3](https://rubytalk.org/u/Jamis_Buck3)\
**Post date:** [15 February 2005 15:44 UTC](https://rubytalk.org/t/ann-sqlite3-ruby-1-1-0/16496/1 "2005-02-15T15:44:40Z")

</div>

The "Og" release!

&nbsp;&nbsp;[http://rubyforge.org/projects/sqlite-ruby](http://rubyforge.org/projects/sqlite-ruby)  
&nbsp;&nbsp;[http://sqlite-ruby.rubyforge.org/sqlite3](http://sqlite-ruby.rubyforge.org/sqlite3)  
&nbsp;&nbsp;[http://docs.jamisbuck.org/read/book/3](http://docs.jamisbuck.org/read/book/3)

This version supports a new Database#query method to make it easier to  
do external row-by-row iteration of result sets:

&nbsp;&nbsp;result = db.query( "select name, gender from person" )  
&nbsp;&nbsp;puts "%30 %10" % result.columns  
&nbsp;&nbsp;while row = result.next  
&nbsp;&nbsp;&nbsp;&nbsp;puts "%30 %10" % row  
&nbsp;&nbsp;end  
&nbsp;&nbsp;result.close

Of course, you can do it with a block and have the result set  
implicitly closed, as well.

Other fixes/changes:

\* Solaris is now supported by the DL driver.  
\* Added three missing exception classes  
\* Exceptions now have a 'code' attribute for querying the numeric  
error value.  
\* If the 'Native' driver is not found, opening a second database  
resulted in a NameError.

Enjoy!

> **···**
>
> --  
> Jamis Buck  
> [jamis\_buck@byu.edu](mailto:jamis_buck@byu.edu)  
> [http://jamis.jamisbuck.org](http://jamis.jamisbuck.org)  
> ------------------------------  
> "I am Victor of Borge. You will be assimil-nine-ed."

---

<div class="post-metadata">

**Author:** ![George\_Moschovitis](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@George\_Moschovitis](https://rubytalk.org/u/George_Moschovitis)\
**Post date:** [15 February 2005 16:34 UTC](https://rubytalk.org/t/ann-sqlite3-ruby-1-1-0/16496/2 "2005-02-15T16:34:53Z")

</div>

Jamis Buck wrote:

> The "Og" release!  
> ... \* If the 'Native' driver is not found, opening a second database  
> resulted in a NameError.

Thanks a lot! 🙂

regards,  
George

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra2](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@Erik\_Veenstra2](https://rubytalk.org/u/Erik_Veenstra2)\
**Post date:** [15 February 2005 17:39 UTC](https://rubytalk.org/t/ann-sqlite3-ruby-1-1-0/16496/3 "2005-02-15T17:39:53Z")

</div>

I have a problem when using SQLITE3. I think it's a bug in the  
Ruby bindings, but I'm not quiet sure.

Just run this script to regenerate the problem.

gegroet,  
Erik V.

> **···**
>
> ----------------------------------------------------------------
> 
> require "rubygems"
> 
> require\_gem "sqlite3-ruby"
> 
> dbfile = "dummy.db"
> 
> File.delete(dbfile) if File.file?(dbfile)
> 
> db = SQLite3::Database.new(dbfile)
> 
> db.type\_translation = true # This is causing the problem.
> 
> db.execute("CREATE TABLE t1 (c1 INTEGER)")
> 
> db.execute("INSERT INTO t1 (c1) VALUES (1)")  
> db.execute("INSERT INTO t1 (c1) VALUES (2)")  
> db.execute("INSERT INTO t1 (c1) VALUES (3)")
> 
> p db.execute("SELECT MAX(c1) FROM t1").shift.shift
> 
> ----------------------------------------------------------------

---

<div class="post-metadata">

**Author:** ![Erik\_Veenstra2](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@Erik\_Veenstra2](https://rubytalk.org/u/Erik_Veenstra2)\
**Post date:** [15 February 2005 17:54 UTC](https://rubytalk.org/t/ann-sqlite3-ruby-1-1-0/16496/4 "2005-02-15T17:54:53Z")

</div>

Just for feeding Google:

/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/translator.rb:85:in  
`type_name': undefined method `upcase' for nil:NilClass (NoMethodError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/translator.rb:77:in  
`translate'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:135:in  
`next'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:134:in  
`map'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:134:in  
`next'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:160:in  
`each'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:215:in  
`inject'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:215:in  
`execute'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:210:in  
`prepare'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from  
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:210:in  
`execute'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /home/erik/bin/kkp.troep.rb:19

---

<div class="post-metadata">

**Author:** ![Jamis\_Buck3](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@Jamis\_Buck3](https://rubytalk.org/u/Jamis_Buck3)\
**Post date:** [15 February 2005 18:43 UTC](https://rubytalk.org/t/ann-sqlite3-ruby-1-1-0/16496/5 "2005-02-15T18:43:14Z")

</div>

> I have a problem when using SQLITE3. I think it's a bug in the  
> Ruby bindings, but I'm not quiet sure.
> 
> Just run this script to regenerate the problem.
> 
> gegroet,  
> Erik V.

Thanks for the bug report, Erik. Must be something about announcing  
a new release that causes these to occur. I dunno. 😉 The problem was  
that some columns do not have a type (like those that are the result  
of functions and so forth), which caused type translation to barf.

At any rate, I've found and fixed the problem, but as I won't have  
time to repackage SQLite3/Ruby for at least a few days, I've attached  
a patch instead.

Alternatively, you can grab the latest from svn:

&nbsp;&nbsp;[http://www.jamisbuck.org/svn/sqlite3-ruby](http://www.jamisbuck.org/svn/sqlite3-ruby)

Note that the fix does NOT result in typeless columns (like MAX(c1) in  
your example) to be translated to integers--sqlite does not give me  
any information about the type of those columns, and so they are not  
translated.

- Jamis

[typeless-columns.patch](https://rubytalk.org/uploads/short-url/2IdFBjV1Dunz8UzYuMLC6vVR6yJ.patch) (463 Bytes)

> **···**
>
> On 02:39 Wed 16 Feb , Erik Veenstra wrote:
> 
> > ----------------------------------------------------------------
> > 
> > require "rubygems"
> > 
> > require\_gem "sqlite3-ruby"
> > 
> > dbfile = "dummy.db"
> > 
> > File.delete(dbfile) if File.file?(dbfile)
> > 
> > db = SQLite3::Database.new(dbfile)
> > 
> > db.type\_translation = true # This is causing the problem.
> > 
> > db.execute("CREATE TABLE t1 (c1 INTEGER)")
> > 
> > db.execute("INSERT INTO t1 (c1) VALUES (1)")  
> > db.execute("INSERT INTO t1 (c1) VALUES (2)")  
> > db.execute("INSERT INTO t1 (c1) VALUES (3)")
> > 
> > p db.execute("SELECT MAX(c1) FROM t1").shift.shift
> > 
> > ----------------------------------------------------------------
> 
> --  
> Jamis Buck  
> jamis\_buck@byu.edu  
> [http://jamis.jamisbuck.org](http://jamis.jamisbuck.org)  
> ------------------------------  
> "I am Victor of Borge. You will be assimil-nine-ed."
