fix bug in sql_encode