Ejemplo n.º 1
0
 /// <summary>
 ///     Moves the cursor to the specified position.
 /// </summary>
 /// <param name="op"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public bool MoveCursor(CursorOp op, int x, int y)
 {
     lock (tn)
     {
         return(tn.Controller.MoveCursor(op, x, y));
     }
 }
Ejemplo n.º 2
0
 public bool MoveCursor(CursorOp op, int x, int y)
 {
     lock (tn)
     {
         return(tn.tnctlr.MoveCursor(op, x, y));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Get items from a database.
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="op"></param>
        /// <returns>false if not found.</returns>
        public bool Get <K, V>(ref K key, ref V value, CursorOp op)
        {
            ISerializer <K> keySerializer   = SerializerRegistry.Get <K>();
            ISerializer <V> valueSerializer = SerializerRegistry.Get <V>();

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

            bool found = Get(ref keyBytes, ref valueBytes, op);

            if (found)
            {
                if (keyBytes != null)
                {
                    key = keySerializer.Deserialize(keyBytes);
                }
                else
                {
                    key = default(K);
                }

                if (valueBytes != null)
                {
                    value = valueSerializer.Deserialize(valueBytes);
                }
                else
                {
                    value = default(V);
                }
            }
            return(found);
        }
Ejemplo n.º 4
0
        internal static void Get(IntPtr cursor, ref DbValue key, ref DbValue value, CursorOp op)
        {
            int err = _getDelegate(cursor, ref key, ref value, op);

            if (err != 0)
            {
                throw new MdbxException("mdbx_cursor_get", err);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get items from a database.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="op"></param>
        public bool Get(ref byte[] key, ref byte[] value, CursorOp op)
        {
            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.Get(_cursorPtr, ref dbKey, ref dbValue, op);

                if (dbKey.Address != IntPtr.Zero)
                {
                    if (key == null || key.Length != dbKey.Length)
                    {
                        key = new byte[dbKey.Length];
                    }
                    Marshal.Copy(dbKey.Address, key, 0, key.Length);
                }
                else
                {
                    key = null;
                }
                if (dbValue.Address != IntPtr.Zero)
                {
                    if (value == null || value.Length != dbValue.Length)
                    {
                        value = new byte[dbValue.Length];
                    }
                    Marshal.Copy(dbValue.Address, value, 0, value.Length);
                }
                else
                {
                    value = null;
                }
            }
            catch (MdbxException ex)
            {
                if (ex.ErrorNumber == MdbxCode.MDBX_NOTFOUND)
                {
                    return(false);
                }
                throw;
            }
            finally
            {
                if (keyPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(keyPtr);
                }
                if (valuePtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(valuePtr);
                }
            }
            return(true);
        }