Browse Source

fix: improve default value quote handling

pull/6584/head
mertmit 1 year ago
parent
commit
f6d1f2f56a
  1. 2
      packages/nc-gui/components/smartsheet/column/DefaultValue.vue
  2. 6
      packages/nc-gui/components/smartsheet/column/SelectOptions.vue
  3. 6
      packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts
  4. 6
      packages/nocodb/src/services/columns.service.ts

2
packages/nc-gui/components/smartsheet/column/DefaultValue.vue

@ -30,7 +30,7 @@ const updateCdfValue = (cdf: string | null) => {
} }
onMounted(() => { onMounted(() => {
updateCdfValue(vModel.value?.cdf ? vModel.value.cdf.replace(/^'/, '').replace(/'$/, '') : null) updateCdfValue(vModel.value?.cdf ? vModel.value.cdf : null)
}) })
</script> </script>

6
packages/nc-gui/components/smartsheet/column/SelectOptions.vue

@ -101,9 +101,9 @@ onMounted(() => {
} }
if (vModel.value.cdf) { if (vModel.value.cdf) {
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped const fndDefaultOption = options.value.find((el) => el.title === vModel.value.cdf)
if (!isMysql.value && !isPg.value) { if (!fndDefaultOption) {
vModel.value.cdf = vModel.value.cdf.replace(/''/g, "'") vModel.value.cdf = vModel.value.cdf.replace(/^'/, '').replace(/'$/, '')
} }
} }

6
packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts

@ -2090,7 +2090,7 @@ class SqliteClient extends KnexClient {
addNewColumnQuery += addNewColumnQuery +=
n.dtxp && n.dt !== 'text' ? `(${this.genRaw(n.dtxp)})` : ''; n.dtxp && n.dt !== 'text' ? `(${this.genRaw(n.dtxp)})` : '';
addNewColumnQuery += n.cdf addNewColumnQuery += n.cdf
? ` DEFAULT ${this.sanitiseDefaultValue(n.cdf)}` ? ` DEFAULT ${this.genValue(n.cdf)}`
: !n.rqd : !n.rqd
? ' ' ? ' '
: ` DEFAULT ''`; : ` DEFAULT ''`;
@ -2122,7 +2122,7 @@ class SqliteClient extends KnexClient {
shouldSanitize, shouldSanitize,
); );
query += n.dtxp && n.dt !== 'text' ? `(${this.genRaw(n.dtxp)})` : ''; query += n.dtxp && n.dt !== 'text' ? `(${this.genRaw(n.dtxp)})` : '';
query += n.cdf ? ` DEFAULT ${this.sanitiseDefaultValue(n.cdf)}` : ' '; query += n.cdf ? ` DEFAULT ${this.genValue(n.cdf)}` : ' ';
query += n.rqd ? ` NOT NULL` : ' '; query += n.rqd ? ` NOT NULL` : ' ';
} else if (change === 1) { } else if (change === 1) {
shouldSanitize = true; shouldSanitize = true;
@ -2133,7 +2133,7 @@ class SqliteClient extends KnexClient {
); );
query += n.dtxp && n.dt !== 'text' ? `(${this.genRaw(n.dtxp)})` : ''; query += n.dtxp && n.dt !== 'text' ? `(${this.genRaw(n.dtxp)})` : '';
query += n.cdf query += n.cdf
? ` DEFAULT ${this.sanitiseDefaultValue(n.cdf)}` ? ` DEFAULT ${this.genValue(n.cdf)}`
: !n.rqd : !n.rqd
? ' ' ? ' '
: ` DEFAULT ''`; : ` DEFAULT ''`;

6
packages/nocodb/src/services/columns.service.ts

@ -410,7 +410,8 @@ export class ColumnsService {
if ( if (
driverType === 'mysql' || driverType === 'mysql' ||
driverType === 'mysql2' || driverType === 'mysql2' ||
driverType === 'pg' driverType === 'pg' ||
driverType === 'sqlite3'
) { ) {
colBody.cdf = colBody.cdf.replace(/'/g, "'"); colBody.cdf = colBody.cdf.replace(/'/g, "'");
} else { } else {
@ -1205,7 +1206,8 @@ export class ColumnsService {
if ( if (
driverType === 'mysql' || driverType === 'mysql' ||
driverType === 'mysql2' || driverType === 'mysql2' ||
driverType === 'pg' driverType === 'pg' ||
driverType === 'sqlite3'
) { ) {
colBody.cdf = colBody.cdf.replace(/'/g, "'"); colBody.cdf = colBody.cdf.replace(/'/g, "'");
} else { } else {

Loading…
Cancel
Save