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, functions: false,
schedulers: false, schedulers: false,
// Settings // Settings
elementsWrapper: '',
stringsWrapper: '"',
tableAdd: false, tableAdd: false,
viewAdd: false, viewAdd: false,
triggerAdd: false, triggerAdd: false,

View File

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

View File

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

View File

@ -4,6 +4,7 @@ export const TEXT = [
'CHARACTER', 'CHARACTER',
'CHARACTER VARYING' 'CHARACTER VARYING'
]; ];
export const LONG_TEXT = [ export const LONG_TEXT = [
'TEXT', 'TEXT',
'MEDIUMTEXT', 'MEDIUMTEXT',
@ -50,6 +51,7 @@ export const BOOLEAN = [
]; ];
export const DATE = ['DATE']; export const DATE = ['DATE'];
export const TIME = [ export const TIME = [
'TIME', 'TIME',
'TIME WITH TIME ZONE' '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) { _getTypeInfo (type) {
return dataTypes return dataTypes
.reduce((acc, group) => [...acc, ...group.types], []) .reduce((acc, group) => [...acc, ...group.types], [])
@ -1065,7 +1085,7 @@ export class PostgreSQLClient extends AntaresCore {
const typeInfo = this._getTypeInfo(field.type); const typeInfo = this._getTypeInfo(field.type);
const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false; 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.type.toUpperCase()}${length ? `(${length})` : ''}
${field.unsigned ? 'UNSIGNED' : ''} ${field.unsigned ? 'UNSIGNED' : ''}
${field.zerofill ? 'ZEROFILL' : ''} ${field.zerofill ? 'ZEROFILL' : ''}

View File

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

View File

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