Browse Source

- fixed getResult()

Franco Ponticelli 16 years ago
parent
commit
f0da72b9a7
1 changed files with 12 additions and 6 deletions
  1. 12 6
      std/php/db/Mysql.hx

+ 12 - 6
std/php/db/Mysql.hx

@@ -135,20 +135,24 @@ private class MysqlResultSet implements ResultSet {
 		return (cache != null);
 		return (cache != null);
 	}
 	}
 
 
+	private var cRow : ArrayAccess<String>;
+	private function fetchRow() : Bool {
+		cRow = untyped __call__("mysql_fetch_array", __r, __php__("MYSQL_NUM"));
+		return ! untyped __physeq__(cRow, false);
+	}
+	
 	public function next() : Dynamic {
 	public function next() : Dynamic {
 		if( cache != null ) {
 		if( cache != null ) {
 			var t = cache;
 			var t = cache;
 			cache = null;
 			cache = null;
 			return t;
 			return t;
 		}
 		}
-		var c = untyped __call__("mysql_fetch_array", __r, __php__("MYSQL_NUM"));
-		if(untyped __physeq__(c, false))
-			return null;
+		if(!fetchRow()) return null;
 
 
 		var o : Dynamic = {};
 		var o : Dynamic = {};
 		var descriptions = getFieldsDescription();
 		var descriptions = getFieldsDescription();
 		for(i in 0...nfields)
 		for(i in 0...nfields)
-			Reflect.setField(o, descriptions[i].name, convert(c[i], descriptions[i].type));
+			Reflect.setField(o, descriptions[i].name, convert(cRow[i], descriptions[i].type));
 		return o;
 		return o;
 	}
 	}
 
 
@@ -160,8 +164,10 @@ private class MysqlResultSet implements ResultSet {
 	}
 	}
 
 
 	public function getResult( n : Int ) : String {
 	public function getResult( n : Int ) : String {
-		var a = untyped __call__("mysql_fetch_row", __r);
-		return a[n];
+		if(cRow == null) 
+			if(!fetchRow())
+				return null;
+		return cRow[n];
 	}
 	}
 
 
 	public function getIntResult( n : Int ) : Int {
 	public function getIntResult( n : Int ) : Int {