예제 #1
0
        public int ValidateAndGetLength(IDictionary <string, string> value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
        {
            if (lengthCache == null)
            {
                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);
        }
예제 #2
0
        public int ValidateAndGetLength(object value, ref LengthCache lengthCache, NpgsqlParameter parameter = null)
        {
            if (lengthCache == null)
            {
                lengthCache = new LengthCache(1);
            }
            if (lengthCache.IsPopulated)
            {
                return(lengthCache.Get() + 1);
            }

            // Add one byte for the prepended version number
            return(_textHandler.ValidateAndGetLength(value, ref lengthCache, parameter) + 1);
        }
예제 #3
0
 /// <inheritdoc />
 public override int ValidateAndGetLength(string value, ref NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter) =>
 1 + _textHandler.ValidateAndGetLength(value, ref lengthCache, parameter);