sqlite db, fix some bugs