Browse Source

[php/neko] Handle the types at Manager that cannot be handled correctly at the drivers' side

Cauê Waneck 11 years ago
parent
commit
c6bfb3fef4
1 changed files with 27 additions and 0 deletions
  1. 27 0
      std/sys/db/Manager.hx

+ 27 - 0
std/sys/db/Manager.hx

@@ -319,6 +319,33 @@ class Manager<T : Object> {
 			Reflect.setField(o, f, Reflect.field(x, f));
 		untyped o._manager = this;
 		#end
+		for (f in Reflect.fields(x) )
+		{
+			var val:Dynamic = Reflect.field(x,f), info = table_infos.hfields.get(f);
+			if (val != null && info != null) switch (info.t) {
+				case DDate, DDateTime if (!Std.is(val,Date)):
+					if (Std.is(val,Float))
+					{
+						val = Date.fromTime(val);
+					} else {
+						val = Date.fromString(val +"");
+					}
+				case DSmallBinary, DLongBinary, DBinary, DBytes(_) if (Std.is(val, String)):
+					val = haxe.io.Bytes.ofString(val);
+				case DBool if (!Std.is(val,Bool)):
+					if (Std.is(val,Int))
+						val = val != 0;
+					else if (Std.is(val, String)) switch (val.toLowerCase()) {
+						case "1", "true": val = true;
+						case "0", "false": val = false;
+					}
+				case DFloat if (Std.is(val,String)):
+					val = Std.parseFloat(val);
+				case _:
+			}
+
+			Reflect.setField(o, f, val);
+		}
 		Reflect.setField(o,cache_field,x);
 		addToCache(o);
 		untyped o._lock = lock;