Fixing hardcoded queries that are MySQL specific.

Fixes testsession so it's supports other databases like MSSQL and PostgreSQL.