Insert() public static méthode

public static Insert ( IntPtr handle, IntPtr txnhandle, byte keyData, byte recordData, int flags ) : int
handle System.IntPtr
txnhandle System.IntPtr
keyData byte
recordData byte
flags int
Résultat int
Exemple #1
0
        /// <summary>
        /// Inserts a Database Item
        /// </summary>
        /// <remarks>
        /// This method wraps the native ups_db_insert function.
        /// <br />
        /// This function inserts a key/record pair as a new Database item.
        /// <br />
        /// If the key already exists in the Database, error code
        /// <see cref="UpsConst.UPS_DUPLICATE_KEY" /> is thrown.
        /// <br />
        /// If you wish to overwrite an existing entry specify the flag
        /// <see cref="UpsConst.UPS_OVERWRITE"/>
        /// <br />
        /// If you wish to insert a duplicate key specify the flag
        /// <see cref="UpsConst.UPS_DUPLICATE" />. (Note that
        /// the Database has to be created with the flag
        /// <see cref="UpsConst.UPS_ENABLE_DUPLICATE_KEYS" /> in order
        /// to use duplicate keys.)
        /// The duplicate key is inserted after all other duplicate keys (see
        /// <see cref="UpsConst.UPS_DUPLICATE_INSERT_LAST" />).
        /// </remarks>
        /// <param name="txn">An optional Transaction object</param>
        /// <param name="key">The key of the new item</param>
        /// <param name="record">The record of the new item</param>
        /// <param name="flags">Optional flags for this operation. Possible
        /// flags are:
        /// <list type="bullet">
        ///   <item><see cref="UpsConst.UPS_OVERWRITE"/>
        ///     If the key already exists, the record is overwritten.
        ///     Otherwise, the key is inserted.</item>
        ///   <item><see cref="UpsConst.UPS_DUPLICATE"/>
        ///     If the key already exists, a duplicate key is inserted.
        ///     The key is inserted before the already existing duplicates.
        ///     </item>
        /// </list></param>
        /// <exception cref="DatabaseException">
        ///   <list type="bullet">
        ///   <item><see cref="UpsConst.UPS_INV_PARAMETER"/>
        ///     if the flags UpsConst.UPS_DUPLICATE <b>AND</b>
        ///     UpsConst.UPS_OVERWRITE were specified, or if
        ///     UpsConst.UPS_DUPLICATE was specified but the Database
        ///     was not created with UpsConst.UPS_ENABLE_DUPLICATE_KEYS</item>
        ///   <item><see cref="UpsConst.UPS_WRITE_PROTECTED"/>
        ///     if you tried to insert a key in a read-only Database</item>
        ///   <item><see cref="UpsConst.UPS_INV_KEYSIZE"/>
        ///     if key size is different than than the key size parameter
        ///     specified for Database.Create.</item>
        ///   </list>
        /// </exception>
        public void Insert(Transaction txn, byte[] key, byte[] record,
                           int flags)
        {
            int st;

            lock (this) {
                st = NativeMethods.Insert(handle,
                                          txn != null ? txn.Handle : IntPtr.Zero,
                                          key, record, flags);
            }
            if (st != 0)
            {
                throw new DatabaseException(st);
            }
        }