Guest User

Untitled

a guest
May 20th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. # To fix unicode character errors in mysql
  2. # => Put this file in lib and require it in environment.rb
  3.  
  4. require 'mysql'
  5.  
  6. class Mysql::Result
  7. def encode(value, encoding = "utf-8")
  8. String === value ? value.force_encoding(encoding) : value
  9. end
  10.  
  11. def each_utf8(&block)
  12. each_orig do |row|
  13. yield row.map {|col| encode(col) }
  14. end
  15. end
  16. alias each_orig each
  17. alias each each_utf8
  18.  
  19. def each_hash_utf8(&block)
  20. each_hash_orig do |row|
  21. row.each {|k, v| row[k] = encode(v) }
  22. yield(row)
  23. end
  24. end
  25. alias each_hash_orig each_hash
  26. alias each_hash each_hash_utf8
  27. end
Add Comment
Please, Sign In to add comment