Updated qwifi.py

Replaced a loop with an sql query. Also added some error catching. I also made sure we were commiting to the database often enough. We were missing a commit or two.