Beispiel #1
0
        /// <inheritdoc />
        public int ValidateAndGetLength(IDictionary <string, string?> value, ref NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter)
        {
            lengthCache ??= new NpgsqlLengthCache(1);
            if (lengthCache.IsPopulated)
            {
                return(lengthCache.Get());
            }

            // Leave empty slot for the entire hstore length, and go ahead an populate the individual string slots
            var pos = lengthCache.Position;

            lengthCache.Set(0);

            var totalLen = 4;  // Number of key-value pairs

            foreach (var kv in value)
            {
                totalLen += 8;   // Key length + value length
                if (kv.Key == null)
                {
                    throw new FormatException("HSTORE doesn't support null keys");
                }
                totalLen += _textHandler.ValidateAndGetLength(kv.Key, ref lengthCache, null);
                if (kv.Value != null)
                {
                    totalLen += _textHandler.ValidateAndGetLength(kv.Value !, ref lengthCache, null);
                }
            }

            return(lengthCache !.Lengths[pos] = totalLen);
        }
Beispiel #2
0
 /// <inheritdoc />
 public override int ValidateAndGetLength(string value, ref NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter) =>
 1 + _textHandler.ValidateAndGetLength(value, ref lengthCache, parameter);