# Amalgalite 0.2.0 Released

**URL:** <https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239>\
**Category:** Ruby\
**Created:** [July 4, 2008, 11:44pm UTC](https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239 "2008-07-04T23:44:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremyheiler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@jeremyheiler](https://www.ruby-forum.com/u/jeremyheiler)\
**Post date:** [July 4, 2008, 11:44pm UTC](https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239/1 "2008-07-04T23:44:55Z")

</div>

amalgalite version 0.2.0 has been released.

- 

[http://www.copiousfreetime.org/articles/2008/07/04/amalgalite-0-2-0-released.html](http://www.copiousfreetime.org/articles/2008/07/04/amalgalite-0-2-0-released.html)

- [http://copiousfreetime.rubyforge.org/amalgalite/](http://copiousfreetime.rubyforge.org/amalgalite/)

Amalgalite embeds the SQLite database engine in a ruby extension. There  
is no  
need to install SQLite separately. Look in the examples/ directory for  
examples  
on:

- general usage
- blob io
- schema information

Also Scroll through Amalgalite::Database for a quick example, and a  
general  
overview of the API.

{{ Release notes for Version 0.2.0 }}

- Major Enhancements

- Minor Enhancements

- Bugfixes

---

<div class="post-metadata">

**Author:** ![jeremyheiler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@jeremyheiler](https://www.ruby-forum.com/u/jeremyheiler)\
**Post date:** [July 5, 2008, 12:29pm UTC](https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239/2 "2008-07-05T12:29:53Z")

</div>

Jeremy H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Amalgalite embeds the SQLite database engine in a ruby extension.  
> There is no need to install SQLite separately.  
> Look in the examples/ directory for examples  
> on:
> 
> - general usage
> - blob io
> - schema information

i’ve tested your online example “gem-db.rb”, looks good at insertion,  
however get :

> > > gem-db.rb

Opening database (version 0.2.0)  
Establishing taps  
Create schema  
Inserting 99 rows of gem information…  
Took 0.246415 seconds  
Done Inserting  
NoMethodError: undefined method ‘columns’ for nil:NilClass  
method is\_column\_rowid?  
in statement.rb at line 349  
method result\_meta  
in statement.rb at line 333  
method times  
in statement.rb at line 320  
method result\_meta  
in statement.rb at line 320  
method next\_row  
in statement.rb at line 250  
method all\_rows  
in statement.rb at line 298  
method execute  
in database.rb at line 252  
at top level  
in gem-db.rb at line 72

line 72 being :  
authors\_by\_number = db.execute(“SELECT author, count( name ) as num\_gems  
FROM gems GROUP BY author ORDER BY num\_gems DESC”)

notice i’m now able to read the Firefox 3 bookmarks file  
(“places.sqlite”) having “LONGVARCHAR” (wasn’t OK with version 0.1).

---

<div class="post-metadata">

**Author:** ![jeremyheiler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@jeremyheiler](https://www.ruby-forum.com/u/jeremyheiler)\
**Post date:** [July 6, 2008, 8:00am UTC](https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239/3 "2008-07-06T08:00:41Z")

</div>

Jeremy H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Or download a new example script from github:
> 
> [GitHub - copiousfreetime/amalgalite: SQLite database engine embedded in a ruby extension.](http://github.com/copiousfreetime/amalgalite)  
> /tree/master/examples/gem-db.rb

fine, thanks, it rocks !

> > notice i’m now able to read the Firefox 3 bookmarks file  
> > (“places.sqlite”) having “LONGVARCHAR” (wasn’t OK with version 0.1).
> 
> I haven’t done any testing with a Firefox 3 bookmarks file. I haven’t  
> done anything specifically to address this, but I could see if SQLite  
> internally had decided that one of the values in there was to be stored as  
> a BLOB storage type that amalgalite would have failed before.

favicons are stored there as blob.

best,

---

<div class="post-metadata">

**Author:** ![jeremyheiler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@jeremyheiler](https://www.ruby-forum.com/u/jeremyheiler)\
**Post date:** [July 6, 2008, 8:27am UTC](https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239/4 "2008-07-06T08:27:35Z")

</div>

On Sun, Jul 06, 2008 at 02:56:40PM +0900, Une B?vue wrote:

> > > (“places.sqlite”) having “LONGVARCHAR” (wasn’t OK with version 0.1).
> > 
> > I haven’t done any testing with a Firefox 3 bookmarks file. I haven’t  
> > done anything specifically to address this, but I could see if SQLite  
> > internally had decided that one of the values in there was to be stored as  
> > a BLOB storage type that amalgalite would have failed before.
> 
> favicons are stored there as blob.

Then yup, firefox 3 bookmarks file can be accessed via amalgalite now it  
look  
like. That’s very cool.

enjoy,

-jeremy

---

<div class="post-metadata">

**Author:** ![jeremyheiler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@jeremyheiler](https://www.ruby-forum.com/u/jeremyheiler)\
**Post date:** [July 6, 2008, 11:07am UTC](https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239/5 "2008-07-06T11:07:49Z")

</div>

Jeremy H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > favicons are stored there as blob.
> 
> Then yup, firefox 3 bookmarks file can be accessed via amalgalite now it look  
> like. That’s very cool.

# meta info about that : Table: moz\_favicons

Column : expiration  
|…default\_value :  
|…declared\_data\_type : LONG  
|collation\_sequence\_name : BINARY  
|…not\_null\_constraint : false  
|…primary\_key : false  
|…auto\_increment : false

Column : url  
|…default\_value :  
|…declared\_data\_type : LONGVARCHAR  
|collation\_sequence\_name : BINARY  
|…not\_null\_constraint : false  
|…primary\_key : false  
|…auto\_increment : false

Column : mime\_type  
|…default\_value :  
|…declared\_data\_type : VARCHAR(32)  
|collation\_sequence\_name : BINARY  
|…not\_null\_constraint : false  
|…primary\_key : false  
|…auto\_increment : false

Column : id  
|…default\_value :  
|…declared\_data\_type : INTEGER  
|collation\_sequence\_name : BINARY  
|…not\_null\_constraint : false  
|…primary\_key : true  
|…auto\_increment : false

Column : data  
|…default\_value :  
|…declared\_data\_type : BLOB  
|collation\_sequence\_name : BINARY  
|…not\_null\_constraint : false  
|…primary\_key : false  
|…auto\_increment : false

I’ll try to extract those icons and build an html page with ![]() to learn with.

I get the first one, saved to file, using :  
#! /usr/bin/env ruby

require ‘rubygems’  
require ‘amalgalite’  
require ‘rexml/document’  
require ‘net/http’  
require ‘uri’

db=Amalgalite::Database.new( “places.sqlite” )  
all\_rows=db.execute( “SELECT url, mime\_type, data FROM moz\_favicons” )  
blob\_row = all\_rows.first  
puts blob\_row[‘url’]  
puts blob\_row[‘mime\_type’]  
uri = URI.parse(blob\_row[‘url’])  
p “uri.host = #{uri.host}, uri.port = #{uri.port}, uri.scheme =  
#{uri.scheme}, uri.path = #{uri.path}”  
puts “#{uri.host}_#{File.basename(uri.path)}"  
blob\_row[‘data’].write\_to\_file( "#{uri.host}_#{File.basename(uri.path)}”  
) if !blob\_row[‘data’].nil?

works great !

now, i need that blob as a string to base64 encode it and make use of :

\<img  
src=‘data:#{blob\_row[‘mime\_type’]};base64,#{Base64.b64encode(blob\_row[‘d  
ata’].to\_string\_io.read)}’ /\>

for the time of posting i get no output from #to\_string\_io.read ?

---

<div class="post-metadata">

**Author:** ![jeremyheiler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@jeremyheiler](https://www.ruby-forum.com/u/jeremyheiler)\
**Post date:** [July 5, 2008, 8:50pm UTC](https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239/6 "2008-07-05T20:50:25Z")

</div>

On Sat, Jul 05, 2008 at 07:21:44PM +0900, Une B?vue wrote:

> NoMethodError: undefined method ‘columns’ for nil:NilClass  
> method all\_rows  
> in statement.rb at line 298  
> method execute  
> in database.rb at line 252  
> at top level  
> in gem-db.rb at line 72

This would be a bug in the example. I’ve run it so many times that the  
db  
already existed all the time ran it. This is the patch:

@@ -37,6 +37,7 @@ unless schema.tables[‘gems’]  
author VARCHAR(128)  
);  
SQL

- db.reload\_schema!  
end

# 

Or download a new example script from github:

[http://github.com/copiousfreetime/amalgalite/tree/master/examples/gem-db.rb](http://github.com/copiousfreetime/amalgalite/tree/master/examples/gem-db.rb)

> notice i’m now able to read the Firefox 3 bookmarks file  
> (“places.sqlite”) having “LONGVARCHAR” (wasn’t OK with version 0.1).

I haven’t done any testing with a Firefox 3 bookmarks file. I haven’t  
done  
anything specifically to address this, but I could see if SQLite  
internally had  
decided that one of the values in there was to be stored as a BLOB  
storage type  
that amalgalite would have failed before.

enjoy,

-jeremy

---

<div class="post-metadata">

**Author:** ![jeremyheiler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/34f0e0/32.png) [@jeremyheiler](https://www.ruby-forum.com/u/jeremyheiler)\
**Post date:** [July 6, 2008, 11:55am UTC](https://www.ruby-forum.com/t/amalgalite-0-2-0-released/142239/7 "2008-07-06T11:55:44Z")

</div>

Une Bévue [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> for the time of posting i get no output from #to\_string\_io.read ?

the method is #string )))

* * *

#! /usr/bin/env ruby

require ‘rubygems’  
require ‘amalgalite’  
require ‘uri’  
require ‘base64’

# write the first favicon to “data” URL scheme

# see [http://www.ietf.org/rfc/rfc2397.txt](http://www.ietf.org/rfc/rfc2397.txt)

db=Amalgalite::Database.new( “places.sqlite” )  
all\_rows=db.execute( “SELECT url, mime\_type, data FROM moz\_favicons” )  
blob\_row = all\_rows.first  
uri = URI.parse(blob\_row[‘url’])

## html=“

#{uri.host} #{File.basename(uri.path)}:  
\<img  
src=‘data:#{blob\_row[‘mime\_type’]};base64,#{Base64.b64encode(blob\_row[‘d  
ata’].to\_string\_io.string)}’ /\>

”  
File.open(“#{uri.host}\_favicon.html”,“w”){|f| f.print html}

resulting in :

www.google.com favicon.ico:  
 ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hA%0AAACzUlEQVQ4jWWR%0Aa0iTURyHf9gst5Wa2pyzt2zTzDaz5aZdTMvuWhGlzsrofjEys7B7YUSMIidi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