|
|
@@ -28,6 +28,7 @@ class Data_Source {
|
|
|
private $_fieldGroupWrite = null;
|
|
|
private $_fieldGroupRead = null;
|
|
|
private $_showMsgsSpecialFilter = false;
|
|
|
+ var $_primaryKey = null; // TODO: set after getFieldTypes to field name - HOW TO handle tables with non unique keys (group by in fetch data in TableAjax)
|
|
|
|
|
|
function __construct($db = null) {
|
|
|
$this->_idDatabase = ($db) ? $db : null;
|
|
|
@@ -68,15 +69,31 @@ class Data_Source {
|
|
|
|
|
|
public function getFieldTypes() {
|
|
|
$fieldTypes = array();
|
|
|
- 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']
|
|
|
+
|
|
|
+ $storage = DB::getStorage($this->_idDatabase);
|
|
|
+ $tableStruct = $storage->getTableStruct($this->_tbl);
|
|
|
+ DBG::log($tableStruct, 'array', "DBG:TEST:\$tableStruct");
|
|
|
+ $fieldTypes = array_map(function ($field) {
|
|
|
+ return [
|
|
|
+ 'type' => $field['raw_storage_type'],
|
|
|
+ 'null' => $field['is_nullable'] ? true : false,
|
|
|
+ 'default' => $field['default'],
|
|
|
];
|
|
|
- }
|
|
|
+ }, $tableStruct);
|
|
|
+
|
|
|
+ // TODO: find unique/primary keys in $tableStruct
|
|
|
+
|
|
|
+ // $struct = DB::getPDO($this->_idDatabase)->fetchAll(" show fields from `{$this->_tbl}` ");
|
|
|
+ // DBG::log($struct, 'array', "DBG:\$struct by `show fields from`");
|
|
|
+ // foreach ($struct 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;
|
|
|
}
|
|
|
@@ -1013,7 +1030,7 @@ class Data_Source {
|
|
|
}
|
|
|
|
|
|
public function getPrimaryKeyField() {
|
|
|
- return 'ID';// TODO: read from struct - jest funkcja w Mysql.php my Psql.php
|
|
|
+ return $this->_primaryKey ? $this->_primaryKey : 'ID';// TODO: read from struct - jest funkcja w Mysql.php my Psql.php
|
|
|
}
|
|
|
|
|
|
}
|