fix: truncate long text in query level

This commit is contained in:
DarkPhoenix2704
2026-01-28 13:04:45 +00:00
parent 323e28b453
commit f05f9db15e
2 changed files with 35 additions and 1 deletions

View File

@@ -16,7 +16,8 @@ if (!NC_REFRESH_TOKEN_EXP_IN_DAYS || NC_REFRESH_TOKEN_EXP_IN_DAYS <= 0) {
throw new Error('NC_REFRESH_TOKEN_EXP_IN_DAYS must be a positive number');
}
export const NC_MAX_TEXT_LENGTH = 100000;
export const NC_MAX_TEXT_LENGTH =
+process.env['NC_MAX_TEXT_LENGTH'] || 100000;
export const NC_EMAIL_ASSETS_BASE_URL = 'https://cdn.nocodb.com/emails/v2';

View File

@@ -19,6 +19,7 @@ import {
shouldSkipField,
} from '~/helpers/dbHelpers';
import { sanitize } from '~/helpers/sqlSanitize';
import { NC_MAX_TEXT_LENGTH } from '~/constants';
export const selectObject = (baseModel: IBaseModelSqlV2, logger: Logger) => {
return async ({
@@ -433,6 +434,38 @@ export const selectObject = (baseModel: IBaseModelSqlV2, logger: Logger) => {
]);
break;
}
case UITypes.LongText: {
const colPath = sanitize(
`${alias || baseModel.tnPath}.${column.column_name}`,
);
if (baseModel.isPg) {
res[sanitize(getAs(column) || column.column_name)] =
baseModel.dbDriver.raw(`SUBSTR(??::TEXT, 1, ?)`, [
colPath,
NC_MAX_TEXT_LENGTH,
]);
} else if (baseModel.isMySQL) {
res[sanitize(getAs(column) || column.column_name)] =
baseModel.dbDriver.raw(`SUBSTR(??, 1, ?)`, [
colPath,
NC_MAX_TEXT_LENGTH,
]);
} else if (baseModel.isSqlite) {
res[sanitize(getAs(column) || column.column_name)] =
baseModel.dbDriver.raw(`SUBSTR(??, 1, ?)`, [
colPath,
NC_MAX_TEXT_LENGTH,
]);
} else {
// SQL Server / other databases - use LEFT function
res[sanitize(getAs(column) || column.column_name)] =
baseModel.dbDriver.raw(`LEFT(??, ?)`, [
colPath,
NC_MAX_TEXT_LENGTH,
]);
}
break;
}
default:
if (baseModel.isPg) {
if (column.dt === 'bytea') {