internal ColumnTypeMetadata TryGetScalarVariableType(string variableName) { var pt = parameters.TryGetParameterType(variableName); if (pt != null) { return(new ColumnTypeMetadata(pt.ColumnDbType, pt.AllowNull)); } // scan for variable declaration TableVariableDeclarionVisitor vstor = new TableVariableDeclarionVisitor(variableName); BodyFragment.Accept(vstor); if (vstor.variableDefinition != null) { throw new NotImplementedException(variableName); } if (vstor.VariableDataType != null) { var variableDbType = ProcedureGenerator.ResolveToDbDataType(vstor.VariableDataType); return(new ColumnTypeMetadata(variableDbType, true)); } //BodyFragment.Accept(new DumpFragmentVisitor(true)); throw new NotImplementedException(variableName); }
public TableVariableMetadata(TableDefinition variableDefinition) { this.variableDefinition = variableDefinition; foreach (ColumnDefinition colDef in variableDefinition.ColumnDefinitions) { cache_columns.Add(colDef.ColumnIdentifier.Value, new ColumnTypeMetadata(ProcedureGenerator.ResolveToDbDataType(colDef.DataType), true)); } }
public OutputColumnDescriptor ResolveSelectScalarExpression(SelectScalarExpression node) { IQueryModel model = EnsureModel(); if (TryGetOutputColumnName(node, out string outputColumnName)) { if (model.TryGetQueryOutputColumnByName(batchResolver, outputColumnName, out QueryColumnBase col)) { return(ColumnModelToDescriptor(col)); } throw new NotImplementedException(node.Expression.WhatIsThis()); } else if (node.Expression is ColumnReferenceExpression colRef) { if (TryColumnReference(model, colRef, out QueryColumnBase col)) { return(ColumnModelToDescriptor(col)); } throw new NotImplementedException(node.Expression.WhatIsThis()); } else if (node.Expression is IIfCall iif) { // no output name! if single column output -> use it??? if (TrtGetAnonymousColumnType_ScalarExpression(iif.ThenExpression, out DbType columnDbTypeT, out bool allowNull)) { return(ColumnModelToDescriptor(columnDbTypeT, allowNull)); } if (TrtGetAnonymousColumnType_ScalarExpression(iif.ThenExpression, out DbType columnDbTypeE, out allowNull)) { return(ColumnModelToDescriptor(columnDbTypeE, allowNull)); } throw new NotImplementedException(iif.ElseExpression.WhatIsThis()); } else if (node.Expression is CastCall castExpr) { var dbType = ProcedureGenerator.ResolveToDbDataType(castExpr.DataType); return(ColumnModelToDescriptor(dbType, true)); } else if (node.Expression is VariableReference varRefExpr) { var varType = batchResolver.TryGetScalarVariableType(varRefExpr.Name); if (varType != null) { return(ColumnModelToDescriptor(varType.ColumnDbType, varType.AllowNull)); } throw new NotImplementedException(varRefExpr.Name); } else if (node.Expression is FunctionCall fCall) { string functionName = fCall.FunctionName.Dequote(); if (string.Equals(functionName, "COUNT", StringComparison.OrdinalIgnoreCase)) { return(ColumnModelToDescriptor(DbType.Int32, true)); } throw new NotImplementedException(fCall.WhatIsThis()); } else { throw new NotImplementedException(node.Expression.WhatIsThis()); } }