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(() => {
updateCdfValue(vModel.value?.cdf ? vModel.value.cdf.replace(/^'/, '').replace(/'$/, '') : null)
updateCdfValue(vModel.value?.cdf ? vModel.value.cdf : null)
})
</script>

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

@ -101,9 +101,9 @@ onMounted(() => {
}
if (vModel.value.cdf) {
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped
if (!isMysql.value && !isPg.value) {
vModel.value.cdf = vModel.value.cdf.replace(/''/g, "'")
const fndDefaultOption = options.value.find((el) => el.title === vModel.value.cdf)
if (!fndDefaultOption) {
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 +=
n.dtxp && n.dt !== 'text' ? `(${this.genRaw(n.dtxp)})` : '';
addNewColumnQuery += n.cdf
? ` DEFAULT ${this.sanitiseDefaultValue(n.cdf)}`
? ` DEFAULT ${this.genValue(n.cdf)}`
: !n.rqd
? ' '
: ` DEFAULT ''`;
@ -2122,7 +2122,7 @@ class SqliteClient extends KnexClient {
shouldSanitize,
);
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` : ' ';
} else if (change === 1) {
shouldSanitize = true;
@ -2133,7 +2133,7 @@ class SqliteClient extends KnexClient {
);
query += n.dtxp && n.dt !== 'text' ? `(${this.genRaw(n.dtxp)})` : '';
query += n.cdf
? ` DEFAULT ${this.sanitiseDefaultValue(n.cdf)}`
? ` DEFAULT ${this.genValue(n.cdf)}`
: !n.rqd
? ' '
: ` DEFAULT ''`;

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

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

Loading…
Cancel
Save