changed wildcard escape logic

(cherry picked from commit b6d2547a0d8369b7d1e3ba13bd5ed3fe95118d72)
Merge pull request #384 from Eric-Guo/rails-4.1

Escape wildcards for Mysql2 and PostgreSQL only