[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] SQLite3/Ruby 1.1.0

Jamis Buck

2/15/2005 3:45:00 PM

The "Og" release!

http://rubyforge.org/projects/s...
http://sqlite-ruby.rubyforge.o...
http://docs.jamisbuck.org/r...

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



4 Answers

George Moschovitis

2/15/2005 4:33:00 PM

0

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

Erik Veenstra

2/15/2005 5:35:00 PM

0

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

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

Erik Veenstra

2/15/2005 5:52:00 PM

0

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

Jamis Buck

2/15/2005 6:43:00 PM

0

On 02:39 Wed 16 Feb , Erik Veenstra wrote:
> 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/sq...

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
jamis_buck@byu.edu
http://jamis.jam...
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."