Initial try at implementing text_counter

Warning: this code written by somebody has never used SQLite so it's
probably horrific. Somebody come along and tidy up after me please :-)