Esempio n. 1
0
        protected override async Task HandleMessage(PgTransaction transaction, MessageBuilder messageBuilder, PipeWriter writer, CancellationToken token)
        {
            if (!string.IsNullOrEmpty(StatementName))
            {
                throw new PgErrorException(PgErrorCodes.FeatureNotSupported, "Named statements are not supported.");
            }

            // Extract optional parameter types (e.g. $1::int4)
            var foundParamTypes = new List <string>();
            var cleanQueryText  = ParamRegex.Replace(Query, new MatchEvaluator((Match match) =>
            {
                foundParamTypes.Add(match.Groups["type"].Value);
                return("");
            }));

            if (ParametersDataTypes.Length < foundParamTypes.Count)
            {
                var arr = ParametersDataTypes;
                ParametersDataTypes = new int[foundParamTypes.Count];
                arr.CopyTo(ParametersDataTypes.AsSpan());
            }

            for (int i = 0; i < foundParamTypes.Count; i++)
            {
                if (ParametersDataTypes[i] == 0)
                {
                    ParametersDataTypes[i] = PgType.Parse(foundParamTypes[i]).Oid;
                }
            }

            transaction.Init(cleanQueryText, ParametersDataTypes);
            await writer.WriteAsync(messageBuilder.ParseComplete(), token);
        }