示例#1
0
        private Database OpenDatabase(string file)
        {
            List<Parameter> list = new List<Parameter>();

            Parameter param1 = new Parameter();
            param1.name = UpsConst.UPS_PARAM_CACHESIZE;
            param1.value = 768 * 1024 * 1024;
            list.Add(param1);

            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            env.Open(file, 0, list.ToArray());
            db = env.OpenDatabase(1);
            db.SetCompareFunc(new CompareFunc(NumericalCompareFunc));
            return db;
        }
示例#2
0
        private void SetComparator()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            byte[] k = new byte[5];
            byte[] r = new byte[5];
            Parameter[] param = new Parameter[1];
            param[0] = new Parameter();
            param[0].name = UpsConst.UPS_PARAM_KEY_TYPE;
            param[0].value = UpsConst.UPS_TYPE_CUSTOM;

            compareCounter = 0;
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1, 0, param);
                db.SetCompareFunc(new CompareFunc(MyCompareFunc));
                db.Insert(k, r);
                k[0] = 1;
                db.Insert(k, r);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.Fail("unexpected exception " + e);
            }
            Assert.AreEqual(1, compareCounter);
        }
示例#3
0
        private void CreateWithParameters()
        {
            using (Upscaledb.Environment env = new Upscaledb.Environment())
            {
                env.Create("ntest.db");

                Parameter[] param = new Parameter[] {
                    new Parameter {
                        name = UpsConst.UPS_PARAM_KEYSIZE, value = 32
                    }
                };
                using (Database db = env.CreateDatabase(13, 0, param)) { }
            }
        }
示例#4
0
        private void Cursor10000Test()
        {
            //create database
            Upscaledb.Environment env = new Upscaledb.Environment();
            env.Create("ntest.db");

            Parameter[] param = new Parameter[1];
            param[0] = new Parameter();
            param[0].name = UpsConst.UPS_PARAM_KEY_TYPE;
            param[0].value = UpsConst.UPS_TYPE_UINT64;
            Database db = env.CreateDatabase(1, 0, param);

            //insert records
            for (ulong i = 0; i < 10000; i++)
            {
                byte[] key = BitConverter.GetBytes(i);
                byte[] record = new byte[20];
                db.Insert(key, record);
            }

            //close database
            db.Close();

            //reopen again
            db = env.OpenDatabase(1);
            Cursor cursor = new Cursor(db);

            cursor.MoveFirst();
            ulong firstKey = BitConverter.ToUInt64(cursor.GetKey(), 0);
            Assert.AreEqual((ulong)0, firstKey);

            cursor.MoveLast();
            ulong lastKey = BitConverter.ToUInt64(cursor.GetKey(), 0);
            Assert.AreEqual((ulong)9999, lastKey);

            //close database
            cursor.Close();
            db.Close();
            env.Close();
        }
示例#5
0
 private void CreateStringIntIntParameter()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     Parameter[] param = new Parameter[1];
     param[0] = new Parameter();
     param[0].name = UpsConst.UPS_PARAM_CACHESIZE;
     param[0].value = 1024;
     try {
         env.Create("ntest.db", 0, 0644, param);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.Fail("Unexpected exception " + e);
     }
 }
示例#6
0
 private void CreateStringIntIntParameterNeg()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     Parameter[] param = new Parameter[1];
     param[0] = new Parameter();
     param[0].name = UpsConst.UPS_PARAM_CACHESIZE;
     param[0].value = 1024;
     try {
         env.Create("ntest.db", UpsConst.UPS_IN_MEMORY, 0644, param);
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
 }
示例#7
0
 private static Parameter[] AppendNullParameter(Parameter[] parameters)
 {
     Parameter[] newArray = new Parameter[parameters.GetLength(0) + 1];
       for (int i = 0; i < parameters.GetLength(0); i++)
     newArray[i] = parameters[i];
       return newArray;
 }
示例#8
0
 private void CreateInvalidParameter()
 {
     Upscaledb.Environment env = new Upscaledb.Environment();
     Database db = new Database();
     Parameter[] param = new Parameter[3];
     param[1] = new Parameter();
     param[2] = new Parameter();
     try {
         env.Create("ntest.db");
         db = env.CreateDatabase(1, 0, param);
         db.Close();
         env.Close();
     }
     catch (DatabaseException e) {
         Assert.AreEqual(UpsConst.UPS_INV_PARAMETER, e.ErrorCode);
     }
 }
示例#9
0
        /// <summary>
        /// Opens a Database in this Environment
        /// </summary>
        /// <remarks>
        /// This method wraps the native ups_env_open_db function.
        /// </remarks>
        /// <param name="name">The name of the Database. If a Database
        /// with this name does not exist, the function will throw
        /// <see cref="UpsConst.UPS_DATABASE_NOT_FOUND"/>.</param>
        /// <param name="flags">Optional flags for this operation, combined
        /// with bitwise OR. Possible flags are:
        ///   <list type="bullet">
        ///   <item><see cref="UpsConst.UPS_READ_ONLY" />
        ///     Opens the database for reading.</item>
        ///   </list>
        /// </param>
        /// <param name="parameters">An array of <see cref="Parameter" />
        /// structures. The following parameters are available:<br />
        ///   <list type="bullet">
        ///   </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_NOT_FOUND"/>
        ///     if a Database with this name does not exist</item>
        ///   <item><see cref="UpsConst.UPS_DATABASE_ALREADY_OPEN"/>
        ///     if this Database was already opened</item>
        ///   <item><see cref="UpsConst.UPS_OUT_OF_MEMORY"/>
        ///     if memory could not be allocated</item>
        ///   <item><see cref="UpsConst.UPS_WOULD_BLOCK"/>
        ///     if another process has locked the file</item>
        ///   </list>
        /// </exception>
        /// <returns>The new Database object</returns>
        public Database OpenDatabase(short name, int flags,
        Parameter[] parameters)
        {
            int st;
              IntPtr dbh = new IntPtr(0);
              if (parameters != null)
            parameters = AppendNullParameter(parameters);
              lock (this) {
            st = NativeMethods.EnvOpenDatabase(handle, out dbh,
            name, flags, parameters);
              }
              if (st != 0)
            throw new DatabaseException(st);

              Database db = new Database(dbh);
              databases.Add(db);
              return db;
        }
示例#10
0
 /// <summary>
 /// Opens an existing Environment
 /// </summary>
 /// <remarks>
 /// This method wraps the native ups_env_open function.
 /// </remarks>
 ///
 /// <param name="fileName">The file name of the Environment file.</param>
 /// <param name="flags">Optional flags for this operation, combined
 /// with bitwise OR. Possible flags are:
 ///   <list type="bullet">
 ///   <item><see cref="UpsConst.UPS_READ_ONLY" />
 ///     Opens the file for reading only. Operations which need
 ///     write access (i.e. Database.Insert)
 ///     will return <see cref="UpsConst.UPS_WRITE_PROTECTED" />.
 ///     </item><br />
 ///   <item><see cref="UpsConst.UPS_ENABLE_FSYNC" />
 ///     Immediately write modified pages to the disk. This
 ///     slows down all Database operations, but may save the
 ///     Database integrity in case of a system crash.</item><br />
 ///   <item><see cref="UpsConst.UPS_DISABLE_MMAP" />
 ///     Do not use memory mapped files for I/O. By default,
 ///     upscaledb checks if it can use mmap, since mmap is faster
 ///     than read/write. For performance reasons, this flag should
 ///     not be used.</item><br />
 ///   <item><see cref="UpsConst.UPS_ENABLE_RECOVERY" />
 ///     Enables logging/recovery for this Database. Will return
 ///     <see cref="UpsConst.UPS_NEED_RECOVERY" />, if the
 ///     Database is in an inconsistent state. Not allowed in
 ///     combination with <see cref="UpsConst.UPS_IN_MEMORY" />,
 ///     <see cref="UpsConst.UPS_DISABLE_FREELIST_FLUSH" /> and
 ///     <see cref="UpsConst.UPS_ENABLE_FSYNC" />.</item><br />
 ///   <item><see cref="UpsConst.UPS_AUTO_RECOVERY" />
 ///     Automatically recover the Database, if necessary. This
 ///     flag imples <see cref="UpsConst.UPS_ENABLE_RECOVERY" />.
 ///     </item><br />
 ///   <item><see cref="UpsConst.UPS_ENABLE_TRANSACTIONS" />
 ///     Enables Transactions for this Database. This flag implies
 ///     <see cref="UpsConst.UPS_ENABLE_RECOVERY" />.</item><br />
 ///   </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_CACHESIZE" />
 ///     The size of the Database cache, in bytes. The default size
 ///     is defined in <i>src/config.h</i> as UPS_DEFAULT_CACHESIZE
 ///     - usually 2 MB.</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_FILE_NOT_FOUND"/>
 ///     if the file does not exist</item>
 ///   <item><see cref="UpsConst.UPS_IO_ERROR"/>
 ///     if the file could not be opened or reading/writing failed</item>
 ///   <item><see cref="UpsConst.UPS_INV_FILE_VERSION"/>
 ///     if the Database version is not compatible with the library
 ///     version</item>
 ///   <item><see cref="UpsConst.UPS_OUT_OF_MEMORY"/>
 ///     if memory could not be allocated</item>
 ///   <item><see cref="UpsConst.UPS_WOULD_BLOCK"/>
 ///     if another process has locked the file</item>
 ///   </list>
 /// </exception>
 public void Open(String fileName, int flags,
 Parameter[] parameters)
 {
     int st;
       handle = new IntPtr(0);
       if (parameters != null)
     parameters = AppendNullParameter(parameters);
       lock (this) {
     st = NativeMethods.EnvOpen(out handle, fileName, flags,
       parameters);
       }
       if (st != 0)
     throw new DatabaseException(st);
 }
示例#11
0
 public static extern int EnvOpenDatabase(IntPtr handle,
 out IntPtr dbhandle, short name, int flags,
 Parameter[] parameters);
示例#12
0
 public static extern int EnvOpen(out IntPtr handle, String fileName,
 int flags, Parameter[] parameters);
示例#13
0
 public static extern int EnvCreate(out IntPtr handle, String fileName,
 int flags, int mode, Parameter[] parameters);