EnvCreateDatabase() private method

private EnvCreateDatabase ( IntPtr handle, IntPtr &dbhandle, short name, int flags, Parameter parameters ) : int
handle System.IntPtr
dbhandle System.IntPtr
name short
flags int
parameters Parameter
return int
Beispiel #1
0
        /// <summary>
        /// Creates a new Database in this Environment
        /// </summary>
        /// <remarks>This method wraps the native ups_env_create_db function.
        /// </remarks>
        /// <returns>The new Database object</returns>
        /// <param name="name">The name of the Database. If a Database
        /// with this name already exists,
        /// <see cref="UpsConst.UPS_DATABASE_ALREADY_EXISTS"/> is thrown.
        /// Database names from 0xf000 to 0xffff and 0 are reserved.</param>
        /// <param name="flags">Optional flags for creating the Database,
        /// combined with bitwise OR. Possible values are:
        ///   <list>
        ///   <item><see cref="UpsConst.UPS_RECORD_NUMBER" />
        ///     Creates an "auto-increment" Database. Keys in Record
        ///     Number Databases are automatically assigned an incrementing
        ///     64bit value.</item>
        ///   </list>
        /// </param>
        /// <param name="parameters">An array of <see cref="Parameter" />
        /// structures. The following parameters are available:<br />
        ///   <list type="bullet">
        ///   <item><see cref="UpsConst.UPS_PARAM_KEYSIZE" />
        ///     The size of the keys in the B+Tree index. The default size
        ///     is 21 bytes.</item><br />
        ///   </list>
        /// </param>
        /// <exception cref="DatabaseException">
        ///   <list type="bullet">
        ///   <item><see cref="UpsConst.UPS_INV_PARAMETER"/>
        ///     if an invalid combination of flags was specified</item>
        ///   <item><see cref="UpsConst.UPS_DATABASE_ALREADY_EXISTS"/>
        ///     if a Database with this name already exists in this
        ///     Environment</item>
        ///   <item><see cref="UpsConst.UPS_OUT_OF_MEMORY"/>
        ///     if memory could not be allocated</item>
        ///   <item><see cref="UpsConst.UPS_INV_KEYSIZE"/>
        ///     if the key size is too large (at least 4 keys must
        ///     fit in a page)</item>
        ///   <item><see cref="UpsConst.UPS_LIMITS_REACHED"/>
        ///     if the maximum number of Databases per Environment
        ///     was already created</item>
        ///   </list>
        /// </exception>
        /// <returns>The new Database object</returns>
        public Database CreateDatabase(short name, int flags,
                                       Parameter[] parameters)
        {
            int    st;
            IntPtr dbh = new IntPtr(0);

            if (parameters != null)
            {
                parameters = AppendNullParameter(parameters);
            }
            lock (this) {
                st = NativeMethods.EnvCreateDatabase(handle, out dbh,
                                                     name, flags, parameters);
            }
            if (st != 0)
            {
                throw new DatabaseException(st);
            }

            Database db = new Database(dbh);

            databases.Add(db);
            return(db);
        }