Skip to content

mikeowens/SQLiteRuby

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 

Ruby SQLite C Extension

About

This is a stripped-down Ruby C extension for SQLite. It compiles/embeds the SQLite amalgamation in the extension and provides a very simple SQLite API and higher level Query/Recordset API.

To install from the internets:

    gem install sqlite

To build/install from source:

    git clone git@github.com:mikeowens/SQLiteRuby.git
    cd SQLiteRuby
    gem install rake-compiler
    rake
    rake gem
    cd pkg
    gem install -l sqlite-*.gem

Usage

    @db = SQLite::Database.new()
    rc = @db.open("#{$test_dir}/files/foods.db")
    
    if rc != SQLITE_OK
      puts @db.error()
    end    

    # Low-level SQLite statement handle API
    query = @db.prepare('select * from foods')
    
    while query.step() == SQLITE_ROW
      # Step though each field in row.
      # k is column name, v is field value
      query.each do |k,v|
        puts "  #{k}: #{v}"
      end    
    end

    # High level Query/Recordset API
    query = SQLite::Query.new(@db)

    recordset = query.exec %Q{ select * from foods order by name }
    
    # Rows can key on both column ordinals and/or name.
    recordset.each do |row|
      puts "%3i %2i %-30s" % [row['id'], row[1], row[2]]
    end

About

A small, simple Ruby C extension for SQLite

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages