Browse Source

fix: large characters in table create

pull/2646/head
Wing-Kam Wong 2 years ago
parent
commit
e2447fc081
  1. 14
      packages/nc-gui/components/utils/DlgTableCreate.vue
  2. 14
      packages/nocodb/src/lib/meta/api/tableApis.ts

14
packages/nc-gui/components/utils/DlgTableCreate.vue

@ -23,7 +23,7 @@
persistent-hint persistent-hint
dense dense
hide-details1 hide-details1
:rules="[validateTableName, validateDuplicateAlias]" :rules="[validateTableName, validateDuplicateAlias, validateLength]"
:hint="$t('msg.info.enterTableName')" :hint="$t('msg.info.enterTableName')"
class="mt-4 caption nc-table-name" class="mt-4 caption nc-table-name"
/> />
@ -231,6 +231,18 @@ export default {
(this.tables || []).every(t => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name' (this.tables || []).every(t => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name'
); );
}, },
validateLength(v) {
let tableNameLengthLimit = 255;
const sqlClientType = this.$store.getters['project/GtrClientType'];
if (sqlClientType === 'mysql2' || sqlClientType === 'mysql') {
tableNameLengthLimit = 64;
} else if (sqlClientType === 'pg') {
tableNameLengthLimit = 63;
} else if (sqlClientType === 'mssql') {
tableNameLengthLimit = 128;
}
return v.length <= tableNameLengthLimit || `Table name exceeds ${tableNameLengthLimit} characters`;
},
onCreateBtnClick() { onCreateBtnClick() {
this.$emit('create', { this.$emit('create', {
...this.table, ...this.table,

14
packages/nocodb/src/lib/meta/api/tableApis.ts

@ -141,6 +141,20 @@ export async function tableCreate(req: Request<any, any, TableReqType>, res) {
const sqlMgr = await ProjectMgrv2.getSqlMgr(project); const sqlMgr = await ProjectMgrv2.getSqlMgr(project);
const sqlClient = NcConnectionMgrv2.getSqlClient(base); const sqlClient = NcConnectionMgrv2.getSqlClient(base);
let tableNameLengthLimit = 255;
const sqlClientType = sqlClient.clientType;
if (sqlClientType === 'mysql2' || sqlClientType === 'mysql') {
tableNameLengthLimit = 64;
} else if (sqlClientType === 'pg') {
tableNameLengthLimit = 63;
} else if (sqlClientType === 'mssql') {
tableNameLengthLimit = 128;
}
if (req.body.table_name.length > tableNameLengthLimit) {
NcError.badRequest(`Table name exceeds ${tableNameLengthLimit} characters`);
}
req.body.columns = req.body.columns?.map((c) => ({ req.body.columns = req.body.columns?.map((c) => ({
...getColumnPropsFromUIDT(c as any, base), ...getColumnPropsFromUIDT(c as any, base),
cn: c.column_name, cn: c.column_name,

Loading…
Cancel
Save