Skip to content

Commit

Permalink
fix(PostgreSQL): issue with uppercase characters in table field names
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Oct 19, 2021
1 parent ea65d8e commit aef17be
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/common/customizations/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
functions: false,
schedulers: false,
// Settings
elementsWrapper: '',
stringsWrapper: '"',
tableAdd: false,
viewAdd: false,
triggerAdd: false,
Expand Down
2 changes: 2 additions & 0 deletions src/common/customizations/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = {
functions: true,
schedulers: true,
// Settings
elementsWrapper: '',
stringsWrapper: '"',
tableAdd: true,
viewAdd: true,
triggerAdd: true,
Expand Down
2 changes: 2 additions & 0 deletions src/common/customizations/postgresql.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = {
routines: true,
functions: true,
// Settings
elementsWrapper: '"',
stringsWrapper: '\'',
tableAdd: true,
viewAdd: true,
triggerAdd: true,
Expand Down
2 changes: 2 additions & 0 deletions src/common/fieldTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const TEXT = [
'CHARACTER',
'CHARACTER VARYING'
];

export const LONG_TEXT = [
'TEXT',
'MEDIUMTEXT',
Expand Down Expand Up @@ -50,6 +51,7 @@ export const BOOLEAN = [
];

export const DATE = ['DATE'];

export const TIME = [
'TIME',
'TIME WITH TIME ZONE'
Expand Down
22 changes: 21 additions & 1 deletion src/main/libs/clients/PostgreSQLClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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], [])
Expand Down Expand Up @@ -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' : ''}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/WorkspaceTabTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<WorkspaceTabTableFilters
v-if="isSearch"
:fields="fields"
:conn-client="connection.client"
@filter="updateFilters"
@filter-change="onFilterChange"
/>
Expand Down
35 changes: 22 additions & 13 deletions src/renderer/components/WorkspaceTabTableFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -83,6 +87,11 @@ export default {
]
};
},
computed: {
customizations () {
return customizations[this.connClient];
}
},
created () {
this.addRow();
},
Expand All @@ -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}`;
}
}
};
Expand Down

0 comments on commit aef17be

Please sign in to comment.