JetMakeKey() public static method

Constructs search keys that may then be used by JetSeek and JetSetIndexRange.
The MakeKey functions provide datatype-specific make key functionality.
public static JetMakeKey ( JET_SESID sesid, JET_TABLEID tableid, byte data, int dataSize, MakeKeyGrbit grbit ) : void
sesid JET_SESID The session to use.
tableid JET_TABLEID The cursor to create the key on.
data byte Column data for the current key column of the current index.
dataSize int Size of the data.
grbit MakeKeyGrbit Key options.
return void
Example #1
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 #2
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 #3
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 #4
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 #5
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);
            }
        }