Permalink
Browse files

fix replace String type

  • Loading branch information...
1 parent 94e0bf2 commit 53d5fed4b02fe2b9c7f6849a19d9ee7d7a521c2d @at-grandpa committed Oct 13, 2016
Showing with 12 additions and 9 deletions.
  1. +1 −9 src/mysql/query.cr
  2. +11 −0 src/mysql/types.cr
View
@@ -42,15 +42,7 @@ module MySQL
end
private def replace(s, name, value)
- result = ""
- len = name.size
- p0 = 0
- while p1 = s.index(name, p0)
- result += s[p0...p1]
- result += value
- p0 = p1 + len
- end
- result + s[p0..-1]
+ s.gsub(/#{name}/, value)
end
def representation(value)
View
@@ -60,6 +60,7 @@ module MySQL
private def lift_down_class(value : ::Float) Float end
private def lift_down_class(value : Time) Datetime end
private def lift_down_class(value : Slice(UInt8)) Blob end
+ private def lift_down_class(value : String) Text end
private def lift_down_class(value) Value end
end
@@ -73,6 +74,16 @@ module MySQL
end
end
+ class Text < Value
+ def _parsed
+ value.to_s
+ end
+
+ def to_mysql
+ %{'#{value.to_s}'}
+ end
+ end
+
class Datetime < Value
def _parsed
Time::Format.new("%F %T").parse(value.to_s, Time::Kind::Utc)

0 comments on commit 53d5fed

Please sign in to comment.