|
|
|
@ -371,23 +371,48 @@ export class ColumnsService {
|
|
|
|
|
); |
|
|
|
|
if (colBody.cdf) { |
|
|
|
|
if (colBody.uidt === UITypes.SingleSelect) { |
|
|
|
|
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${colBody.cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for (const cdf of colBody.cdf.split(',')) { |
|
|
|
|
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { |
|
|
|
|
try { |
|
|
|
|
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${cdf}' is not a select option.`, |
|
|
|
|
`Default value '${colBody.cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, ''); |
|
|
|
|
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${colBody.cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
for (const cdf of colBody.cdf.split(',')) { |
|
|
|
|
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, ''); |
|
|
|
|
for (const cdf of colBody.cdf.split(',')) { |
|
|
|
|
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// handle single quote for default value
|
|
|
|
|
if (driverType === 'mysql' || driverType === 'mysql2') { |
|
|
|
|
if ( |
|
|
|
|
driverType === 'mysql' || |
|
|
|
|
driverType === 'mysql2' || |
|
|
|
|
driverType === 'pg' || |
|
|
|
|
driverType === 'sqlite3' |
|
|
|
|
) { |
|
|
|
|
colBody.cdf = colBody.cdf.replace(/'/g, "'"); |
|
|
|
|
} else { |
|
|
|
|
colBody.cdf = colBody.cdf.replace(/'/g, "''"); |
|
|
|
@ -1142,23 +1167,48 @@ export class ColumnsService {
|
|
|
|
|
// Handle default values
|
|
|
|
|
if (colBody.cdf) { |
|
|
|
|
if (colBody.uidt === UITypes.SingleSelect) { |
|
|
|
|
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${colBody.cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for (const cdf of colBody.cdf.split(',')) { |
|
|
|
|
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { |
|
|
|
|
try { |
|
|
|
|
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${colBody.cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, ''); |
|
|
|
|
if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${cdf}' is not a select option.`, |
|
|
|
|
`Default value '${colBody.cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
for (const cdf of colBody.cdf.split(',')) { |
|
|
|
|
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, ''); |
|
|
|
|
for (const cdf of colBody.cdf.split(',')) { |
|
|
|
|
if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { |
|
|
|
|
NcError.badRequest( |
|
|
|
|
`Default value '${cdf}' is not a select option.`, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// handle single quote for default value
|
|
|
|
|
if (driverType === 'mysql' || driverType === 'mysql2') { |
|
|
|
|
if ( |
|
|
|
|
driverType === 'mysql' || |
|
|
|
|
driverType === 'mysql2' || |
|
|
|
|
driverType === 'pg' || |
|
|
|
|
driverType === 'sqlite3' |
|
|
|
|
) { |
|
|
|
|
colBody.cdf = colBody.cdf.replace(/'/g, "'"); |
|
|
|
|
} else { |
|
|
|
|
colBody.cdf = colBody.cdf.replace(/'/g, "''"); |
|
|
|
|