Piotr Labudda 8 rokov pred
rodič
commit
bfce79f04d

+ 53 - 55
SE/se-lib/Data_Source.php

@@ -30,15 +30,20 @@ class Data_Source {
 	private $_showMsgsSpecialFilter = false;
 
 	function __construct($db = null) {
-		if ($db) {
-			$this->_db = DB::getDB($db);
-		} else {
-			$this->_db = DB::getDB();
-		}
+		$this->_idDatabase = ($db) ? $db : null;
+		// if ($db) { // TODO: RM use DB::getPDO($this->_idDatabase)
+		// 	$this->_db = DB::getDB($db); // TODO: RM
+		// } else {
+		// 	$this->_db = DB::getDB(); // TODO: RM
+		// }
 		$this->_default_sql_limit = 10;
 		$this->_showMsgsSpecialFilter = true;// TODO: allow by acl, procesy?
 	}
 
+	function getDB() {
+		return ($this->_idDatabase) ? DB::getDB($this->_idDatabase) : DB::getDB();
+	}
+
 	function set_table($tbl) {// TODO: RMME
 		$this->setTable($tbl);
 	}
@@ -50,16 +55,12 @@ class Data_Source {
 	}
 
 	function get_cols() {
-		// TODO: cache in session
 		if (empty($this->_cols)) {
-			if (!$this->_tbl) {
-				return $this->_tbl;
-			}
-			$sql = "show fields from `{$this->_tbl}` ; ";
-			$res = $this->_db->query($sql);
-			while ($r = $this->_db->fetch($res)) {
-				$this->_cols[$r->Field] = $r->Field;
-				$this->_col_types[$r->Field] = $r->Type . ';' . $r->Default;
+			if (!$this->_tbl) return null;
+			foreach (DB::getPDO($this->_idDatabase)->fetchAll(" show fields from `{$this->_tbl}` ") as $row) {
+				$fieldName = $row['Field'];
+				$this->_cols[ $fieldName ] = $fieldName;
+				$this->_col_types[ $fieldName ] = "{$row['Type']};{$row['Default']}";
 			}
 		}
 		return $this->_cols;
@@ -67,26 +68,23 @@ class Data_Source {
 
 	public function getFieldTypes() {
 		$fieldTypes = array();
-		//$dbID = $this->getDB();
-		$db = $this->_db;//(TableAcl) DB::getDB($dbID);
-		$tblName = $this->_tbl;//(TableAcl) $this->getName();
-		if (!$db) {
-			throw new Exception('DataSource is not defined');
-		}
-		$res = $db->query("show fields from `{$tblName}` ");
-		while ($h = $db->fetch_row($res)) {
-			$fieldName = $h[0];
-			$fieldType = $h[1];
-			$fieldTypes[$fieldName] = array('type'=>$h[1], 'null'=>('YES' == $h[2]), 'default'=>$h[4]);
-		}
-		DBG::_('DBG_DS', '>4', "types({$tblName})", $fieldTypes, __CLASS__, __FUNCTION__, __LINE__);
+		foreach (DB::getPDO($this->_idDatabase)->fetchAll(" show fields from `{$this->_tbl}` ") as $row) {
+			$fieldName = $row['Field'];
+			$fieldType = $row['Type'];
+			$fieldTypes[ $fieldName ] = [
+				'type' => $fieldType,
+				'null' => ('YES' == $row['Null']),
+				'default' => $row['Default']
+			];
+		}
+		DBG::log($fieldTypes, 'array', "types({$this->_tbl})");
 		return $fieldTypes;
 	}
 
 	public function getUniqueKeys() {
 		$sqlKeys = array();
 		//$dbID = $this->getDB();
-		$db = $this->_db;//(TableAcl) DB::getDB($dbID);
+		$db = $this->getDB();
 		$tblName = $this->_tbl;//(TableAcl) $this->getName();
 		if (!$db) {
 			throw new Exception('DataSource is not defined');
@@ -492,37 +490,37 @@ class Data_Source {
 				}
 
 				if (substr($v, 0, 1) == '=') {
-					$v = $this->_db->_(substr($v, 1));
+					$v = $this->getDB()->_(substr($v, 1));
 					if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`='{$v}'";
 				}
 				else if ($v == '!NULL' || $v == 'IS NOT NULL') {
 					$sql_where_and[] = "t.`{$fldName}` is not null";
 				}
 				else if (substr($v, 0, 1) == '!') {
-					$v = $this->_db->_(substr($v, 1));
+					$v = $this->getDB()->_(substr($v, 1));
 					if (strlen($v)) $sql_where_and[] = "t.`{$fldName}` not like '{$v}'";
 				}
 				else if (substr($v, 0, 2) == '<=') {
-					$v = $this->_db->_(substr($v, 2));
+					$v = $this->getDB()->_(substr($v, 2));
 					if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`<='{$v}'";
 				}
 				else if (substr($v, 0, 2) == '>=') {
-					$v = $this->_db->_(substr($v, 2));
+					$v = $this->getDB()->_(substr($v, 2));
 					if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`>='{$v}'";
 				}
 				else if (substr($v, 0, 1) == '<') {
-					$v = $this->_db->_(substr($v, 1));
+					$v = $this->getDB()->_(substr($v, 1));
 					if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`<'{$v}'";
 				}
 				else if (substr($v, 0, 1) == '>') {
-					$v = $this->_db->_(substr($v, 1));
+					$v = $this->getDB()->_(substr($v, 1));
 					if (strlen($v)) $sql_where_and[] = "t.`{$fldName}`>'{$v}'";
 				}
 				else if (false !== strpos($v, '%')) {
 					$sql_where_and[] = "t.`{$fldName}` like '{$v}'";
 				}
 				else if ($this->isColTypeNumber($fldName)) {
-					$v = $this->_db->_($v);
+					$v = $this->getDB()->_($v);
 					$sql_where_and[] = "t.`{$fldName}`='{$v}'";
 				}
 				else {
@@ -531,7 +529,7 @@ class Data_Source {
 					$sqlWhereWords = array();
 					if (!empty($searchWords)) {
 						foreach ($searchWords as $word) {
-							$sqlWord = $this->_db->_($word);
+							$sqlWord = $this->getDB()->_($word);
 							$sqlWhereWords[] = "t.`{$fldName}` like '%{$sqlWord}%'";
 						}
 					}
@@ -555,7 +553,7 @@ class Data_Source {
 			else if ('primaryKey' == $k) {
 				if (!empty($v)) {
 					$primaryKeyField = $this->getPrimaryKeyField();
-					$sql_where_and[] = "t.`{$primaryKeyField}` = '" . $this->_db->_($v) . "'";
+					$sql_where_and[] = "t.`{$primaryKeyField}` = '" . $this->getDB()->_($v) . "'";
 				}
 			}
 		}
@@ -640,8 +638,8 @@ class Data_Source {
 			where t.`{$primaryKeyField}`='{$primaryKey}'
 		";
 		// TODO: use PDO
-		$res = $this->_db->query($sql);
-		if ($r = $this->_db->fetch($res)) {
+		$res = $this->getDB()->query($sql);
+		if ($r = $this->getDB()->fetch($res)) {
 			$ret = $r;
 		}
 		return $ret;
@@ -713,8 +711,8 @@ class Data_Source {
 			limit {$sql->limit} offset {$sql->offset}
 		";
 		DBG::log([ 'msg'=>"Data_Source::getItems - \$sql", '$sql'=>$sql ]);
-		$res = $this->_db->query($sql->query);
-		while ($r = $this->_db->fetch($res)) {
+		$res = $this->getDB()->query($sql->query);
+		while ($r = $this->getDB()->fetch($res)) {
 			$items[$r->{$primaryKeyField}] = $r;
 		}
 		return $items;
@@ -752,8 +750,8 @@ class Data_Source {
 			order by ID DESC
 		";
 		DBG::_('DBG_DS', '>1', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
-		$res = $this->_db->query($sql);
-		while ($r = $this->_db->fetch($res)) {
+		$res = $this->getDB()->query($sql);
+		while ($r = $this->getDB()->fetch($res)) {
 			$r->_author = $r->A_RECORD_UPDATE_AUTHOR;
 			$r->_created = $r->A_RECORD_UPDATE_DATE;
 
@@ -781,8 +779,8 @@ class Data_Source {
 			from {$this->_tbl} as t
 			where {$sql_where}
 		";
-		$res = $this->_db->query($sql);
-		if ($r = $this->_db->fetch($res)) {
+		$res = $this->getDB()->query($sql);
+		if ($r = $this->getDB()->fetch($res)) {
 			$ret = $r->cnt;
 		}
 		return $ret;
@@ -843,8 +841,8 @@ class Data_Source {
 			from `{$this->_tbl}`
 			where {$sql_where}
 		";
-		$res = $this->_db->query($sql);
-		if ($r = $this->_db->fetch($res)) {
+		$res = $this->getDB()->query($sql);
+		if ($r = $this->getDB()->fetch($res)) {
 			$ret = $r->cnt;
 		}
 		return $ret;
@@ -863,8 +861,8 @@ class Data_Source {
 			where {$sql_where}
 			limit {$this->_sql_limit} offset {$this->_sql_offset}
 		";
-		$res = $this->_db->query($sql);
-		while ($r = $this->_db->fetch($res)) {
+		$res = $this->getDB()->query($sql);
+		while ($r = $this->getDB()->fetch($res)) {
 			$ret[$r->{$primaryKeyField}] = $r;
 		}
 		return $ret;
@@ -897,7 +895,7 @@ class Data_Source {
 				}
 			}
 		}
-		$affected = $this->_db->PDATE_OBJ($this->_tbl, $sql_obj);
+		$affected = $this->getDB()->PDATE_OBJ($this->_tbl, $sql_obj);
 		return $affected;
 	}
 
@@ -914,7 +912,7 @@ class Data_Source {
 				}
 			}
 		}
-		$insert_id = $this->_db->ADD_NEW_OBJ($this->_tbl, $sql_obj);
+		$insert_id = $this->getDB()->ADD_NEW_OBJ($this->_tbl, $sql_obj);
 		return $insert_id;
 	}
 
@@ -956,7 +954,7 @@ class Data_Source {
 		}
 
 		$itemPatch = (object)$itemPatch;
-		$affected = $this->_db->UPDATE_OBJ($this->_tbl, $itemPatch);
+		$affected = $this->getDB()->UPDATE_OBJ($this->_tbl, $itemPatch);
 		if ($affected < 0) {
 			$dsErrors = $this->getDbErrors();
 			//$dsErrors = "Wystąpiły błędy!\n" . implode("\n", $dsErrors);
@@ -988,7 +986,7 @@ class Data_Source {
 			}
 		}
 
-		$primaryKey = $this->_db->ADD_NEW_OBJ($this->_tbl, (object)$item);
+		$primaryKey = $this->getDB()->ADD_NEW_OBJ($this->_tbl, (object)$item);
 		if ($primaryKey <= 0) {
 			$dsErrors = $this->getDbErrors();
 			$dsErrors = "Wystąpiły błędy!\n" . implode("\n", $dsErrors);
@@ -999,8 +997,8 @@ class Data_Source {
 
 	public function getDbErrors() {
 		$errors = array();
-		if ($this->_db->has_errors()) {
-			$errorsSql = $this->_db->get_errors();
+		if ($this->getDB()->has_errors()) {
+			$errorsSql = $this->getDB()->get_errors();
 			foreach ($errorsSql as $vErr) {
 				if ('SQL QUERY FAILED: ' == substr($vErr, 0, 18)) {
 					$vErr = substr($vErr, 18);

+ 9 - 12
SE/se-lib/ProcesHelper.php

@@ -357,17 +357,17 @@ class ProcesHelper {
 
 	public static function getZasobTableInfoByUri($uri) {
 		$zasobObj = null;
-		$db = DB::getDB();
 		$uriParts = explode('/', $uri);
 		if (count($uriParts) < 2) {
 			return null;
 		}
 		$tblName = array_pop($uriParts);
 		$dbName = array_pop($uriParts);
-		if ('default_db' == $dbName) {
-			$dbName = $db->getDatabaseName();
+		if ('default_db' === $dbName) {
+			$dbName = DB::getPDO()->getDatabaseName();
 		}
-		return (object)DB::getPDO()->fetchFirst("select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`
+		return (object)DB::getPDO()->fetchFirst("
+			select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`
 				, zp.`ID` as P__ID, zp.`DESC` as P__DESC, zp.`TYPE` as P__TYPE
 			from `CRM_LISTA_ZASOBOW` as z
 				left join `CRM_LISTA_ZASOBOW` as zp on(zp.`ID`=z.`PARENT_ID`)
@@ -380,18 +380,15 @@ class ProcesHelper {
 
 	public static function getZasobTableFieldsInfo($id) {
 		$fldsInfo = array();
-		$db = DB::getDB();
-		$sql = "select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`, z.`SORT_PRIO`
+		$sql = "
+			select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`, z.`SORT_PRIO`
 			from `CRM_LISTA_ZASOBOW` as z
 			where z.`TYPE`='KOMORKA'
 				and z.`PARENT_ID`={$id}
 		";
-		DBG::_('DBG_SQL', '>1', "sql", $sql, __CLASS__, __FUNCTION__, __LINE__);
-		$res = $db->query($sql);
-		while ($r = $db->fetch($res)) {
-			$fldsInfo[$r->DESC] = $r;
-		}
-		return $fldsInfo;
+		return array_map(function ($row) {
+			return (object)$row;
+		}, DB::getPDO()->fetchAllByKey($sql, 'DESC'));
 	}
 
 	public static function getZasobInfo($zasobID) {

+ 7 - 9
SE/se-lib/Route/Msgs.php

@@ -289,24 +289,22 @@ SQL_QUERY;
 
 	public function getActiveMessagesForTable($tblName) {
 		if (empty($tblName)) return;
-		$db = DB::getDB();
-		$tblName = $db->_($tblName);
-
+		$sqlTableName = DB::getPDO()->quote($tblName);
 		$usrLogin = User::getLogin();
-		$msgs = null;
-		$sql = "select m.*
+		$msgs = [];
+		$sql = "
+			select m.*
 			from `CRM_UI_MSGS` m
 			where m.`uiTargetType`='default_db_table'
 				and m.`A_STATUS`='WAITING'
-				and m.`uiTargetName`='{$tblName}'
+				and m.`uiTargetName`={$sqlTableName}
 				and (m.`userTargetType` in('everyone')
 					or (m.`userTargetType`='user' and m.`userTargetName`='{$usrLogin}')
 					-- TODO: use 'admin', 'group'
 				)
 		";
-		$db = DB::getDB();
-		$res = $db->query($sql);
-		while ($r = $db->fetch($res)) {
+		foreach (DB::getPDO()->fetchAll($sql) as $row) {
+			$r = (object)$row;
 			if ($msg = $this->parseMessage($r)) {
 				$msg['link'] = 'index.php?_route=Msgs&_task=run&_msgId=' . $r->ID;
 				$msg['linkType'] = 'ajax';

+ 5 - 7
SE/se-lib/TableAjaxMap.php

@@ -1295,8 +1295,8 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 
 		if (!array_key_exists($idTable, $_cache)) {
 			$layers = array();
-			$db = DB::getDB();
-			$sql = "select layer.`ID`
+			$sql = "
+				select layer.`ID`
 					, layer.`DESC`
 					, layer.`DESC_PL`
 					, layer.`OPIS`
@@ -1317,11 +1317,9 @@ var myOpenLayers_Control_ManageLayers = OpenLayers.Class(OpenLayers.Control, {
 					and layers.`DESC`='MAP_ADDITIONAL_LAYERS'
 				order by layer.`SORT_PRIO`
 			";
-			//echo '<pre>L.' . __LINE__ . ' $sql:'."\n";print_r($sql);echo '</pre>';
-			$res = $db->query($sql);
-			while ($r = $db->fetch($res)) {
-				$layers[] = $r;
-			}
+			$layers = array_map(function ($row) {
+				return (object)$row;
+			}, DB::getPDO()->fetchAll($sql));
 			$_cache[$idTable] = $layers;
 		}
 		return $_cache[$idTable];

+ 67 - 74
SE/se-lib/Typespecial.php

@@ -106,9 +106,9 @@ class Typespecial extends TypespecialBase {
 			return;
 		}
 
-		$db = DB::getDB();
 		$typeSpecials = array();
-		$sql = "select z.`ID`
+		$sql = "
+			select z.`ID`
 				, z.`ALIAS_ID` as fieldID
 				, zpp.`ID` as TYPE_ID
 			from `CRM_LISTA_ZASOBOW` as z
@@ -121,8 +121,8 @@ class Typespecial extends TypespecialBase {
 				and z.`ALIAS_ID` in(" . implode(",", $fieldIds) . ")
 		";
 		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
-		$res = $db->query($sql);
-		while ($r = $db->fetch($res)) {
+		foreach (DB::getPDO()->fetchAll($sql) as $row) {
+			$r = (object)$row;
 			$r->params_out = array();
 			$r->filters = array();
 			$typeSpecials[$r->TYPE_ID] = $r;
@@ -130,14 +130,13 @@ class Typespecial extends TypespecialBase {
 			$_SESSION['Typespecial_Cache']['map'][$r->fieldID] = $r->TYPE_ID;
 			$_SESSION['Typespecial_Cache']['map_param_out'][$r->fieldID] = $r->TYPE_ID;
 		}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecials (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecials);echo'</pre>';}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid blue;text-align:left;">typeSpecials_2 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecials_2);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecials (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecials);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid blue;text-align:left;">typeSpecials_2 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecials_2);echo'</pre>';}
 
-		if (empty($typeSpecials)) {
-			return;
-		}
+		if (empty($typeSpecials)) return;
 
-		$sql = "select z.`ID`
+		$sql = "
+			select z.`ID`
 				, z.`ALIAS_ID`
 				, z.`TYPE`
 				, z.`DESC`
@@ -156,9 +155,9 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
 				and z.`TYPE` not in('PARAM_IN')
 				and zp.`PARENT_ID` in(" . implode(",", array_keys($typeSpecials)) . ")
 		";
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
-		$res = $db->query($sql);
-		while ($r = $db->fetch($res)) {
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
+		foreach (DB::getPDO()->fetchAll($sql) as $row) {
+			$r = (object)$row;
 			if ($r->TYPE_TYPE == 'PARAM_OUT') {
 				$typeSpecials[$r->TYPE_ID]->params_out[$r->PARAM_ID][] = $r;
 			}
@@ -199,7 +198,7 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
 				$typeSpecials[$r->TYPE_ID]->filters[$r->PARAM_ID]->filtersByID[$r->ID] = $param;
 			}
 		}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecials (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecials);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecials (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecials);echo'</pre>';}
 
 		$typeSpecialsByField = array();// table, db info
 		$aliasesMap = array();
@@ -249,7 +248,7 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
 		}
 
 		{// fetch filters recursive
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecialsByField update by filtersTodoIds (F.' . __FUNCTION__ . ':' . __LINE__ . '): '."\n";}
+			if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecialsByField update by filtersTodoIds (F.' . __FUNCTION__ . ':' . __LINE__ . '): '."\n";}
 			$filtersTodoIds = array();
 			foreach ($typeSpecialsByField as $kFldID => $vType) {
 				if (!empty($vType->filters)) {
@@ -260,17 +259,18 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
 					}
 				}
 			}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo "filtersTodoIds: [" . implode(",", array_keys($filtersTodoIds)) . "]\n";}
+			if(V::get('DBG_TS', 0, $_GET) > 0){echo "filtersTodoIds: [" . implode(",", array_keys($filtersTodoIds)) . "]\n";}
 
 			$deepLimit = 3;
 			for ($i = 0; $i < $deepLimit; $i++) {
-if(V::get('DBG_TS', 0, $_GET) > 0){echo "loop i({$i}) filtersTodoIds[" . implode(",", array_keys($filtersTodoIds)) . "] \n";}
+				if(V::get('DBG_TS', 0, $_GET) > 0){echo "loop i({$i}) filtersTodoIds[" . implode(",", array_keys($filtersTodoIds)) . "] \n";}
 				if (empty($filtersTodoIds)) {
 					break;
 				}
 
 				$newFiltersTodoIds = array();
-				$sql = "select z.`ID`
+				$sql = "
+					select z.`ID`
 						, z.`ALIAS_ID`
 						, z.`TYPE`
 						, z.`DESC`
@@ -283,12 +283,12 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo "loop i({$i}) filtersTodoIds[" . implode
 					where
 						z.`PARENT_ID` in(" . implode(",", array_keys($filtersTodoIds)) . ")
 				";
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;display:none">sql (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
-				$res = $db->query($sql);
-				while ($r = $db->fetch($res)) {
+				if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;display:none">sql (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
+				foreach (DB::getPDO()->fetchAll($sql) as $row) {
+					$r = (object)$row;
 					$fltr = $filtersTodoIds[$r->PARENT_ID];
-if(V::get('DBG_TS', 0, $_GET) > 0){echo "\tr: {" . json_encode($r) . "}\n";}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo "\t\tfltr: {" . json_encode($fltr) . "}\n";}
+					if(V::get('DBG_TS', 0, $_GET) > 0){echo "\tr: {" . json_encode($r) . "}\n";}
+					if(V::get('DBG_TS', 0, $_GET) > 0){echo "\t\tfltr: {" . json_encode($fltr) . "}\n";}
 					$typeSpecialsByField[$fltr['type']]->filters[$fltr['filter']]->filtersByID[$r->ID] = $r;
 					$newFiltersTodoIds[$r->ID] = array('type' => $fltr['type'], 'filter' => $fltr['filter']);
 
@@ -298,17 +298,18 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo "\t\tfltr: {" . json_encode($fltr) . "}\
 				}
 				$filtersTodoIds = $newFiltersTodoIds;
 			}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo '</pre>';}
+			if(V::get('DBG_TS', 0, $_GET) > 0){echo '</pre>';}
 		}
 
 		foreach ($typeSpecialsByField as $kFieldID => $vType) {
 			$vType->filters = Typespecial::convertFilters($vType->filters);
 		}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecialsByField (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecialsByField);echo'</pre>';}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">aliasesMap (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($aliasesMap);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecialsByField (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecialsByField);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">aliasesMap (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($aliasesMap);echo'</pre>';}
 		$sqlTables = array();
 		if (!isset($_SESSION['Typespecial_Cache']['sqlTablesInfo'])) $_SESSION['Typespecial_Cache']['sqlTablesInfo'] = array();
-		$sql = "select z.`ID`
+		$sql = "
+			select z.`ID`
 				, z.`PARENT_ID`
 				, z.`ALIAS_ID`
 				, z.`TYPE`
@@ -326,22 +327,22 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
 		--		and zpp.`TYPE` in('DATABASE', 'DATABASE_MYSQL')
 				and z.`ID` in(" . implode(",", array_keys($aliasesMap)) . ")
 		";
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (C.' . __CLASS__ . ':C.' . __CLASS__ . ':F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
-			$res = $db->query($sql);
-			while ($r = $db->fetch($res)) {
-				$_SESSION['Typespecial_Cache']['sqlTablesInfo'][$r->ID] = (object)array('tbl_id'=>$r->TBL_ID, 'db_id'=>$r->DB_ID, 'tbl_name'=>$r->TBL_NAME);
-			}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sqlTablesInfo (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SESSION['Typespecial_Cache']['sqlTablesInfo']);echo'</pre>';}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left">typeSpecialsByField update by sqlTablesInfo (F.' . __FUNCTION__ . ':' . __LINE__ . '): '."\n";}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (C.' . __CLASS__ . ':C.' . __CLASS__ . ':F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
+		foreach (DB::getPDO()->fetchAll($sql) as $row) {
+			$r = (object)$row;
+			$_SESSION['Typespecial_Cache']['sqlTablesInfo'][$r->ID] = (object)array('tbl_id'=>$r->TBL_ID, 'db_id'=>$r->DB_ID, 'tbl_name'=>$r->TBL_NAME);
+		}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sqlTablesInfo (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SESSION['Typespecial_Cache']['sqlTablesInfo']);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left">typeSpecialsByField update by sqlTablesInfo (F.' . __FUNCTION__ . ':' . __LINE__ . '): '."\n";}
 		foreach ($typeSpecialsByField as $kFieldID => $vType) {
-if(V::get('DBG_TS', 0, $_GET) > 0){			echo "loop: {$kFieldID}\n";}
+			if(V::get('DBG_TS', 0, $_GET) > 0){			echo "loop: {$kFieldID}\n";}
 			$vType->fldAliasList = array();// [tblID][fldID] = fldName
 			$vType->tblAliasList = array();
 			foreach ($vType->param_out->values as $kName => $vZasobID) {
-if(V::get('DBG_TS', 0, $_GET) > 0){				echo "\t value: {$kName}=>{$vZasobID} (" . (array_key_exists($vZasobID, $_SESSION['Typespecial_Cache']['sqlTablesInfo'])) . ") \n";}
+				if(V::get('DBG_TS', 0, $_GET) > 0){				echo "\t value: {$kName}=>{$vZasobID} (" . (array_key_exists($vZasobID, $_SESSION['Typespecial_Cache']['sqlTablesInfo'])) . ") \n";}
 				if (array_key_exists($vZasobID, $_SESSION['Typespecial_Cache']['sqlTablesInfo'])) {
 					$vTbl = $_SESSION['Typespecial_Cache']['sqlTablesInfo'][$vZasobID];
-if(V::get('DBG_TS', 0, $_GET) > 0){					echo "\t\t tbl({$vTbl->tbl_id}:{$vTbl->tbl_name}), db({$vTbl->db_id}) (info: " . '<b style="display:none">' . json_encode($vTbl) . '</b>' . ") \n";}
+					if(V::get('DBG_TS', 0, $_GET) > 0){					echo "\t\t tbl({$vTbl->tbl_id}:{$vTbl->tbl_name}), db({$vTbl->db_id}) (info: " . '<b style="display:none">' . json_encode($vTbl) . '</b>' . ") \n";}
 					$vType->fldAliasList[$vTbl->tbl_id][$vZasobID] = $aliasesMap[$vZasobID];
 					$vType->tblAliasList[$vTbl->tbl_id] = $vTbl->tbl_name;
 				}
@@ -353,7 +354,7 @@ if(V::get('DBG_TS', 0, $_GET) > 0){					echo "\t\t tbl({$vTbl->tbl_id}:{$vTbl->t
 						$vZasobID = $vFltr->ALIAS_ID;
 						if (array_key_exists($vZasobID, $_SESSION['Typespecial_Cache']['sqlTablesInfo'])) {
 							$vTbl = $_SESSION['Typespecial_Cache']['sqlTablesInfo'][$vZasobID];
-if(V::get('DBG_TS', 0, $_GET) > 0){					echo "\t\t filters tbl({$vTbl->tbl_id}:{$vTbl->tbl_name}), db({$vTbl->db_id}) (info: " . '<b style="display:none">' . json_encode($vTbl) . '</b>' . ") \n";}
+							if(V::get('DBG_TS', 0, $_GET) > 0){					echo "\t\t filters tbl({$vTbl->tbl_id}:{$vTbl->tbl_name}), db({$vTbl->db_id}) (info: " . '<b style="display:none">' . json_encode($vTbl) . '</b>' . ") \n";}
 							if (!empty($aliasesMap[$vZasobID])) {
 								$vType->fldAliasList[$vTbl->tbl_id][$vZasobID] = $aliasesMap[$vZasobID];
 							}
@@ -363,13 +364,13 @@ if(V::get('DBG_TS', 0, $_GET) > 0){					echo "\t\t filters tbl({$vTbl->tbl_id}:{
 				}
 			}
 		}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'</pre>';}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:300px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecialsByField-2 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecialsByField);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:300px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecialsByField-2 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecialsByField);echo'</pre>';}
 
 		foreach ($typeSpecialsByField as $kFieldID => $vType) {
 			$vType->buildSqlQuery();
 		}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:300px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecialsByField-3 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecialsByField);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:300px;overflow:auto;border:1px solid orange;text-align:left;">typeSpecialsByField-3 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecialsByField);echo'</pre>';}
 
 		foreach ($typeSpecialsByField as $kFieldID => $vType) {
 			$vType->saveCache();
@@ -529,12 +530,7 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'</pre>';}
 
 	public function getFieldName() {
 		if (empty($this->_fldName)) {
-			$db = DB::getDB();
-			$sql = "select z.`DESC` from `CRM_LISTA_ZASOBOW` as z where z.`ID`='{$this->fldID}' ";
-			$res = $db->query($sql);
-			if ($r = $db->fetch($res)) {
-				$this->_fldName = $r->DESC;
-			}
+			$this->_fldName = DB::getPDO()->fetchValue("select z.`DESC` from `CRM_LISTA_ZASOBOW` as z where z.`ID`='{$this->fldID}' ");
 		}
 		return $this->_fldName;
 	}
@@ -883,7 +879,6 @@ jQuery('#typeahead-{$fName}').typeahead({
 
 	public function _getValues($query) {
 		$rows = array();
-		$db = DB::getDB();// TODO: get from DB by zasoby ID
 		DBG::log(['msg'=>"session", $_SESSION['Typespecial_Cache']['sqlTablesInfo']]);
 		DBG::log(['msg'=>"this", $this]);
 		$query = trim($query);
@@ -1101,11 +1096,10 @@ jQuery('#typeahead-{$fName}').typeahead({
 
 	public function getEditSelectedValuesByIds($tblId, $rowId, $fieldName, $fieldValue = '') {
 		$rows = array();
-		$db = DB::getDB();// TODO: get from DB by zasoby ID
-if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">args (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('tblId'=>$tblId, 'rowId'=>$rowId, 'fieldName'=>$fieldName, 'fieldValue'=>$fieldValue));echo'</pre>';}// TODO: RMME
-if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sqlTablesInfo (tblId:'.$tblId.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SESSION['Typespecial_Cache']['sqlTablesInfo']);echo'</pre>';}// TODO: RMME
-if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">this->tblAliasList (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->tblAliasList);echo'</pre>';}// TODO: RMME
-if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">this (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this);echo'</pre>';}// TODO: RMME
+		if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">args (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('tblId'=>$tblId, 'rowId'=>$rowId, 'fieldName'=>$fieldName, 'fieldValue'=>$fieldValue));echo'</pre>';}// TODO: RMME
+		if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sqlTablesInfo (tblId:'.$tblId.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SESSION['Typespecial_Cache']['sqlTablesInfo']);echo'</pre>';}// TODO: RMME
+		if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">this->tblAliasList (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->tblAliasList);echo'</pre>';}// TODO: RMME
+		if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">this (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this);echo'</pre>';}// TODO: RMME
 
 		$retFldName = '';
 		$sqlWhereAdd = array();
@@ -1174,23 +1168,23 @@ if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:au
 				{$sqlWhereAdd}
 			{$sqlLimit}
 		";
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
-		$res = $db->query($sql);
-		while ($r = $db->fetch($res)) {
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
+		foreach (DB::getPDO()->fetchAll($sql) as $row) {
+			$r = (object)$row;
 			$rows[] = $r;
 		}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">rows (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">rows (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
 
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">param_out (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->param_out);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">param_out (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->param_out);echo'</pre>';}
 		{// convert param_out
 			$format = $this->param_out->format;
 			foreach ($this->param_out->values as $kFldName => $vFldID) {
 				$format = str_replace("{{$kFldName}}", "{f_{$vFldID}}", $format);
 			}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">format (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($format);echo'</pre>';}
+			if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">format (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($format);echo'</pre>';}
 		}
 
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">retFldName:'.$retFldName.' (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">retFldName:'.$retFldName.' (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
 		$rowsOut = array();
 		foreach ($rows as $r) {
 			$rowOut = $format;
@@ -1209,10 +1203,9 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
 
 	public function getValuesByIds($tblId, $ids) {
 		$rows = array();
-		$db = DB::getDB();// TODO: get from DB by zasoby ID
-if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sqlTablesInfo (tblId:'.$tblId.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SESSION['Typespecial_Cache']['sqlTablesInfo']);echo'</pre>';}// TODO: RMME
-if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">this->tblAliasList (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->tblAliasList);echo'</pre>';}// TODO: RMME
-if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">this (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this);echo'</pre>';}// TODO: RMME
+		if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sqlTablesInfo (tblId:'.$tblId.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_SESSION['Typespecial_Cache']['sqlTablesInfo']);echo'</pre>';}// TODO: RMME
+		if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">this->tblAliasList (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->tblAliasList);echo'</pre>';}// TODO: RMME
+		if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">this (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this);echo'</pre>';}// TODO: RMME
 
 		$sqlWhereAdd = array();
 		$tblFound = null;
@@ -1240,20 +1233,20 @@ if(V::get('DBG_TS', 0, $_GET) > 1){echo'<pre style="max-height:200px;overflow:au
 				{$sqlWhereAdd}
 			{$sqlLimit}
 		";
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
-		$res = $db->query($sql);
-		while ($r = $db->fetch($res)) {
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
+		foreach (DB::getPDO()->fetchAll($sql) as $row) {
+			$r = (object)$row;
 			$rows[$r->ID][] = $r;
 		}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">rows (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">rows (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
 
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">param_out (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->param_out);echo'</pre>';}
+		if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">param_out (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->param_out);echo'</pre>';}
 		{// convert param_out
 			$format = $this->param_out->format;
 			foreach ($this->param_out->values as $kFldName => $vFldID) {
 				$format = str_replace("{{$kFldName}}", "{f_{$vFldID}}", $format);
 			}
-if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">format (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($format);echo'</pre>';}
+			if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">format (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($format);echo'</pre>';}
 		}
 
 		$rowsOut = array();
@@ -1355,8 +1348,8 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
 		if (empty($itemsJson)) return null;
 		$retData->items = $itemsJson;
 
-		$db = DB::getDB();
-		$sql = "select z.`ID`
+		$sql = "
+			select z.`ID`
 				, z.`DESC` as fld_name
 				, tbl.`ID` as tbl_id
 				, tbl.`DESC` as tbl_name
@@ -1369,8 +1362,8 @@ if(V::get('DBG_TS', 0, $_GET) > 0){echo'<pre style="max-height:200px;overflow:au
 				and tbl.`TYPE`='TABELA'
 		";
 		if(V::get('DBG_TS', 0, $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid orange;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
-		$res = $db->query($sql);
-		if ($r = $db->fetch($res)) {
+		$r = (object)DB::getPDO()->fetchFirst($sql);
+		if ($r) {
 			$retData->fld_name = $r->fld_name;
 			$retData->tbl_id = $r->tbl_id;
 			$retData->tbl_name = $r->tbl_name;