Use sqlite locking on db file

Use CREATE INDEX/TABLE IF NOT EXISTS to prevent DB errors and
preserve creation functionality for new instances.
Merge pull request #271 from openquery/create-if-not-exists

Use sqlite locking on db file