# DBI and SQLite3

**URL:** <https://www.ruby-forum.com/t/dbi-and-sqlite3/172071>\
**Category:** Ruby\
**Created:** [July 14, 2009, 6:31am UTC](https://www.ruby-forum.com/t/dbi-and-sqlite3/172071 "2009-07-14T06:31:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dafydd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@dafydd](https://www.ruby-forum.com/u/dafydd)\
**Post date:** [July 14, 2009, 6:31am UTC](https://www.ruby-forum.com/t/dbi-and-sqlite3/172071/1 "2009-07-14T06:31:28Z")

</div>

I’m trying to load an SQLite3 database with the DBI and I need some  
help. Here’s the setup I have and the error I’m getting:

the sqlite stuff:  
sqlite test  
SQLite version 2.8.17  
Enter “.help” for instructions  
sqlite\> .databases  
seq name file

* * *

* * *

0 main /home/noob/test  
1 temp /var/tmp/sqlite\_nEeVH8LjfjhjMNv  
sqlite\> select name, favnum from test;  
Me|37  
Fred|12  
Pervert|69

#!/usr/bin/env ruby  
require “dbi”

the script:  
db = DBI.connect(“DBI:SQLite3:main”)  
sth = db.execute(“select \* from test”)

sth.fetch\_hash do |row|  
puts row[“name”] + "'s favorite number is " + row[“favnum”].to\_s  
end

db.disconnect

the error:  
ruby sqlite.rb  
/usr/lib/ruby/1.8/DBD/SQLite3/SQLite3.rb:236:in `initialize': no such table: test (DBI::ProgrammingError) from /usr/lib/ruby/1.8/DBD/SQLite3/SQLite3.rb:111:in`new’  
from /usr/lib/ruby/1.8/DBD/SQLite3/SQLite3.rb:111:in `prepare' from /usr/lib/ruby/1.8/dbi.rb:910:in`execute’  
from /usr/lib/ruby/1.8/dbi.rb:504:in `execute’  
from sqlite.rb:5

---

<div class="post-metadata">

**Author:** ![dafydd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@dafydd](https://www.ruby-forum.com/u/dafydd)\
**Post date:** [July 14, 2009, 8:48am UTC](https://www.ruby-forum.com/t/dbi-and-sqlite3/172071/2 "2009-07-14T08:48:13Z")

</div>

Dafydd F. wrote:

> ## the error: ruby sqlite.rb /usr/lib/ruby/1.8/DBD/SQLite3/SQLite3.rb:236:in `initialize’: no such table: test (DBI::ProgrammingError)

You might want to try “select tbl\_name from sqlite\_master where  
type=“table”” to see if there is really a table called “test”.
