Browse Source

fix sqlite single quote in cdf

pull/6323/head
DarkPhoenix2704 1 year ago
parent
commit
c4e446e792
  1. 44
      packages/nc-gui/components/smartsheet/column/DefaultValue.vue
  2. 7
      packages/nc-gui/components/smartsheet/column/SelectOptions.vue

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

@ -1,31 +1,34 @@
<script lang="ts" setup>
import { UITypes } from 'nocodb-sdk'
import MdiPlusIcon from '~icons/mdi/plus-circle-outline'
const props = defineProps<{
value: any
}>()
const emit = defineEmits(['update:value'])
const enableDefaultOption = ref(false)
const column = inject(ColumnInj)
provide(EditColumnInj, ref(true))
const vModel = useVModel(props, 'value', emit)
const rowRef = ref({
row: {},
oldRow: {},
rowMeta: {
isUpdatedFromCopyNPaste: [column?.value.title],
isUpdatedFromCopyNPaste: [vModel?.value.title],
},
})
const vModel = useVModel(props, 'value', emit)
const cdfValue = computed({
get: () => {
if (column?.value.uidt === UITypes.MultiSelect || column?.value.uidt === UITypes.SingleSelect) {
return vModel.value.cdf?.replaceAll("'", '')
if (vModel.value.uidt === UITypes.MultiSelect || vModel.value.uidt === UITypes.SingleSelect) {
return (vModel.value.cdf ?? '').replaceAll("'", '')
} else if (
vModel.value.uidt === UITypes.SingleLineText ||
vModel.value.uidt === UITypes.LongText ||
vModel.value.uidt === UITypes.Email ||
vModel.value.uidt === UITypes.URL ||
vModel.value.uidt === UITypes.JSON
) {
return (vModel.value.cdf ?? '').replace(/^'/, '').replace(/'$/, '')
}
return vModel.value.cdf
},
@ -38,25 +41,10 @@ useProvideSmartsheetRowStore(vModel, rowRef)
</script>
<template>
<span v-if="!enableDefaultOption && !vModel.cdf" class="cursor-pointer" @click="enableDefaultOption = !enableDefaultOption">
<MdiPlusIcon class="text-gray-600" />
Set Default Value
</span>
<div v-else>
<p class="mt-3 text-gray-900">Default Value</p>
<div class="flex flex-row gap-2">
<div class="border-1 w-full px-1 my-[-4px] border-gray-300 rounded-md">
<LazySmartsheetCell :column="vModel" :model-value="cdfValue" :edit-enabled="true" />
</div>
<MdiDeleteOutline
class="w-6 h-6 text-red-500 cursor-pointer"
@click="
() => {
vModel.cdf = null
enableDefaultOption = false
}
"
/>
<p class="mt-3 text-gray-900">Default Value</p>
<div class="flex flex-row gap-2">
<div class="border-1 w-full px-1 my-[-4px] border-gray-300 rounded-md">
<LazySmartsheetCell :column="vModel" :model-value="cdfValue" :edit-enabled="true" />
</div>
</div>
</template>

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

@ -101,11 +101,6 @@ onMounted(() => {
}
if (vModel.value.cdf) {
// Postgres returns default value wrapped with single quotes & casted with type so we have to get value between single quotes to keep it unified for all databases
if (isPg.value) {
vModel.value.cdf = vModel.value.cdf.substring(vModel.value.cdf.indexOf(`'`) + 1, vModel.value.cdf.lastIndexOf(`'`))
}
// Mysql escapes single quotes with backslash so we keep quotes but others have to unescaped
if (!isMysql.value) {
vModel.value.cdf = vModel.value.cdf.replace(/''/g, "'")
@ -187,7 +182,7 @@ watch(inputs, () => {
// Removes the Select Option from cdf if the option is removed
watch(vModel.value, (next) => {
const cdfs = (next.cdf ?? '').replaceAll("'", '').split(',')
const cdfs = (next.cdf ?? '').split(',')
const values = (next.colOptions.options ?? []).map((col) => {
return col.title.replaceAll("'", '')
})

Loading…
Cancel
Save