Friday, November 1, 2013

Installing SQLite3 on Ubuntu/Xubuntu 13.04

1. Installing SQLite3
$ sudo apt-get install sqlite3
Test the installation.
$ mkdir sqlprj
cd sqlprj/
$ sqlite3 test.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
sqlite> .exit

2. Installing sqliteman (GUI app to manage SQLite)
sudo apt-get install sqliteman
Test the installation by launching it from menu and creating a table and inserting a few rows.


3. Installing ruby gem for SQLite3 
$ sudo apt-get install libsqlite3-dev
$ sudo gem install sqlite3
Test the installation.
#!/usr/bin/ruby
#
# test.rb
#  
# based on samples in 
# http://zetcode.com/db/sqliteruby/
#

require 'sqlite3'

begin
    
    db = SQLite3::Database.open "test.db"
    
    stm = db.prepare "SELECT * FROM party" 
    rs = stm.execute 
    
    rs.each do |row|
        puts row.join "\s"
    end
           
rescue SQLite3::Exception => e 
    puts "Exception occured"
    puts e
ensure
    stm.close if stm
    db.close if db    
end
$ ruby test.rb
1 Doe, John per
2 Big Company org

No comments:

Post a Comment