# Create, read, update an sqlite database

**URL:** <https://www.ruby-forum.com/t/create-read-update-an-sqlite-database/120613>\
**Category:** Ruby\
**Created:** [November 19, 2007, 6:50am UTC](https://www.ruby-forum.com/t/create-read-update-an-sqlite-database/120613 "2007-11-19T06:50:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [November 19, 2007, 6:50am UTC](https://www.ruby-forum.com/t/create-read-update-an-sqlite-database/120613/1 "2007-11-19T06:50:28Z")

</div>

This is all from [http://sqlite-ruby.rubyforge.org/sqlite3/faq.html](http://sqlite-ruby.rubyforge.org/sqlite3/faq.html).  
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.rubyforge.org](http://gems.rubyforge.org)  
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

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [November 19, 2007, 8:13am UTC](https://www.ruby-forum.com/t/create-read-update-an-sqlite-database/120613/2 "2007-11-19T08:13:01Z")

</div>

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.rubyforge.org/](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."

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [November 19, 2007, 12:37pm UTC](https://www.ruby-forum.com/t/create-read-update-an-sqlite-database/120613/3 "2007-11-19T12:37:58Z")

</div>

On Mon, 19 Nov 2007 16:12:23 +0900, Ryan D. 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](http://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
