[ANN] SQLite3/Ruby 1.1.0

The "Og" release!

  http://rubyforge.org/projects/sqlite-ruby
  http://sqlite-ruby.rubyforge.org/sqlite3
  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:

  result = db.query( "select name, gender from person" )
  puts "%30 %10" % result.columns
  while row = result.next
    puts "%30 %10" % row
  end
  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
http://jamis.jamisbuck.org
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."

Jamis Buck wrote:

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

Thanks a lot! :slight_smile:

regards,
George

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

----------------------------------------------------------------

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)
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/translator.rb:77:in
`translate'
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:135:in
`next'
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:134:in
`map'
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:134:in
`next'
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/resultset.rb:160:in
`each'
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:215:in
`inject'
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:215:in
`execute'
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:210:in
`prepare'
        from
/usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/database.rb:210:in
`execute'
        from /home/erik/bin/kkp.troep.rb:19

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. :wink: 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:

  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 (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
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."