Types for flexible attributes

This is a rebase of #947, with a couple of fixes and docs (also relevant to #445 and #647). Types! Types for everybody!

There's one outstanding unfortunate issue. The schema for the flexattr tables currently has a [type affinity](http://www.sqlite.org/datatype3.html) of TEXT for the value column. This means that values are being coerced to strings when they're stored to the database. I changed this in the setup code, but we'll need some manner of backwards-compatibility. Looks like it's not easy.