Browse Source

fix: validate function implemented for the db

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/7268/head
Pranav C 7 months ago
parent
commit
3a2e15fce7
  1. 17
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

17
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -1249,6 +1249,10 @@ async function extractColumnIdentifierType({
errors?: Set<string>;
[p: string]: any;
} = {};
const sqlUI =
typeof clientOrSqlUi === 'string'
? SqlUiFactory.create({ client: clientOrSqlUi })
: clientOrSqlUi;
switch (col?.uidt) {
// string
@ -1342,10 +1346,6 @@ async function extractColumnIdentifierType({
case UITypes.ForeignKey:
case UITypes.SpecificDBType:
{
const sqlUI =
typeof clientOrSqlUi === 'string'
? SqlUiFactory.create({ client: clientOrSqlUi })
: clientOrSqlUi;
if (sqlUI) {
const abstractType = sqlUI.getAbstractType(col);
if (['integer', 'float', 'decimal'].includes(abstractType)) {
@ -1405,6 +1405,11 @@ export async function validateFormulaAndExtractTreeWithType({
column?: ColumnType;
getMeta: (tableId: string) => Promise<any>;
}) {
const sqlUI =
typeof clientOrSqlUi === 'string'
? SqlUiFactory.create({ client: clientOrSqlUi })
: clientOrSqlUi;
const colAliasToColMap = {};
const colIdToColMap = {};
@ -1423,11 +1428,11 @@ export async function validateFormulaAndExtractTreeWithType({
if (parsedTree.type === JSEPNode.CALL_EXP) {
const calleeName = parsedTree.callee.name.toUpperCase();
// validate function name
if (!formulas[calleeName]) {
if (!formulas[calleeName] || sqlUI?.getUnsupportedFnList().includes(calleeName)) {
throw new FormulaError(
FormulaErrorType.INVALID_FUNCTION_NAME,
{},
'Function not available'
`Function ${calleeName} is not available`
);
}

Loading…
Cancel
Save