Beispiel #1
0
        /// <summary>Store the column value in the database.</summary>
        public override void Serialize(EseCursorBase cur, JET_COLUMNID idColumn, object value, bool bNewRecord)
        {
            if (!bNewRecord)
            {
                // If this is an UPDATE operation, erase the old values.
                JET_SETINFO si = new JET_SETINFO();
                for (int itg = GetValuesCountSilent(cur, idColumn); itg > 0; itg--)
                {
                    si.ibLongValue  = 0;
                    si.itagSequence = itg;
                    Api.JetSetColumn(cur.idSession, cur.idTable, idColumn,
                                     null, 0, SetColumnGrbit.None, si);
                }
            }

            var arr = value as int[];

            if (null == arr)
            {
                return;
            }

            // Set new values
            foreach (var s in arr)
            {
                AddValue(cur, idColumn, s);
            }
        }
Beispiel #2
0
        // Get the multiple values as the int[]
        int[] GetValues(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            int nValues = GetValuesCount(cur, idColumn);
            var res     = new int[nValues];

            if (0 == nValues)
            {
                return(res);
            }

            byte[]      buff = new byte[sizeof(int)];
            JET_RETINFO ri   = new JET_RETINFO();

            for (int itg = 1; itg <= nValues; itg++)
            {
                ri.itagSequence = itg;
                int cbSize;
                Api.JetRetrieveColumn(cur.idSession, cur.idTable, idColumn,
                                      buff, buff.Length, out cbSize, RetrieveColumnGrbit.None, ri);
                if (cbSize != buff.Length)
                {
                    throw new SerializationException();
                }
                res[itg - 1] = BitConverter.ToInt32(buff, 0);
            }
            return(res);
        }
Beispiel #3
0
        // Get the multiple values as the List<string>
        List <string> GetValues(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            int           nValues = GetValuesCount(cur, idColumn);
            List <string> res     = new List <string>(nValues);

            if (0 == nValues)
            {
                return(res);
            }

            byte[] buff = new byte[s_cbMaxValueLength];
            System.Text.Encoding enc = getEncoding();

            JET_RETINFO ri = new JET_RETINFO();

            for (int itg = 1; itg <= nValues; itg++)
            {
                ri.itagSequence = itg;
                int cbSize;
                Api.JetRetrieveColumn(cur.idSession, cur.idTable, idColumn,
                                      buff, buff.Length, out cbSize, RetrieveColumnGrbit.None, ri);
                if (cbSize >= 0)
                {
                    res.Add(enc.GetString(buff, 0, cbSize));
                }
                else
                {
                    res.Add(null);
                }
            }

            return(res);
        }
Beispiel #4
0
        /// <summary>Retrieve the column value from the DB.</summary>
        public override object Deserialize(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            byte[] res = Api.RetrieveColumn(cur.idSession, cur.idTable, idColumn);
            if (null == res || 0 == res.Length)
            {
                if (bFieldNullable)
                {
                    return(null);
                }
                throw new SerializationException("The column is marked 'ColumnNotNULL', however the NULL value was pulled from the database.");
            }
            if (16 != res.Length)
            {
                throw new SerializationException("The column of type Decimal must contain exactly 16 bytes.");
            }

            Int32[] bits = new Int32[4]
            {
                BitConverter.ToInt32(res, 0),
                BitConverter.ToInt32(res, 4),
                BitConverter.ToInt32(res, 8),
                BitConverter.ToInt32(res, 12),
            };

            return(new Decimal(bits));
        }
Beispiel #5
0
        static bool isDirectory(EseCursorBase cur)
        {
            bool?val = Api.RetrieveColumnAsBoolean(cur.idSession, cur.idTable,
                                                   colIsDirectory, RetrieveColumnGrbit.RetrieveFromIndex);

            return(val.HasValue && val.Value);
        }
Beispiel #6
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);
 }
Beispiel #7
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);
 }
Beispiel #8
0
        // Append the given value to this column
        void AddValue(EseCursorBase cur, JET_COLUMNID idColumn, int val)
        {
            byte[]      data = BitConverter.GetBytes(val);
            JET_SETINFO si   = new JET_SETINFO();

            si.itagSequence = 0;
            Api.JetSetColumn(cur.idSession, cur.idTable, idColumn, data, data.Length, SetColumnGrbit.None, si);
        }
Beispiel #9
0
 /// <summary>Store the column value in the database.</summary>
 public override void Serialize(EseCursorBase cur, JET_COLUMNID idColumn, object value, bool bNewRecord)
 {
     if (serializeNull(cur, idColumn, value))
     {
         return;
     }
     Api.SetColumn(cur.idSession, cur.idTable, idColumn, Convert.ToInt32(value));
 }
Beispiel #10
0
 /// <summary>Open the stream as read-write.</summary>
 /// <param name="cur">The cursor; it must be on the same table.</param>
 /// <returns>The read-write ColumnStream object</returns>
 /// <remarks>
 /// <para>Calling this method will change DB cursor position, setting it to the row where the record is located.</para>
 /// <para><b>NB!</b> You must call Dispose() on the returned stream.
 /// Failing to do that will cancel the update and leak the unmanaged resources.</para>
 /// </remarks>
 public ColumnStream Write(EseCursorBase cur)
 {
     if (!PositionOnTheRecord(cur))
     {
         return(null);
     }
     return(new ReadWriteColumnStream(cur, idColumn));
 }
Beispiel #11
0
        /// <summary>Store the column value in the database.</summary>
        public override void Serialize(EseCursorBase cur, JET_COLUMNID idColumn, object value, bool bNewRecord)
        {
            if (serializeNull(cur, idColumn, value))
            {
                return;
            }
            DateTime dt = (DateTime)(value);

            Api.SetColumn(cur.idSession, cur.idTable, idColumn, getTicks(dt));
        }
Beispiel #12
0
        /// <summary>Store the column value in the database.</summary>
        public override void Serialize(EseCursorBase cur, JET_COLUMNID idColumn, object value, bool bNewRecord)
        {
            if (serializeNull(cur, idColumn, value))
            {
                return;
            }
            long lv = toOac(Convert.ToDecimal(value));

            Api.SetColumn(cur.idSession, cur.idTable, idColumn, lv);
        }
Beispiel #13
0
        /// <summary>Retrieve the column value from the DB.</summary>
        public override object Deserialize(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            int?res = Api.RetrieveColumnAsInt32(cur.idSession, cur.idTable, idColumn);

            if (null == res)
            {
                return(null);
            }
            return(Enum.ToObject(m_enumType, res));
        }
Beispiel #14
0
        /// <summary>Retrieve the column value from the DB.</summary>
        public override object Deserialize(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            int?res = Api.RetrieveColumnAsInt32(cur.idSession, cur.idTable, idColumn);

            if (!bFieldNullable)
            {
                return(res.Value);
            }
            return(res);
        }
Beispiel #15
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);
     }
 }
Beispiel #16
0
 // Same as GetValuesCount, but no exception is ever thrown, instead zero is being silently returned.
 int GetValuesCountSilent(EseCursorBase cur, JET_COLUMNID idColumn)
 {
     try
     {
         return(GetValuesCount(cur, idColumn));
     }
     catch (System.Exception)
     {
         return(0);
     }
 }
Beispiel #17
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);
     }
 }
Beispiel #18
0
 /// <summary>Retrieve copy of the auto-incremented value.</summary>
 /// <remarks>See the <a href="http://managedesent.codeplex.com/wikipage?title=HowDoI" target="_blank" >"How do I?" page in managed ESENT wiki</a>,
 /// section "How Do I Retrieve an Auto-Increment Column Value?"</remarks>
 /// <param name="cur"></param>
 /// <param name="idColumn"></param>
 public object RetrieveCopy(EseCursorBase cur, JET_COLUMNID idColumn)
 {
     if (this.m_cp == JET_coltyp.Long)
     {
         return(Api.RetrieveColumnAsInt32(cur.idSession, cur.idTable, idColumn, RetrieveColumnGrbit.RetrieveCopy) ?? null);
     }
     if (this.m_cp == JET_coltyp.Currency)
     {
         return(Api.RetrieveColumnAsInt64(cur.idSession, cur.idTable, idColumn, RetrieveColumnGrbit.RetrieveCopy) ?? null);
     }
     throw new System.Runtime.Serialization.SerializationException();
 }
Beispiel #19
0
 /// <summary>Retrieve the column value from the DB.</summary>
 public override object Deserialize(EseCursorBase cur, JET_COLUMNID idColumn)
 {
     if (this.m_cp == JET_coltyp.Long)
     {
         return(Api.RetrieveColumnAsInt32(cur.idSession, cur.idTable, idColumn).Value);
     }
     if (this.m_cp == JET_coltyp.Currency)
     {
         return(Api.RetrieveColumnAsInt64(cur.idSession, cur.idTable, idColumn).Value);
     }
     throw new System.Runtime.Serialization.SerializationException();
 }
Beispiel #20
0
 /// <summary>Retrieve the column value from the DB.</summary>
 public override object Deserialize(EseCursorBase cur, JET_COLUMNID idColumn)
 {
     using (var stm = new ColumnStream(cur.idSession, cur.idTable, idColumn))
     {
         if (stm.Length < 1)
         {
             return(null);
         }
         using (var br = XmlDictionaryReader.CreateBinaryReader(stm, this.dict, XmlDictionaryReaderQuotas.Max))
             return(m_serializer.ReadObject(br));
     }
 }
Beispiel #21
0
        // Get the count of the values stored in the multi-valued column.
        int GetValuesCount(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            // See http://stackoverflow.com/questions/2929587 for more info
            JET_RETRIEVECOLUMN jrc = new JET_RETRIEVECOLUMN();

            jrc.columnid     = idColumn;
            jrc.itagSequence = 0;
            Api.JetRetrieveColumns(cur.idSession, cur.idTable, new JET_RETRIEVECOLUMN[1] {
                jrc
            }, 1);
            return(jrc.itagSequence);
        }
Beispiel #22
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);
 }
Beispiel #23
0
 /// <summary>Try to store a null value.</summary>
 /// <param name="cur">ESENT cursor</param>
 /// <param name="idColumn">ID of the column</param>
 /// <param name="value">The value that might be null. If it's not null, this method silently returns false.</param>
 /// <returns>true if the field is nullable, and the value is null, and JetSetColumn was called.</returns>
 protected bool serializeNull(EseCursorBase cur, JET_COLUMNID idColumn, object value)
 {
     if (!bFieldNullable)
     {
         return(false);
     }
     if (value != null)
     {
         return(false);
     }
     Api.SetColumn(cur.idSession, cur.idTable, idColumn, null);
     return(true);
 }
Beispiel #24
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);
 }
Beispiel #25
0
        /// <summary>Retrieve the column value from the DB.</summary>
        public override object Deserialize(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            double?res = Api.RetrieveColumnAsDouble(cur.idSession, cur.idTable, idColumn);

            if (null == res)
            {
                if (bFieldNullable)
                {
                    return(null);
                }
                throw new SerializationException("The column is marked 'ColumnNotNULL', however the NULL value was pulled from the database.");
            }
            return(res.Value);
        }
Beispiel #26
0
        /// <summary>Construct the object</summary>
        /// <param name="cur"></param>
        /// <param name="_idColumn"></param>
        public EseStreamValue(EseCursorBase cur, JET_COLUMNID _idColumn)
        {
            idColumn  = _idColumn;
            bk        = cur.getBookmark();
            tableName = cur.tableName;

            // Fetch the length.
            // Copy-pasted from Microsoft.Isam.Esent.Interop.ColumnStream.Length get
            var retinfo = new JET_RETINFO {
                itagSequence = 1, ibLongValue = 0
            };

            Api.JetRetrieveColumn(cur.idSession, cur.idTable, idColumn, null, 0, out length, RetrieveColumnGrbit.RetrieveCopy, retinfo);
        }
Beispiel #27
0
        /// <summary>Retrieve the column value from the DB.</summary>
        public override object Deserialize(EseCursorBase cur, JET_COLUMNID idColumn)
        {
            long?val = Api.RetrieveColumnAsInt64(cur.idSession, cur.idTable, idColumn);

            if (null == val)
            {
                if (bFieldNullable)
                {
                    return(null);
                }
                throw new SerializationException("The column is marked 'ColumnNotNULL', however the NULL value was pulled from the database.");
            }
            return(getDateTime(val.Value));
        }
Beispiel #28
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);
     }
 }
Beispiel #29
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();
     }
 }
Beispiel #30
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);
     }
 }