diff --git a/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts index 61cfa2f934..50b559ab6f 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts @@ -1,5 +1,5 @@ import UITypes from '../UITypes'; -import { IDType } from './index'; +import { IDType } from '~/lib'; const dbTypes = [ 'int', @@ -630,17 +630,13 @@ export class MysqlUi { static colPropUNDisabled(col) { // console.log(col); - if ( + return !( col.dt === 'int' || col.dt === 'tinyint' || col.dt === 'smallint' || col.dt === 'mediumint' || col.dt === 'bigint' - ) { - return false; - } else { - return true; - } + ); } static onCheckboxChangeAI(col) { diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 03d9be0edc..ecabddcbe1 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -4479,6 +4479,8 @@ class BaseModelSqlv2 { ); } await this.validateOptions(column, data); + // Validates the constraints on the data based on the column definitions + this.validateConstraints(column, data); // skip validation if `validate` is undefined or false if (!column?.meta?.validate || !column?.validate) continue; @@ -4514,6 +4516,24 @@ class BaseModelSqlv2 { return true; } + /* + * Utility method to validate database constraints + */ + protected validateConstraints( + column: Column, + data: Record, + ) { + if ( + typeof data[column.title] === 'string' && + typeof column.dtxp === 'number' && + column.dtxp < data[column.title]?.length + ) { + NcError.badRequest( + `Column "${column.title}" value exceeds the maximum length of ${column.dtxp}`, + ); + } + } + // method for validating otpions if column is single/multi select protected async validateOptions( column: Column, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 003f9be720..ebfca3caa0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28424,4 +28424,4 @@ packages: name: xlsx version: 0.19.3 engines: {node: '>=0.8'} - hasBin: true + hasBin: true \ No newline at end of file