public static IColumn VisitSelectElement(SelectElementContext context) { switch (context) { case SelectColumnElementContext selectColumnElementContext: return(new PropertyColumn { Name = IdentifierUtility.Parse(selectColumnElementContext.fullColumnName().GetText()), Alias = IdentifierUtility.Unescape(selectColumnElementContext.alias?.GetText()), }); case SelectFunctionElementContext selectFunctionElementContext: { if (selectFunctionElementContext.builtInFunctionCall() is CountFunctionCallContext) { return new CountFunctionColumn { Alias = IdentifierUtility.Unescape(selectFunctionElementContext.alias?.GetText()), } } ; return(VisitorHelper.ThrowNotSupportedFeature <IColumn>("Select Element Function")); } case SelectExpressionElementContext _: return(VisitorHelper.ThrowNotSupportedFeature <IColumn>("Select Element Expression")); } return(VisitorHelper.ThrowNotSupportedContext <IColumn>(context)); }
public override bool MatchIdentifier(QsiIdentifier x, QsiIdentifier y) { string nX = x.IsEscaped ? IdentifierUtility.Unescape(x.Value) : x.Value; string nY = y.IsEscaped ? IdentifierUtility.Unescape(y.Value) : y.Value; return(string.Equals(nX, nY, StringComparison.OrdinalIgnoreCase)); }
public override async Task <DbDataReader> ExecuteAsync(CancellationToken cancellationToken = default) { _deletedCount = 0; var selectQueryInfo = new SelectQueryInfo { WhereExpression = QueryInfo.WhereExpression, Limit = QueryInfo.Limit, TableSource = new AtomTableSource(QueryInfo.TableName, string.Empty), Columns = await GetColumnsAsync(cancellationToken), }; // TODO: Performance issue, need to performance enhancement. if (QueryInfo.WhereExpression == null) { throw new InvalidOperationException("Update not support without where expression."); } var planner = new SelectPlanner { QueryInfo = selectQueryInfo, Context = Context }; var reader = await planner.ExecuteAsync(cancellationToken); bool hasSortKey = selectQueryInfo.Columns.Length == 2; while (await reader.ReadAsync(cancellationToken)) { var request = new DeleteItemRequest { TableName = QueryInfo.TableName, ExpressionAttributeNames = ExpressionAttributeNames, ExpressionAttributeValues = ExpressionAttributeValues }; request.Key.Add(IdentifierUtility.Unescape(reader.GetName(0)), reader[0].ToAttributeValue()); if (hasSortKey) { request.Key.Add(IdentifierUtility.Unescape(reader.GetName(1)), reader[1].ToAttributeValue()); } try { await Context.Client.DeleteItemAsync(request, cancellationToken); } catch (AggregateException e) { var innerException = e.InnerExceptions[0]; throw new Exception($"Error while delete Item (Key: {reader.GetName(0)}){Environment.NewLine}{innerException.Message}"); } _deletedCount++; } return(new PrimarSqlDataReader(new EmptyDataProvider(_deletedCount))); }
public static QsiLiteralExpressionNode VisitLiteral(ParserRuleContext context) { QsiDataType literalType; object value; switch (context) { case NullLiteralContext _: literalType = QsiDataType.Null; value = null; break; case StringLiteralContext stringLiteral: { value = string.Join("", stringLiteral.STRING_LITERAL() .Select(l => IdentifierUtility.Unescape(l.GetText()))); literalType = QsiDataType.String; break; } case DecimalLiteralContext _: literalType = QsiDataType.Decimal; value = decimal.Parse(context.GetText()); break; case BooleanLiteralContext _: literalType = QsiDataType.Boolean; value = bool.Parse(context.GetText()); break; default: throw TreeHelper.NotSupportedTree(context); } var node = new QsiLiteralExpressionNode { Value = value, Type = literalType }; PrimarSqlTree.PutContextSpan(node, context); return(node); }
public bool Equals(QsiIdentifier x, QsiIdentifier y) { if (x == null && y == null) { return(true); } if (x == null || y == null) { return(false); } string nX = x.IsEscaped ? IdentifierUtility.Unescape(x.Value) : x.Value; string nY = y.IsEscaped ? IdentifierUtility.Unescape(y.Value) : y.Value; return(string.Equals(nX, nY, _comparison)); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is not QsiColumnTreeItem item) { return("<ERROR>"); } var column = item.Column; var name = column.IsAnonymous ? null : column.Name.IsEscaped ? IdentifierUtility.Unescape(column.Name.Value) : column.Name.Value; if (item.Column.IsExpression) { if (!item.Column.IsAnonymous) { return($"{name} {{expression}}"); } return("{expression}"); } return(name); }