[ANN] SQLite3/Ruby 1.1.0

J

Jamis Buck

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!
 
G

George Moschovitis

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

Thanks a lot! :)

regards,
George
 
E

Erik Veenstra

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

----------------------------------------------------------------
 
E

Erik Veenstra

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
 
J

Jamis Buck

--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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:

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
----------------------------------------------------------------

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
(e-mail address removed)
http://jamis.jamisbuck.org
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."

--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="typeless-columns.patch"

Index: sqlite3/translator.rb
===================================================================
--- sqlite3/translator.rb (revision 18)
+++ sqlite3/translator.rb (working copy)
@@ -81,6 +81,7 @@
# A convenience method for working with type names. This returns the "base"
# type name, without any parenthetical data.
def type_name( type )
+ return "" if type.nil?
type = $1 if type =~ /^(.*?)\(/
type.upcase
end

--zYM0uCDKw75PZbzx--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top