Amalgalite Pthread Error

If you happen to get an error like the following when running amalgalite, it was a bug in how amalgalite was built. I wasn't matching the thread support in amalgalite with the threadsupport of the installed ruby.

amalgalite-0.2.0/ext/amalgalite3.so: undefined symbol: pthread_mutexattr_init

For future reference this is how you can see how ruby was compiled on my iMac

1.8.6 114 (2008-03-03) i686-darwin9.2.2
>> require 'rbconfig'
>> puts Config::CONFIG['configure_args']
 '--prefix=/opt/local' '--enable-shared' '--mandir=/opt/local/share/man'
 '--enable-pthread' '--without-tk' 'CC=/usr/bin/gcc-4.0' 'CFLAGS=-O2'
 'LDFLAGS=-L/opt/local/lib' 'CPPFLAGS=-I/opt/local/include'

versus my OpenBSD server:

1.8.6 110 (2007-09-23) x86_64-openbsd4.2
>> require 'rbconfig'
>>puts Config::CONFIG['configure_args']
 '--enable-shared' '--enable-ipv6' '--with-dbm-type=bogus'
 '--with-opt-dir=/usr/local' '--with-tcl-include=/usr/local/include/tcl8.4'
 '--with-tk-include=/usr/local/include/tk8.4' '--with-X11-dir=/usr/X11R6'
 '--prefix=/usr/local' '--sysconfdir=/etc' '--mandir=/usr/local/man'
 '--infodir=/usr/local/info' 'CC=cc' 'CFLAGS=-O2 -pipe'

You can see that on my iMac ruby was compiled with @--enable-pthread@ but on my OpenBSD machine that configuration option is missing. I didn't take this into account when building Amalgalite.

Version 0.2.1 was just released which fixes this bug.

gem install amalgalite

Comments (View)

Amalgalite 0.2.0 Released

Now with more examples!

SQLite has the ability to do incremental IO on items that are BLOB's. I just finished adding support for this in Amalgalite. This means you can SELECT a blob, and from the result set, transfer the data directly to an IO stream.

A quick example. Assume we store files in filestore.db that has the following schema:

  data BLOB

You can then write all the files in this table to a different tree with this piece of code. In this case, the files are not loaded into memory, the are copied directly from the pages in the database for the BLOBs to the output files.

new_root_dir = "/tmp"
db = Amalgalite::Database.new( "filestore.db" )
db.execute( "SELECT * FROM files" ) do |row|
  # unsafe path expansion
  dest_path = File.expand_path( File.join( new_root_dir, row['path']) )
  row['data'].write_to_file( dest_path )

To get this behavior you need to make sure that column that is SQLite's rowid column is part of the result set. If one of your columns is INTEGER PRIMARY KEY it is that one. Otherwise you must specifically select ROWID, OID. The code above will still work if the rowid column is not specified, but Amalgalite will fully read it into memory before being written to the file.

Take a look at the Amalgalite::Blob api and the example.

Comments (View)