fix(PostgreSQL): issue with uppercase characters in table field names

This commit is contained in:
Fabio Di Stasio 2021-10-19 17:42:31 +02:00
parent ea65d8eee7
commit aef17be36c
7 changed files with 52 additions and 14 deletions

View File

@ -22,6 +22,8 @@ module.exports = {
functions: false,
schedulers: false,
// Settings
elementsWrapper: '',
stringsWrapper: '"',
tableAdd: false,
viewAdd: false,
triggerAdd: false,

View File

@ -21,6 +21,8 @@ module.exports = {
functions: true,
schedulers: true,
// Settings
elementsWrapper: '',
stringsWrapper: '"',
tableAdd: true,
viewAdd: true,
triggerAdd: true,

View File

@ -18,6 +18,8 @@ module.exports = {
routines: true,
functions: true,
// Settings
elementsWrapper: '"',
stringsWrapper: '\'',
tableAdd: true,
viewAdd: true,
triggerAdd: true,

View File

@ -4,6 +4,7 @@ export const TEXT = [
'CHARACTER',
'CHARACTER VARYING'
];
export const LONG_TEXT = [
'TEXT',
'MEDIUMTEXT',
@ -50,6 +51,7 @@ export const BOOLEAN = [
];
export const DATE = ['DATE'];
export const TIME = [
'TIME',
'TIME WITH TIME ZONE'

View File

@ -36,6 +36,26 @@ export class PostgreSQLClient extends AntaresCore {
};
}
_reducer (acc, curr) {
const type = typeof curr;
switch (type) {
case 'number':
case 'string':
return [...acc, curr];
case 'object':
if (Array.isArray(curr))
return [...acc, ...curr];
else {
const clausoles = [];
for (const key in curr)
clausoles.push(`"${key}" ${curr[key]}`);
return clausoles;
}
}
}
_getTypeInfo (type) {
return dataTypes
.reduce((acc, group) => [...acc, ...group.types], [])
@ -1065,7 +1085,7 @@ export class PostgreSQLClient extends AntaresCore {
const typeInfo = this._getTypeInfo(field.type);
const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false;
newColumns.push(`${field.name}
newColumns.push(`"${field.name}"
${field.type.toUpperCase()}${length ? `(${length})` : ''}
${field.unsigned ? 'UNSIGNED' : ''}
${field.zerofill ? 'ZEROFILL' : ''}

View File

@ -131,6 +131,7 @@
<WorkspaceTabTableFilters
v-if="isSearch"
:fields="fields"
:conn-client="connection.client"
@filter="updateFilters"
@filter-change="onFilterChange"
/>

View File

@ -71,9 +71,13 @@
</template>
<script>
import customizations from 'common/customizations';
import { NUMBER, FLOAT } from 'common/fieldTypes';
export default {
props: {
fields: Array
fields: Array,
connClient: String
},
data () {
return {
@ -83,6 +87,11 @@ export default {
]
};
},
computed: {
customizations () {
return customizations[this.connClient];
}
},
created () {
this.addRow();
},
@ -101,40 +110,40 @@ export default {
},
createClausole (filter) {
const field = this.fields.find(field => field.name === filter.field);
const isNumeric = field.type.match(/INT|FLOAT|DECIMAL/);
let value = null;
const isNumeric = [...NUMBER, ...FLOAT].includes(field.type);
const { elementsWrapper: ew, stringsWrapper: sw } = this.customizations;
let value;
switch (filter.op) {
case '=':
case '!=':
value = isNumeric ? filter.value : '"' + filter.value + '"';
value = isNumeric ? filter.value : `${sw}${filter.value}${sw}`;
break;
case 'BETWEEN':
value = isNumeric ? filter.value : '"' + filter.value + '"';
value = isNumeric ? filter.value : `${sw}${filter.value}${sw}`;
value += ' AND ';
value += isNumeric ? filter.value2 : '"' + filter.value2 + '"';
console.log(value);
value += isNumeric ? filter.value2 : `${sw}${filter.value2}${sw}`;
break;
case 'IN':
case 'NOT IN':
value = filter.value.split(',').map(val => {
val = val.trim();
return isNumeric ? val : '"' + val + '"';
return isNumeric ? val : `${sw}${val}${sw}`;
}).join(',');
value = '(' + filter.value + ')';
value = `(${filter.value})`;
break;
case 'IS NULL':
case 'IS NOT NULL':
value = '';
break;
default:
value = '"' + filter.value + '"';
value = `${sw}${filter.value}${sw}`;
}
if (isNumeric && value.length === 0)
value = '""';
if (isNumeric && !value.length && !['IS NULL', 'IS NOT NULL'].includes(filter.op))
value = `${sw}${sw}`;
return `${filter.field} ${filter.op} ${value}`;
return `${ew}${filter.field}${ew} ${filter.op} ${value}`;
}
}
};