/// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, Encoding encoding, MakeKeyGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit);
            }
            else if (0 == data.Length)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit | MakeKeyGrbit.KeyDataZeroLength);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for Unicode strings
                unsafe
                {
                    fixed (char* buffer = data)
                    {
                        Api.JetMakeKey(sesid, tableid, (IntPtr) buffer, data.Length * sizeof(char), grbit);
                    }
                }
            }
            else
            {
                byte[] bytes = encoding.GetBytes(data);
                Api.JetMakeKey(sesid, tableid, bytes, bytes.Length, grbit);
            }
        }
        /// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, Encoding encoding, MakeKeyGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit);
            }
            else if (0 == data.Length)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit | MakeKeyGrbit.KeyDataZeroLength);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for Unicode strings
                unsafe
                {
                    fixed (char* buffer = data)
                    {
                        Api.JetMakeKey(sesid, tableid, new IntPtr(buffer), checked(data.Length * sizeof(char)), grbit);
                    }
                }
            }
            else
            {
            #if MANAGEDESENT_ON_WSA
                // Encoding.GetBytes(char*, int, byte*, int) overload is missing in new Windows UI.
                // So we can't use the ColumnCache. We'll just use a different GetBytes() overload.
                byte[] buffer = encoding.GetBytes(data);
                Api.JetMakeKey(sesid, tableid, buffer, buffer.Length, grbit);
            #else
                // Convert the string using a cached column buffer. The column buffer is far larger
                // than the maximum key size, so any data truncation here won't matter.
                byte[] buffer = null;
                try
                {
                    buffer = Caches.ColumnCache.Allocate();
                    int dataSize;
                    unsafe
                    {
                        fixed (char* chars = data)
                        fixed (byte* bytes = buffer)
                        {
                            dataSize = encoding.GetBytes(chars, data.Length, bytes, buffer.Length);
                        }
                    }

                    JetMakeKey(sesid, tableid, buffer, dataSize, grbit);
                }
                finally
                {
                    if (buffer != null)
                    {
                        Caches.ColumnCache.Free(ref buffer);
                    }
                }
            #endif
            }
        }
Example #3
0
 /// <summary>Make the search key for this column.</summary>
 public override void MakeKey(EseCursorBase cur, object value, MakeKeyGrbit flags)
 {
     if (makeNullKey(cur, value, flags))
     {
         return;
     }
     Api.MakeKey(cur.idSession, cur.idTable, toOac(Convert.ToDecimal(value)), flags);
 }
Example #4
0
 /// <summary>Make the search key for this column.</summary>
 public override void MakeKey(EseCursorBase cur, object val, MakeKeyGrbit flags)
 {
     if (makeNullKey(cur, val, flags))
     {
         return;
     }
     Api.MakeKey(cur.idSession, cur.idTable, Convert.ToInt64(val), flags);
 }
Example #5
0
 public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, ulong data, MakeKeyGrbit grbit)
 {
     unsafe
     {
         const int DataSize = sizeof(ulong);
         var       pointer  = new IntPtr(&data);
         Api.JetMakeKey(sesid, tableid, pointer, DataSize, grbit);
     }
 }
Example #6
0
 /// <summary>Make the search key for this column.</summary>
 /// <param name="cur">The cursor to create the key on.</param>
 /// <param name="val">This object must be a string, otherwise an exception will be thrown.</param>
 /// <param name="flags">Key options.</param>
 public override void MakeKey(EseCursorBase cur, object val, MakeKeyGrbit flags)
 {
     if (val is string)
     {
         Api.MakeKey(cur.idSession, cur.idTable, val as string, getEncoding(), flags);
     }
     else
     {
         makeKeyException(val);
     }
 }
Example #7
0
 /// <summary>Make the search key for this column.</summary>
 public override void MakeKey(EseCursorBase cur, object val, MakeKeyGrbit flags)
 {
     if (m_bFieldNullable && val == null)
     {
         Api.MakeKey(cur.idSession, cur.idTable, null, flags);
     }
     else
     {
         Api.MakeKey(cur.idSession, cur.idTable, Convert.ToBoolean(val), flags);
     }
 }
Example #8
0
 /// <summary>Make the search key for this column.</summary>
 public override void MakeKey(EseCursorBase cur, object val, MakeKeyGrbit flags)
 {
     if (makeNullKey(cur, val, flags))
     {
         return;
     }
     if (!val.GetType().GetTypeInfo().IsPrimitive)
     {
         makeKeyException(val);
     }
     Api.MakeKey(cur.idSession, cur.idTable, Convert.ToByte(val), flags);
 }
Example #9
0
 /// <summary>Try to make a null key.</summary>
 /// <param name="cur">ESENT cursor.</param>
 /// <param name="value">The value that might be null. If it's not null, this method silently returns false. If it is null but the column is not nullable, this method throws an exception.</param>
 /// <param name="flags">Key options.</param>
 /// <returns>true if the field is nullable, and the value is null, and the JetMakeKey was called.</returns>
 protected bool makeNullKey(EseCursorBase cur, object value, MakeKeyGrbit flags)
 {
     if (value != null)
     {
         return(false);
     }
     if (!bFieldNullable)
     {
         makeKeyException(value);
     }
     Api.MakeKey(cur.idSession, cur.idTable, null, flags);
     return(true);
 }
Example #10
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="JetSeek"/>
 /// and <see cref="JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, byte[] data, MakeKeyGrbit grbit)
 {
     if (null == data)
     {
         Api.JetMakeKey(sesid, tableid, null, 0, grbit);
     }
     else if (0 == data.Length)
     {
         Api.JetMakeKey(sesid, tableid, data, data.Length, grbit | MakeKeyGrbit.KeyDataZeroLength);
     }
     else
     {
         Api.JetMakeKey(sesid, tableid, data, data.Length, grbit);
     }
 }
Example #11
0
 /// <summary>Make the search key for this column.</summary>
 public override void MakeKey(EseCursorBase cur, object val, MakeKeyGrbit flags)
 {
     if (this.m_cp == JET_coltyp.Long)
     {
         Api.MakeKey(cur.idSession, cur.idTable, Convert.ToInt32(val), flags);
     }
     else if (this.m_cp == JET_coltyp.Currency)
     {
         Api.MakeKey(cur.idSession, cur.idTable, Convert.ToInt64(val), flags);
     }
     else
     {
         throw new System.Runtime.Serialization.SerializationException();
     }
 }
Example #12
0
 /// <summary>Make the search key for this column.</summary>
 /// <remarks><b>NB!</b> The native GUID columns are only supported by ESENT shipped with Vista and above.
 /// You'll get different sort order between Server 2003 and Vista.
 /// On Server 2003 and below, the sort order will be just memcmp() of the GUID's 16 bytes, while on Vista and above the sort order will be OK.</remarks>
 public override void MakeKey(EseCursorBase cur, object value, MakeKeyGrbit flags)
 {
     if (m_bFieldNullable && value == null)
     {
         Api.MakeKey(cur.idSession, cur.idTable, null, flags);
     }
     else if (value is Guid)
     {
         Api.MakeKey(cur.idSession, cur.idTable, (Guid)value, flags);
     }
     else
     {
         makeKeyException(value);
     }
 }
Example #13
0
 /// <summary>Make the search key for this column.</summary>
 public override void MakeKey(EseCursorBase cur, object val, MakeKeyGrbit flags)
 {
     if (val == null)
     {
         Api.MakeKey(cur.idSession, cur.idTable, null, flags);
     }
     else if (val is DateTime)
     {
         Api.MakeKey(cur.idSession, cur.idTable, getTicks((DateTime)val), flags);
     }
     else
     {
         makeKeyException(val);
     }
 }
Example #14
0
 // Make the search key.
 // The first MakeKey call is made with MakeKeyGrbit.NewKey flag.
 // The final MakeKey call is made with the 'lastColumnFlags' flag.
 // The rest of MakeKey calls (if any) is made with zero flag.
 protected void makeKey(object[] vals, MakeKeyGrbit lastColumnFlags)
 {
     System.Diagnostics.Debug.Assert(indColumns.Length >= vals.Length);
     for (int i = 0; i < vals.Length; i++)
     {
         MakeKeyGrbit flags = MakeKeyGrbit.None;
         if (0 == i)
         {
             flags |= MakeKeyGrbit.NewKey;
         }
         if (i + 1 == vals.Length)
         {
             flags |= lastColumnFlags;
         }
         indColumns[i].MakeKey(cur, vals[i], flags);
     }
 }
Example #15
0
        /// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, Encoding encoding, MakeKeyGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit);
            }
            else if (0 == data.Length)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit | MakeKeyGrbit.KeyDataZeroLength);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for Unicode strings
                unsafe
                {
                    fixed (char* buffer = data)
                    {
                        Api.JetMakeKey(sesid, tableid, new IntPtr(buffer), checked(data.Length * sizeof(char)), grbit);
                    }
                }
            }
            else
            {
                // Convert the string using a cached column buffer. The column buffer is far larger
                // than the maximum key size, so any data truncation here won't matter.
                byte[] buffer = Caches.ColumnCache.Allocate();
                int dataSize;
                unsafe
                {
                    fixed (char* chars = data)
                    fixed (byte* bytes = buffer)
                    {
                        dataSize = encoding.GetBytes(chars, data.Length, bytes, buffer.Length);
                    }
                }

                JetMakeKey(sesid, tableid, buffer, dataSize, grbit);
                Caches.ColumnCache.Free(ref buffer);
            }
        }
Example #16
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="JetSeek"/>
 /// and <see cref="JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, bool data, MakeKeyGrbit grbit)
 {
     byte b = data ? (byte)0xff : (byte)0x0;
     Api.MakeKey(sesid, tableid, b, grbit);
 }
Example #17
0
 /// <summary>Make the search key for this column.</summary>
 public override void MakeKey(EseCursorBase cur, object val, MakeKeyGrbit flags)
 {
     Api.MakeKey(cur.idSession, cur.idTable, Convert.ToInt32(val), flags);
 }
Example #18
0
 /// <summary>Make search key for this column.</summary>
 /// <remarks>This abstract base class always throws an exception instead of calling JetMakeKey API.</remarks>
 /// <param name="cur">ESENT cursor.</param>
 /// <param name="value">The key value supplied by the user.</param>
 /// <param name="flags">Bit flags for JetMakeKey.</param>
 public virtual void MakeKey(EseCursorBase cur, object value, MakeKeyGrbit flags)
 {
     makeKeyException(value);
 }
Example #19
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="JetSeek"/>
 /// and <see cref="JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 internal static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, ulong data, MakeKeyGrbit grbit)
 {
     unsafe
     {
         const int DataSize = 8;
         var pointer = new IntPtr(&data);
         Api.JetMakeKey(sesid, tableid, pointer, DataSize, grbit);
     }
 }
Example #20
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="JetSeek"/>
 /// and <see cref="JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, DateTime data, MakeKeyGrbit grbit)
 {
     Api.MakeKey(sesid, tableid, data.ToOADate(), grbit);
 }
Example #21
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="JetSeek"/>
 /// and <see cref="JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, DateTime data, MakeKeyGrbit grbit)
 {
     Api.MakeKey(sesid, tableid, data.ToOADate(), grbit);
 }
Example #22
0
 /// <summary>
 /// Make a key for the cursor.
 /// </summary>
 /// <param name="data">The data to use.</param>
 /// <param name="grbit">MakeKey option.</param>
 public virtual void MakeKey(byte[] data, MakeKeyGrbit grbit)
 {
     Api.JetMakeKey(this.session, this.table, data, data.Length, grbit);
 }
Example #23
0
 public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, uint data, MakeKeyGrbit grbit)
 {
     unsafe
     {
         const int DataSize = sizeof(uint);
         var pointer = new IntPtr(&data);
         Api.JetMakeKey(sesid, tableid, pointer, DataSize, grbit);
     }
 }
Example #24
0
 /// <summary>
 /// Constructs search keys that may then be used by JetSeek and JetSetIndexRange.
 /// </summary>
 /// <remarks>
 /// This is an internal (unsafe) version that takes an IntPtr.
 /// </remarks>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="dataSize">Size of the data.</param>
 /// <param name="grbit">Key options.</param>
 internal static void JetMakeKey(JET_SESID sesid, JET_TABLEID tableid, IntPtr data, int dataSize, MakeKeyGrbit grbit)
 {
     Api.Check(Impl.JetMakeKey(sesid, tableid, data, dataSize, grbit));
 }
Example #25
0
        /// <summary>
        /// Constructs search keys that may then be used by <see cref="JetSeek"/> and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <remarks>
        /// The MakeKey functions provide datatype-specific make key functionality.
        /// </remarks>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="dataSize">Size of the data.</param>
        /// <param name="grbit">Key options.</param>
        public static void JetMakeKey(JET_SESID sesid, JET_TABLEID tableid, byte[] data, int dataSize, MakeKeyGrbit grbit)
        {
            if ((null == data && 0 != dataSize) || (null != data && dataSize > data.Length))
            {
                throw new ArgumentOutOfRangeException(
                    "dataSize",
                    dataSize,
                    "cannot be greater than the length of the data");
            }

            unsafe
            {
                fixed (byte* pointer = data)
                {
                    Api.JetMakeKey(sesid, tableid, new IntPtr(pointer), dataSize, grbit);
                }
            }
        }
Example #26
0
        /// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, Encoding encoding, MakeKeyGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit);
            }
            else if (0 == data.Length)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit | MakeKeyGrbit.KeyDataZeroLength);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for Unicode strings
                unsafe
                {
                    fixed(char *buffer = data)
                    {
                        Api.JetMakeKey(sesid, tableid, new IntPtr(buffer), checked (data.Length * sizeof(char)), grbit);
                    }
                }
            }
            else
            {
#if MANAGEDESENT_ON_WSA
                // Encoding.GetBytes(char*, int, byte*, int) overload is missing in new Windows UI.
                // So we can't use the ColumnCache. We'll just use a different GetBytes() overload.
                byte[] buffer = encoding.GetBytes(data);
                Api.JetMakeKey(sesid, tableid, buffer, buffer.Length, grbit);
#else
                // Convert the string using a cached column buffer. The column buffer is far larger
                // than the maximum key size, so any data truncation here won't matter.
                byte[] buffer = null;
                try
                {
                    buffer = Caches.ColumnCache.Allocate();
                    int dataSize;
                    unsafe
                    {
                        fixed(char *chars = data)
                        fixed(byte *bytes = buffer)
                        {
                            dataSize = encoding.GetBytes(chars, data.Length, bytes, buffer.Length);
                        }
                    }

                    JetMakeKey(sesid, tableid, buffer, dataSize, grbit);
                }
                finally
                {
                    if (buffer != null)
                    {
                        Caches.ColumnCache.Free(ref buffer);
                    }
                }
#endif
            }
        }
Example #27
0
 // Make search key from the input values, return the normalized search key.
 protected byte[] getSearchKey(object[] vals, MakeKeyGrbit lastColumnFlag)
 {
     makeKey(vals, lastColumnFlag);
     return(Api.RetrieveKey(cur.idSession, cur.idTable, RetrieveKeyGrbit.RetrieveCopy));
 }
Example #28
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="Api.JetSeek"/>
 /// and <see cref="Api.JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 private static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, MakeKeyGrbit grbit)
 {
     Api.MakeKey(sesid, tableid, data, Encoding.Unicode, grbit);
 }
Example #29
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="JetSeek"/>
 /// and <see cref="JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, byte[] data, MakeKeyGrbit grbit)
 {
     if (null == data)
     {
         Api.JetMakeKey(sesid, tableid, null, 0, grbit);
     }
     else if (0 == data.Length)
     {
         Api.JetMakeKey(sesid, tableid, data, data.Length, grbit | MakeKeyGrbit.KeyDataZeroLength);
     }
     else
     {
         Api.JetMakeKey(sesid, tableid, data, data.Length, grbit);
     }
 }
Example #30
0
 /// <summary>
 /// Constructs search keys that may then be used by JetSeek and JetSetIndexRange.
 /// </summary>
 /// <remarks>
 /// This is an internal (unsafe) version that takes an IntPtr.
 /// </remarks>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="dataSize">Size of the data.</param>
 /// <param name="grbit">Key options.</param>
 internal static void JetMakeKey(JET_SESID sesid, JET_TABLEID tableid, IntPtr data, int dataSize, MakeKeyGrbit grbit)
 {
     Api.Check(Impl.JetMakeKey(sesid, tableid, data, dataSize, grbit));
 }
Example #31
0
        /// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, Encoding encoding, MakeKeyGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit);
            }
            else if (0 == data.Length)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit | MakeKeyGrbit.KeyDataZeroLength);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for Unicode strings
                unsafe
                {
                    fixed(char *buffer = data)
                    {
                        Api.JetMakeKey(sesid, tableid, new IntPtr(buffer), checked (data.Length * sizeof(char)), grbit);
                    }
                }
            }
            else
            {
                byte[] bytes = encoding.GetBytes(data);
                Api.JetMakeKey(sesid, tableid, bytes, bytes.Length, grbit);
            }
        }
Example #32
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="JetSeek"/>
 /// and <see cref="JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, Guid data, MakeKeyGrbit grbit)
 {
     byte[] bytes = data.ToByteArray();
     Api.JetMakeKey(sesid, tableid, bytes, bytes.Length, grbit);
 }
Example #33
0
 /// <summary>
 /// Make a key for the cursor.
 /// </summary>
 /// <param name="data">The data to use.</param>
 /// <param name="grbit">MakeKey option.</param>
 public virtual void MakeKey(byte[] data, MakeKeyGrbit grbit)
 {
     Api.JetMakeKey(this.session, this.table, data, data.Length, grbit);
 }
Example #34
0
        /// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, bool data, MakeKeyGrbit grbit)
        {
            byte b = data ? (byte)0xff : (byte)0x0;

            Api.MakeKey(sesid, tableid, b, grbit);
        }
Example #35
0
 /// <summary>
 /// Constructs a search key that may then be used by <see cref="Api.JetSeek"/>
 /// and <see cref="Api.JetSetIndexRange"/>.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The cursor to create the key on.</param>
 /// <param name="data">Column data for the current key column of the current index.</param>
 /// <param name="grbit">Key options.</param>
 private static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, DateTime data, MakeKeyGrbit grbit)
 {
     Api.MakeKey(sesid, tableid, data.Ticks, grbit);
 }
Example #36
0
        /// <summary>
        /// Constructs a search key that may then be used by <see cref="JetSeek"/>
        /// and <see cref="JetSetIndexRange"/>.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to create the key on.</param>
        /// <param name="data">Column data for the current key column of the current index.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">Key options.</param>
        public static void MakeKey(JET_SESID sesid, JET_TABLEID tableid, string data, Encoding encoding, MakeKeyGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit);
            }
            else if (0 == data.Length)
            {
                Api.JetMakeKey(sesid, tableid, null, 0, grbit | MakeKeyGrbit.KeyDataZeroLength);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for Unicode strings
                unsafe
                {
                    fixed(char *buffer = data)
                    {
                        Api.JetMakeKey(sesid, tableid, new IntPtr(buffer), checked (data.Length * sizeof(char)), grbit);
                    }
                }
            }
            else
            {
                // Convert the string using a cached column buffer. The column buffer is far larger
                // than the maximum key size, so any data truncation here won't matter.
                byte[] buffer = Caches.ColumnCache.Allocate();
                int    dataSize;
                unsafe
                {
                    fixed(char *chars = data)
                    fixed(byte *bytes = buffer)
                    {
                        dataSize = encoding.GetBytes(chars, data.Length, bytes, buffer.Length);
                    }
                }

                JetMakeKey(sesid, tableid, buffer, dataSize, grbit);
                Caches.ColumnCache.Free(ref buffer);
            }
        }