create, read, update an sqlite database


T

Thufir

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

[email protected] ~/rubyCode/sqlite $
[email protected] ~/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
[email protected] ~/rubyCode/sqlite $
[email protected] ~/rubyCode/sqlite $
[email protected] ~/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.rubyforge.org
[email protected] ~/rubyCode/sqlite $
[email protected] ~/rubyCode/sqlite $
[email protected] ~/rubyCode/sqlite $ cat seven.rb
require 'sqlite3'

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



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




thanks,

Thufir
 
Ad

Advertisements

R

Ryan Davis

[email protected] ~/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.rubyforge.org/

"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."
 
Ad

Advertisements

T

Thufir

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


[email protected] ~/rubyCode/sqlite $
[email protected] ~/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
[email protected] ~/rubyCode/sqlite $
[email protected] ~/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
[email protected] ~/rubyCode/sqlite $
[email protected] ~/rubyCode/sqlite $ date
Mon Nov 19 03:34:38 PST 2007
[email protected] ~/rubyCode/sqlite $
[email protected] ~/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
 

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

Top