Example #1
0
        internal static void Put(IntPtr cursor, ref DbValue key, ref DbValue value, CursorPutOption option)
        {
            int err = _putDelegate(cursor, ref key, ref value, option);

            if (err != 0)
            {
                throw new MdbxException("mdbx_cursor_put", err);
            }
        }
Example #2
0
        /// <summary>
        /// Store by cursor.
        /// This function stores key/data pairs into the database. The cursor is
        /// positioned at the new item, or on failure usually near it.
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="option"></param>
        public void Put <K, V>(K key, V value, CursorPutOption option = CursorPutOption.Unspecific)
        {
            ISerializer <K> keySerializer   = SerializerRegistry.Get <K>();
            ISerializer <V> valueSerializer = SerializerRegistry.Get <V>();

            byte[] keyBytes   = keySerializer.Serialize(key);
            byte[] valueBytes = valueSerializer.Serialize(value);

            Put(keyBytes, valueBytes, option);
        }
Example #3
0
        /// <summary>
        /// Store by cursor.
        /// This function stores key/data pairs into the database. The cursor is
        /// positioned at the new item, or on failure usually near it.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="option"></param>
        public void Put(byte[] key, byte[] value, CursorPutOption option)
        {
            IntPtr keyPtr   = IntPtr.Zero;
            IntPtr valuePtr = IntPtr.Zero;

            if (key != null)
            {
                keyPtr = Marshal.AllocHGlobal(key.Length);
            }
            if (value != null)
            {
                valuePtr = Marshal.AllocHGlobal(key.Length);
            }

            try
            {
                if (key != null && key.Length > 0)
                {
                    Marshal.Copy(key, 0, keyPtr, key.Length);
                }
                if (value != null && value.Length > 0)
                {
                    Marshal.Copy(value, 0, valuePtr, value.Length);
                }

                DbValue dbKey   = new DbValue(keyPtr, key == null ? 0 : key.Length);
                DbValue dbValue = new DbValue(valuePtr, value == null ? 0 : value.Length);

                Cursor.Put(_cursorPtr, ref dbKey, ref dbValue, option);
            }
            finally
            {
                if (keyPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(keyPtr);
                }
                if (valuePtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(valuePtr);
                }
            }
        }