Browse Source

minor fixes

Nicolas Cannasse 14 years ago
parent
commit
388a8c7a7f
5 changed files with 48 additions and 26 deletions
  1. 6 1
      doc/ImportAll.hx
  2. 8 0
      std/php/db/Mysql.hx
  3. 26 22
      std/php/db/PDO.hx
  4. 7 2
      std/php/db/Sqlite.hx
  5. 1 1
      std/sys/db/Manager.hx

+ 6 - 1
doc/ImportAll.hx

@@ -27,7 +27,10 @@ import haxe.macro.Context;
 class ImportAll {
 class ImportAll {
 
 
 	public static function run( ?pack ) {
 	public static function run( ?pack ) {
-		if( pack == null ) pack = "";
+		if( pack == null ) {
+			pack = "";
+			haxe.macro.Compiler.define("doc_gen");
+		}
 		switch( pack ) {
 		switch( pack ) {
 		case "php":
 		case "php":
 			if( !Context.defined("php") ) return;
 			if( !Context.defined("php") ) return;
@@ -43,6 +46,8 @@ class ImportAll {
 			if( !Context.defined("flash9") ) return;
 			if( !Context.defined("flash9") ) return;
 		case "mt","mtwin":
 		case "mt","mtwin":
 			return;
 			return;
+		case "sys":
+			if( !Context.defined("neko") && !Context.defined("php") && !Context.defined("cpp") ) return;
 		case "tools":
 		case "tools":
 			return;
 			return;
 		}
 		}

+ 8 - 0
std/php/db/Mysql.hx

@@ -189,6 +189,14 @@ private class MysqlResultSet implements ResultSet {
 	public function getFloatResult( n : Int ) : Float {
 	public function getFloatResult( n : Int ) : Float {
 		return untyped __call__("floatval", getResult(n));
 		return untyped __call__("floatval", getResult(n));
 	}
 	}
+
+	public function getFieldsNames() : Array<String> {
+		var fields = [];
+		for( i in 0...nfields )
+			fields.push(untyped __call__("mysql_field_name", __r, i));
+		return fields;
+	}
+
 }
 }
 
 
 class Mysql {
 class Mysql {

+ 26 - 22
std/php/db/PDO.hx

@@ -40,7 +40,7 @@ class PDO
 		return new PDOConnection(dsn, user, password, options);
 		return new PDOConnection(dsn, user, password, options);
 	}
 	}
 }
 }
-	
+
 extern class PDOClass
 extern class PDOClass
 {
 {
 //	public function new(dns : String, ?username : String, ?password : String, ?driver_options : NativeArray) : Void;
 //	public function new(dns : String, ?username : String, ?password : String, ?driver_options : NativeArray) : Void;
@@ -135,7 +135,7 @@ private class PDOConnection implements Connection {
 			return "x'"+base16_encode(s)+"'";
 			return "x'"+base16_encode(s)+"'";
 		return pdo.quote(s);
 		return pdo.quote(s);
 	}
 	}
-	
+
 	public function addValue( s : StringBuf, v : Dynamic ) {
 	public function addValue( s : StringBuf, v : Dynamic ) {
 		if( untyped __call__("is_int", v) || __call__("is_null", v))
 		if( untyped __call__("is_int", v) || __call__("is_null", v))
 			s.add(v);
 			s.add(v);
@@ -179,7 +179,7 @@ private class TypeStrategy {
 	{
 	{
 		return throw "must override";
 		return throw "must override";
 	}
 	}
-	
+
 	public static function convert(v : String, type : String) : Dynamic {
 	public static function convert(v : String, type : String) : Dynamic {
 		if (v == null) return v;
 		if (v == null) return v;
 		switch(type) {
 		switch(type) {
@@ -237,7 +237,7 @@ private class DBNativeStrategy extends PHPNativeStrategy {
 		this.dbname = dbname.toLowerCase();
 		this.dbname = dbname.toLowerCase();
 		this.key = dbname + SUFFIX;
 		this.key = dbname + SUFFIX;
 	}
 	}
-	
+
 	override function map(data : NativeArray) : Dynamic {
 	override function map(data : NativeArray) : Dynamic {
 		if (!untyped __call__("isset", data[key]))
 		if (!untyped __call__("isset", data[key]))
 			return super.map(data);
 			return super.map(data);
@@ -261,10 +261,10 @@ private class BaseResultSet implements php.db.ResultSet {
 	var _fields : Int;
 	var _fields : Int;
 	var _columnNames : Array<String>;
 	var _columnNames : Array<String>;
 	var _columnTypes : Array<String>;
 	var _columnTypes : Array<String>;
-	
+
 	public var length(getLength, null) : Int;
 	public var length(getLength, null) : Int;
 	public var nfields(getNFields, null) : Int;
 	public var nfields(getNFields, null) : Int;
-	
+
 	public function new(pdo : PDOStatement, typeStrategy : TypeStrategy)
 	public function new(pdo : PDOStatement, typeStrategy : TypeStrategy)
 	{
 	{
 		this.pdo = pdo;
 		this.pdo = pdo;
@@ -274,7 +274,7 @@ private class BaseResultSet implements php.db.ResultSet {
 		this._columnTypes = [];
 		this._columnTypes = [];
 		feedColumns();
 		feedColumns();
 	}
 	}
-	
+
 	private function feedColumns() {
 	private function feedColumns() {
 		for (i in 0..._fields) {
 		for (i in 0..._fields) {
 			var data = pdo.getColumnMeta(i);
 			var data = pdo.getColumnMeta(i);
@@ -282,19 +282,19 @@ private class BaseResultSet implements php.db.ResultSet {
 			_columnTypes.push(typeStrategy.map(data));
 			_columnTypes.push(typeStrategy.map(data));
 		}
 		}
 	}
 	}
-	
+
 	public function getFloatResult(index : Int) : Float {
 	public function getFloatResult(index : Int) : Float {
 		return untyped __call__("floatval", getResult(index));
 		return untyped __call__("floatval", getResult(index));
 	}
 	}
-	
+
 	public function getIntResult(index : Int) : Int {
 	public function getIntResult(index : Int) : Int {
 		return untyped __call__("intval", getResult(index));
 		return untyped __call__("intval", getResult(index));
 	}
 	}
-	
+
 	public function getResult(index : Int) : String {
 	public function getResult(index : Int) : String {
 		return throw "must override";
 		return throw "must override";
 	}
 	}
-	
+
 	public function hasNext() : Bool {
 	public function hasNext() : Bool {
 		return throw "must override";
 		return throw "must override";
 	}
 	}
@@ -302,11 +302,11 @@ private class BaseResultSet implements php.db.ResultSet {
 	function getLength() : Int {
 	function getLength() : Int {
 		return throw "must override";
 		return throw "must override";
 	}
 	}
-	
+
 	function nextRow() : NativeArray {
 	function nextRow() : NativeArray {
 		return throw "must override";
 		return throw "must override";
 	}
 	}
-	
+
 	public function next() : Dynamic {
 	public function next() : Dynamic {
 		var row = nextRow();
 		var row = nextRow();
 		var o : Dynamic = { };
 		var o : Dynamic = { };
@@ -314,11 +314,11 @@ private class BaseResultSet implements php.db.ResultSet {
 			Reflect.setField(o, _columnNames[i], TypeStrategy.convert(row[i], _columnTypes[i]));
 			Reflect.setField(o, _columnNames[i], TypeStrategy.convert(row[i], _columnTypes[i]));
 		return o;
 		return o;
 	}
 	}
-	
+
 	function getNFields() : Int {
 	function getNFields() : Int {
 		return _fields;
 		return _fields;
 	}
 	}
-	
+
 	public function results() : List<Dynamic>
 	public function results() : List<Dynamic>
 	{
 	{
 		var list = new List();
 		var list = new List();
@@ -326,13 +326,17 @@ private class BaseResultSet implements php.db.ResultSet {
 			list.add(next());
 			list.add(next());
 		return list;
 		return list;
 	}
 	}
+
+	public function getFieldsNames() : Array<String> {
+		return throw "Not implemented";
+	}
 }
 }
 
 
 private class AllResultSet extends BaseResultSet {
 private class AllResultSet extends BaseResultSet {
 	var all : NativeArray;
 	var all : NativeArray;
 	var pos : Int;
 	var pos : Int;
 	var _length : Int;
 	var _length : Int;
-	
+
 	public function new(pdo : PDOStatement, typeStrategy : TypeStrategy)
 	public function new(pdo : PDOStatement, typeStrategy : TypeStrategy)
 	{
 	{
 		super(pdo, typeStrategy);
 		super(pdo, typeStrategy);
@@ -340,14 +344,14 @@ private class AllResultSet extends BaseResultSet {
 		this.pos = 0;
 		this.pos = 0;
 		this._length = untyped __call__("count", all);
 		this._length = untyped __call__("count", all);
 	}
 	}
-	
+
 	override function getResult(index : Int) : String {
 	override function getResult(index : Int) : String {
 		untyped if(__call__("isset", all[0]) && __call__("isset", all[0][index]))
 		untyped if(__call__("isset", all[0]) && __call__("isset", all[0][index]))
 			return all[0][index];
 			return all[0][index];
 		else
 		else
 			return null;
 			return null;
 	}
 	}
-	
+
 	override function hasNext() : Bool {
 	override function hasNext() : Bool {
 		return pos < _length;
 		return pos < _length;
 	}
 	}
@@ -355,7 +359,7 @@ private class AllResultSet extends BaseResultSet {
 	override function getLength() : Int {
 	override function getLength() : Int {
 		return _length;
 		return _length;
 	}
 	}
-	
+
 	override function nextRow() : NativeArray {
 	override function nextRow() : NativeArray {
 		return all[pos++];
 		return all[pos++];
 	}
 	}
@@ -367,7 +371,7 @@ private class PDOResultSet extends BaseResultSet {
 	{
 	{
 		super(pdo, typeStrategy);
 		super(pdo, typeStrategy);
 	}
 	}
-	
+
 	override function getResult(index : Int) : String {
 	override function getResult(index : Int) : String {
 		if (!hasNext())
 		if (!hasNext())
 			return null;
 			return null;
@@ -379,7 +383,7 @@ private class PDOResultSet extends BaseResultSet {
 			cacheRow();
 			cacheRow();
 		return (untyped cache);
 		return (untyped cache);
 	}
 	}
-	
+
 	override function getLength() {
 	override function getLength() {
 		if (untyped __physeq__(pdo, false))
 		if (untyped __physeq__(pdo, false))
 			return 0;
 			return 0;
@@ -389,7 +393,7 @@ private class PDOResultSet extends BaseResultSet {
 	private function cacheRow() {
 	private function cacheRow() {
 		cache = untyped pdo.fetch(__php__("PDO::FETCH_NUM"), __php__("PDO::FETCH_ORI_NEXT"));
 		cache = untyped pdo.fetch(__php__("PDO::FETCH_NUM"), __php__("PDO::FETCH_ORI_NEXT"));
 	}
 	}
-	
+
 	override function nextRow()
 	override function nextRow()
 	{
 	{
 		if (!hasNext())
 		if (!hasNext())

+ 7 - 2
std/php/db/Sqlite.hx

@@ -106,7 +106,7 @@ private class SqliteResultSet implements ResultSet {
 	public function new( r ) {
 	public function new( r ) {
 		this.r = r;
 		this.r = r;
 	}
 	}
-	
+
 	private function getLength() {
 	private function getLength() {
 		if(untyped __physeq__(r, true))
 		if(untyped __physeq__(r, true))
 			return untyped __call__("sqlite_changes", r);
 			return untyped __call__("sqlite_changes", r);
@@ -143,7 +143,7 @@ private class SqliteResultSet implements ResultSet {
 		if(!fetchRow()) return null;
 		if(!fetchRow()) return null;
 		return untyped __call__("_hx_anonymous", cRow);
 		return untyped __call__("_hx_anonymous", cRow);
 	}
 	}
-	
+
 	public function results() : List<Dynamic> {
 	public function results() : List<Dynamic> {
 		var l = new List();
 		var l = new List();
 		while( true ) {
 		while( true ) {
@@ -168,6 +168,11 @@ private class SqliteResultSet implements ResultSet {
 	public function getFloatResult( n : Int ) : Float {
 	public function getFloatResult( n : Int ) : Float {
 		return untyped __call__("floatval", getResult(n));
 		return untyped __call__("floatval", getResult(n));
 	}
 	}
+
+	public function getFieldsNames() : Array<String> {
+		return throw "Not implemented";
+	}
+
 }
 }
 
 
 class Sqlite {
 class Sqlite {

+ 1 - 1
std/sys/db/Manager.hx

@@ -26,7 +26,7 @@ package sys.db;
 import Reflect;
 import Reflect;
 import sys.db.Connection;
 import sys.db.Connection;
 
 
-#if !spod_macro
+#if (!spod_macro && !doc_gen && !macro)
 #error "Please use -D spod_macro when using new SPOD version"
 #error "Please use -D spod_macro when using new SPOD version"
 #end
 #end