|
|
@@ -154,19 +154,24 @@ class InstanceConfig {
|
|
|
]));
|
|
|
}
|
|
|
|
|
|
- static function generateSqlWhereFromFieldsWithRestrictions($fieldsRestrictions, $sqlTablePrefix = 't') { // @param $fieldsRestrictions Array [ fieldName => xsdRestrictions | Null ]
|
|
|
+ static function generateSqlWhereFromFieldsWithRestrictions($fieldsRestrictions, $sqlTablePrefix = 't', $charset = 'utf8') { // @param $fieldsRestrictions Array [ fieldName => xsdRestrictions | Null ]
|
|
|
// TODO: add @param $acl to check if field is local, and if not then generate remote query (join)
|
|
|
if (empty($fieldsRestrictions)) return '';
|
|
|
$fieldsWithRestrictions = array_filter($fieldsRestrictions, ['V', 'filterNotEmpty']);
|
|
|
if (empty($fieldsWithRestrictions)) return '';
|
|
|
|
|
|
return array_reduce(
|
|
|
- array_map(function ($fieldName, $xsdRestriction) use ($sqlTablePrefix) {
|
|
|
+ array_map(function ($fieldName, $xsdRestriction) use ($sqlTablePrefix, $charset) {
|
|
|
$sqlRestrictions = [];
|
|
|
if (false !== strpos($fieldName, ':')) return $sqlRestrictions; // SKIP ref fields - TODO: generate remote query, require $acl
|
|
|
if (!empty($xsdRestriction)) {
|
|
|
if (!empty($xsdRestriction['enumeration'])) {
|
|
|
- $sqlRestrictions[] = "{$sqlTablePrefix}.`{$fieldName}` in (" . implode(",", array_map([DB::getPDO(), 'quote'], array_keys($xsdRestriction['enumeration']))) . ")";
|
|
|
+ // $sqlRestrictions[] = "{$sqlTablePrefix}.`{$fieldName}` in (" . implode(",", array_map([DB::getPDO(), 'quote'], array_keys($xsdRestriction['enumeration']))) . ")";
|
|
|
+ $sqlRestrictions[] = "{$sqlTablePrefix}.`{$fieldName}` in (" . implode(",", array_map(function ($option) use ($charset) {
|
|
|
+ return ($charset && $charset !== 'utf8')
|
|
|
+ ? "CONVERT(" . DB::getPDO()->quote($option) . " using {$charset})"
|
|
|
+ : DB::getPDO()->quote($option);
|
|
|
+ }, array_keys($xsdRestriction['enumeration']))) . ")";
|
|
|
}
|
|
|
}
|
|
|
return $sqlRestrictions;
|
|
|
@@ -247,10 +252,12 @@ class InstanceConfig {
|
|
|
return $ret;
|
|
|
}, []);
|
|
|
$sqlTablePrefix = "instance_{$idInstance}";
|
|
|
- $sqlListWhere = self::generateSqlWhereFromFieldsWithRestrictions($fieldsWithRestrictions, $sqlTablePrefix);
|
|
|
+ $appInfo = (!empty($item['appInfo'])) ? @json_decode($item['appInfo'], $assoc = true) : null;
|
|
|
+ $charset = (!empty($appInfo) && !empty($appInfo['table_structure']['@charset'])) ? $appInfo['table_structure']['@charset'] : null;
|
|
|
+ $sqlListWhere = self::generateSqlWhereFromFieldsWithRestrictions($fieldsWithRestrictions, $sqlTablePrefix, $charset);
|
|
|
$sqlWhere = (!empty($sqlListWhere)) ? implode("\n\t and ", $sqlListWhere) : "1=1";
|
|
|
$rootTableName = $item['_rootTableName'];
|
|
|
- $primaryKey = 'ID'; // TODO: primaryKeyField into SystemObject structure // TODO: is in struct, read from `primaryKey`? field
|
|
|
+ $primaryKey = V::get('primaryKey', 'ID', $item);
|
|
|
return implode("\n\t", [
|
|
|
"select {$primaryKey}",
|
|
|
"from `{$rootTableName}` `{$sqlTablePrefix}`",
|