[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

create, read, update an sqlite database

Thufir Hawat

11/19/2007 5:50:00 AM

This is all from <http://sqlite-ruby.rubyforge.org/sqlite3/fa....
How do interpret the following error pls:

thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $ ruby seven.rb
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/
errors.rb:94:in
`check': no such table: test (SQLite3::SQLException)
from
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/
statement.rb:70:in
`initialize'
from
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/
database.rb:183:in
`new'
from
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/
database.rb:183:in
`prepare'
from
/usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0/lib/sqlite3/
database.rb:210:in
`execute'
from seven.rb:4
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $ gem search sqlite --both

*** LOCAL GEMS ***

sqlite-ruby (2.2.3)
SQLite/Ruby is a module to allow Ruby scripts to interface with a
SQLite database.

sqlite3-ruby (1.1.0)
SQLite3/Ruby is a module to allow Ruby scripts to interface with a
SQLite3 database.

*** REMOTE GEMS ***
Bulk updating Gem source index for: http://gems.rub...
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $ cat seven.rb
require 'sqlite3'

db = SQLite3::Database.new( "test.db" )
rows = db.execute( "select * from test" )
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $ cat /etc/gentoo-release
Gentoo Base System release 1.12.9
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $ date
Sun Nov 18 21:39:49 PST 2007
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $



Wasn't it supposed to create test.db in line three?




thanks,

Thufir


2 Answers

Ryan Davis

11/19/2007 7:12:00 AM

0


On Nov 18, 2007, at 21:49 , Thufir wrote:

> thufir@arrakis ~/rubyCode/sqlite $ cat seven.rb
> require 'sqlite3'
>
> db = SQLite3::Database.new( "test.db" )
> rows = db.execute( "select * from test" )
[cut lots of shit that only makes helping you harder]
> Wasn't it supposed to create test.db in line three?

http://sqlite-ruby.ruby...

"new( file_name, mode=0 )

Create a new Database object that opens the given file. The mode
parameter has no meaning yet, and may be omitted. If the file does not
exist, it will be created if possible."



Thufir Hawat

11/19/2007 11:38:00 AM

0

On Mon, 19 Nov 2007 16:12:23 +0900, Ryan Davis wrote:

> "new( file_name, mode=0 )
>
> Create a new Database object that opens the given file. The mode
> parameter has no meaning yet, and may be omitted. If the file does not
> exist, it will be created if possible."


Thank you for the information, I googled it and found <http://sqlite-
ruby.rubyforge.org/classes/SQLite/Database.html> which has an example
that fails for reasons unclear to me but which looks quite promising:


thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $ ruby eight.rb
/usr/lib/ruby/gems/1.8/gems/sqlite-ruby-2.2.3/lib/sqlite/
resultset.rb:71:in `compile': near "table": syntax error
(SQLite::Exceptions::SQLException)
from /usr/lib/ruby/gems/1.8/gems/sqlite-ruby-2.2.3/lib/sqlite/
resultset.rb:71:in `commence'
from /usr/lib/ruby/gems/1.8/gems/sqlite-ruby-2.2.3/lib/sqlite/
resultset.rb:65:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/sqlite-ruby-2.2.3/lib/sqlite/
statement.rb:104:in `new'
from /usr/lib/ruby/gems/1.8/gems/sqlite-ruby-2.2.3/lib/sqlite/
statement.rb:104:in `execute'
from /usr/lib/ruby/gems/1.8/gems/sqlite-ruby-2.2.3/lib/sqlite/
database.rb:194:in `execute'
from eight.rb:5
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $ cat eight.rb
require 'sqlite'

db = SQLite::Database.new( "data.db" )

db.execute( "select * from table" ) do |row|
p row
end

db.close
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $ date
Mon Nov 19 03:34:38 PST 2007
thufir@arrakis ~/rubyCode/sqlite $
thufir@arrakis ~/rubyCode/sqlite $




Are the errors due to something with my ruby setup, gems, or installed
packages such as sqlite? That is, does the example work in another
environment?




thanks,

Thufir