Make the logic for manipulating sqlite data types a bit more solid

Closes #1049