This module allows Ruby programs to interface with the SQLite3 database engine (www.sqlite.org). You must have the SQLite engine installed in order to build this module.
Note that this module is only compatible with SQLite 3.6.16 or newer.
require "sqlite3" # Open a database db = SQLite3::Database.new "test.db" # Create a database rows = db.execute <<-SQL create table numbers ( name varchar(30), val int ); SQL # Execute a few inserts { "one" => 1, "two" => 2, }.each do |pair| db.execute "insert into numbers values ( ?, ? )", pair end # Execute inserts with parameter markers db.execute("INSERT INTO students (name, email, grade, blog) VALUES (?, ?, ?, ?)", [@name, @email, @grade, @blog]) # Find a few rows db.execute( "select * from numbers" ) do |row| p row end
Install SQLite3, enabling the option SQLITE_ENABLE_COLUMN_METADATA (see www.sqlite.org/compile.html for details).
Then do the following:
ruby setup.rb config ruby setup.rb setup ruby setup.rb install
Alternatively, you can download and install the RubyGem package for SQLite3/Ruby (you must have RubyGems and SQLite3 installed, first):
gem install sqlite3
If you have sqlite3 installed in a non-standard location, you can specify the location of the include and lib files by doing:
gem install sqlite3 -- --with-sqlite3-include=/opt/local/include \ --with-sqlite3-lib=/opt/local/lib
The best place to get help is from the sqlite3-ruby mailing list which can be found here:
* http://groups.google.com/group/sqlite3-ruby
Uh oh. After contacting the mailing list, you’ve found that you’ve actually discovered a bug. You can file the bug at the github issues page which can be found here:
* http:/luislavena/sqlite3-ruby/issues
For help figuring out the SQLite3/Ruby interface, check out the SYNOPSIS as well as the RDoc. It includes examples of usage. If you have any questions that you feel should be address in the FAQ, please send them to the mailing list
The source repository is accessible via git:
git clone git:/luislavena/sqlite3-ruby.git
It fixes the deadlock condition which will cause the throwing of the busy_exception.
<pre> some testing is done here: github.com/dxj19831029/sqlite3-test-multithread </pre>
Noted: don’t put selection inside transaction, that will be likely to cause busy exception, which is expected behiour
www.sqlite.org/c3ref/busy_handler.html
The presence of a busy handler does not guarantee that it will be invoked when there is lock contention. If SQLite determines that invoking the busy handler could result in a deadlock, it will go ahead and return SQLITE_BUSY or SQLITE_IOERR_BLOCKED instead of invoking the busy handler. Consider a scenario where one process is holding a read lock that it is trying to promote to a reserved lock and a second process is holding a reserved lock that it is trying to promote to an exclusive lock. The first process cannot proceed because it is blocked by the second and the second process cannot proceed because it is blocked by the first. If both processes invoke the busy handlers, neither will make any progress. Therefore, SQLite returns SQLITE_BUSY for the first process, hoping that this will induce the first process to release its read lock and allow the second process to proceed.