Beispiel #1
0
 /// <summary>
 /// Create a new database object with the same underlying DB handle as
 /// <paramref name="clone"/>.  Used during Database.Open to get an
 /// object of the correct DBTYPE.
 /// </summary>
 /// <param name="clone">Database to clone</param>
 protected BaseDatabase(BaseDatabase clone) {
     db = clone.db;
     clone.db = null;
     db.api_internal = this;
     env = clone.env;
     clone.env = null;
 }
Beispiel #2
0
Datei: DB.cs Projekt: mcandre/db
 internal int associate(DB_TXN txn, DB sec, BDB_AssociateDelegate callback, uint flags)
 {
     int ret;
     ret = libdb_csharpPINVOKE.DB_associate(swigCPtr, DB_TXN.getCPtr(txn), DB.getCPtr(sec), callback, flags);
     DatabaseException.ThrowException(ret);
     return ret;
 }
Beispiel #3
0
Datei: DB.cs Projekt: mcandre/db
 internal int associate_foreign(DB dbp, BDB_AssociateForeignDelegate callback, uint flags)
 {
     int ret;
     ret = libdb_csharpPINVOKE.DB_associate_foreign(swigCPtr, DB.getCPtr(dbp), callback, flags);
     DatabaseException.ThrowException(ret);
     return ret;
 }
Beispiel #4
0
 /// <summary>
 /// Protected constructor
 /// </summary>
 /// <param name="envp">
 /// The environment in which to create this database
 /// </param>
 /// <param name="flags">Flags to pass to the DB->create() method</param>
 protected BaseDatabase(DatabaseEnvironment envp, uint flags) {
     db = new DB(envp == null ? null : envp.dbenv, flags);
     db.api_internal = this;
     if (envp == null) {
         env = new DatabaseEnvironment(db.env());
     } else
         env = envp;
 }
        private static int doDupCompare(
            IntPtr dbp, IntPtr dbt1p, IntPtr dbt2p, IntPtr locp)
        {
            DB db = new DB(dbp, false);
            DBT dbt1 = new DBT(dbt1p, false);
            DBT dbt2 = new DBT(dbt2p, false);
            if (locp != IntPtr.Zero)
                locp = IntPtr.Zero;

            return ((SecondaryBTreeDatabase)(db.api_internal)).DupCompare(
                DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
        }
 private static uint doPrefixCompare(
     IntPtr dbp, IntPtr dbtp1, IntPtr dbtp2)
 {
     DB db = new DB(dbp, false);
     DBT dbt1 = new DBT(dbtp1, false);
     DBT dbt2 = new DBT(dbtp2, false);
     SecondaryBTreeDatabase tmp =
                     (SecondaryBTreeDatabase)db.api_internal;
     return tmp.prefixCompareHandler(
         DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
 }
        private static uint doHash(IntPtr dbp, IntPtr datap, uint len)
        {
            DB db = new DB(dbp, false);
            byte[] t_data = new byte[len];
            Marshal.Copy(datap, t_data, 0, (int)len);

            SecondaryHashDatabase tmp = (SecondaryHashDatabase)db.api_internal;
            return tmp.HashFunction(t_data);
        }
 private static int doCompare(IntPtr dbp,
     IntPtr dbtp1, IntPtr dbtp2, IntPtr locp)
 {
     DB db = new DB(dbp, false);
     DBT dbt1 = new DBT(dbtp1, false);
     DBT dbt2 = new DBT(dbtp2, false);
     if (locp != IntPtr.Zero)
         locp = IntPtr.Zero;
     SecondaryBTreeDatabase tmp =
         (SecondaryBTreeDatabase)db.api_internal;
     return tmp.compareHandler(
         DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
 }
 private static int doCompare(IntPtr dbp, 
     IntPtr dbtp1, IntPtr dbtp2, IntPtr locp)
 {
     DB db = new DB(dbp, false);
     DBT dbt1 = new DBT(dbtp1, false);
     DBT dbt2 = new DBT(dbtp2, false);
     if (locp != IntPtr.Zero)
         locp = IntPtr.Zero;
     BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
     return btdb.Compare(
         DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
 }
Beispiel #10
0
        private static int doDupCompare(
            IntPtr dbp, IntPtr dbt1p, IntPtr dbt2p)
        {
            DB db = new DB(dbp, false);
            DBT dbt1 = new DBT(dbt1p, false);
            DBT dbt2 = new DBT(dbt2p, false);

            BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
            return btdb.DupCompare(
                DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
        }
Beispiel #11
0
 internal DB_SEQUENCE(DB dbp, uint flags) : this(libdb_csharpPINVOKE.new_DB_SEQUENCE(DB.getCPtr(dbp), flags), true)
 {
 }
Beispiel #12
0
 internal DB_SEQUENCE(DB dbp, uint flags)
     : this(libdb_csharpPINVOKE.new_DB_SEQUENCE(DB.getCPtr(dbp), flags), true)
 {
 }
Beispiel #13
0
        private static uint doHash(IntPtr dbp, IntPtr datap, uint len)
        {
            DB db = new DB(dbp, false);
            byte[] t_data = new byte[len];
            Marshal.Copy(datap, t_data, 0, (int)len);

            return ((HashDatabase)(db.api_internal)).hashHandler(t_data);
        }
 private static void doFeedback(IntPtr dbp, int opcode, int percent)
 {
     DB db = new DB(dbp, false);
     db.api_internal.Feedback((DatabaseFeedbackEvent)opcode, percent);
 }
Beispiel #15
0
        private static int doCompare(IntPtr dbp, IntPtr dbtp1, IntPtr dbtp2)
        {
            DB db = new DB(dbp, false);
            DBT dbt1 = new DBT(dbtp1, false);
            DBT dbt2 = new DBT(dbtp2, false);

            return ((HashDatabase)(db.api_internal)).compareHandler(
                DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
        }
Beispiel #16
0
        /// <summary>
        /// Protected method to call the key generation function.
        /// </summary>
        /// <param name="dbp">Secondary DB Handle</param>
        /// <param name="keyp">Primary Key</param>
        /// <param name="datap">Primary Data</param>
        /// <param name="skeyp">Scondary Key</param>
        /// <returns>0 on success, !0 on failure</returns>
        protected static int doAssociate(
            IntPtr dbp, IntPtr keyp, IntPtr datap, IntPtr skeyp)
        {
            DB db = new DB(dbp, false);
            DBT key = new DBT(keyp, false);
            DBT data = new DBT(datap, false);
            DBT skey = new DBT(skeyp, false);

            DatabaseEntry s =
                ((SecondaryDatabase)db.api_internal).KeyGen(
                DatabaseEntry.fromDBT(key), DatabaseEntry.fromDBT(data));

            if (s == null)
                return DbConstants.DB_DONOTINDEX;

            skey.data = s.Data;
            return 0;
        }
Beispiel #17
0
 private static uint doPartition(IntPtr dbp, IntPtr dbtp)
 {
     DB db = new DB(dbp, false);
     DatabaseEntry dbt = DatabaseEntry.fromDBT(new DBT(dbtp, false));
     BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
     return btdb.Partition(dbt);
 }
Beispiel #18
0
        private static void doAppend(IntPtr dbp, IntPtr dbtp1, uint recno)
        {
            DB db = new DB(dbp, false);
            DBT dbt1 = new DBT(dbtp1, false);
            RecnoDatabase rdb = (RecnoDatabase)(db.api_internal);

            rdb.AppendCallback(DatabaseEntry.fromDBT(dbt1), recno);
        }
        /// <summary>
        /// Protected method to nullify a foreign key
        /// </summary>
        /// <param name="dbp">Secondary DB Handle</param>
        /// <param name="keyp">Primary Key</param>
        /// <param name="datap">Primary Data</param>
        /// <param name="fkeyp">Foreign Key</param>
        /// <param name="changed">Whether the foreign key has changed</param>
        /// <returns>0 on success, !0 on failure</returns>
        protected static int doNullify(IntPtr dbp,
            IntPtr keyp, IntPtr datap, IntPtr fkeyp, ref int changed) {
            DB db = new DB(dbp, false);
            DBT key = new DBT(keyp, false);
            DBT data = new DBT(datap, false);
            DBT fkey = new DBT(fkeyp, false);

            DatabaseEntry d = ((SecondaryDatabase)db.api_internal).Nullifier(
                DatabaseEntry.fromDBT(key),
                DatabaseEntry.fromDBT(data), DatabaseEntry.fromDBT(fkey));

            if (d == null)
                changed = 0;
            else {
                changed = 1;
                data.data = d.Data;
            }

            return 0;
        }
Beispiel #20
0
Datei: DB.cs Projekt: mcandre/db
 internal static HandleRef getCPtr(DB obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
        private static int doDupCompare(
            IntPtr dbp, IntPtr dbt1p, IntPtr dbt2p)
        {
            DB db = new DB(dbp, false);
            DBT dbt1 = new DBT(dbt1p, false);
            DBT dbt2 = new DBT(dbt2p, false);

            SecondaryHashDatabase tmp = (SecondaryHashDatabase)db.api_internal;
            return tmp.DupCompare(
                DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
        }
Beispiel #22
0
 private static uint doPrefixCompare(
     IntPtr dbp, IntPtr dbtp1, IntPtr dbtp2)
 {
     DB db = new DB(dbp, false);
     DBT dbt1 = new DBT(dbtp1, false);
     DBT dbt2 = new DBT(dbtp2, false);
     BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
     return btdb.PrefixCompare(
         DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
 }
Beispiel #23
0
 private static void doMsgFeedback(IntPtr dbp, string msg)
 {
     DB db = new DB(dbp, false);
     db.api_internal.msgFeedbackHandler(msg);
 }
        /// <summary>
        /// Protected method to call the key generation function.
        /// </summary>
        /// <param name="dbp">Secondary DB Handle</param>
        /// <param name="keyp">Primary Key</param>
        /// <param name="datap">Primary Data</param>
        /// <param name="skeyp">Scondary Key</param>
        /// <returns>0 on success, !0 on failure</returns>
        protected static int doAssociate(
            IntPtr dbp, IntPtr keyp, IntPtr datap, IntPtr skeyp) {
            DB db = new DB(dbp, false);
            DBT key = new DBT(keyp, false);
            DBT data = new DBT(datap, false);
            DBT skey = new DBT(skeyp, false);
            IntPtr dataPtr, sdataPtr;
            int nrecs, dbt_sz;

            DatabaseEntry s =
                ((SecondaryDatabase)db.api_internal).KeyGen(
                DatabaseEntry.fromDBT(key), DatabaseEntry.fromDBT(data));

            if (s == null)
                return DbConstants.DB_DONOTINDEX;
            if (s is MultipleDatabaseEntry) {
                MultipleDatabaseEntry mde = (MultipleDatabaseEntry)s;
                nrecs = mde.nRecs;
                /* 
                 * Allocate an array of nrecs DBT in native memory.  The call 
                 * returns sizeof(DBT), so that we know where one DBT ends and 
                 * the next begins.
                 */
                dbt_sz = (int)libdb_csharp.alloc_dbt_arr(null, nrecs, out sdataPtr);
                /* 
                 * We need a managed array to copy each DBT into and then we'll
                 * copy the managed array to the native array we just allocated.
                 * We are not able to copy native -> native.
                 */
                byte[] arr = new byte[nrecs * dbt_sz];
                IntPtr p;
                int off = 0;
                /* Copy each DBT into the array. */
                foreach (DatabaseEntry dbt in mde) {
                    /* Allocate room for the data in native memory. */
                    dataPtr = libdb_csharp.__os_umalloc(null, dbt.size);
                    Marshal.Copy(dbt.Data, 0, dataPtr, (int)dbt.size);
                    dbt.dbt.dataPtr = dataPtr;
                    dbt.flags |= DbConstants.DB_DBT_APPMALLOC;

                    p = DBT.getCPtr(DatabaseEntry.getDBT(dbt)).Handle;
                    Marshal.Copy(p, arr, off, dbt_sz);
                    off += dbt_sz;
                }
                Marshal.Copy(arr, 0, sdataPtr, nrecs * dbt_sz);
                skey.dataPtr = sdataPtr;
                skey.size = (uint)mde.nRecs;
                skey.flags = DbConstants.DB_DBT_MULTIPLE | DbConstants.DB_DBT_APPMALLOC;
            } else
                skey.data = s.Data;
            return 0;
        }
Beispiel #25
0
 private static int doCompress(IntPtr dbp, IntPtr prevKeyp,
     IntPtr prevDatap, IntPtr keyp, IntPtr datap, IntPtr destp)
 {
     DB db = new DB(dbp, false);
     DatabaseEntry prevKey =
         DatabaseEntry.fromDBT(new DBT(prevKeyp, false));
     DatabaseEntry prevData =
         DatabaseEntry.fromDBT(new DBT(prevDatap, false));
     DatabaseEntry key = DatabaseEntry.fromDBT(new DBT(keyp, false));
     DatabaseEntry data = DatabaseEntry.fromDBT(new DBT(datap, false));
     DBT dest = new DBT(destp, false);
     BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
     byte[] arr = new byte[(int)dest.ulen];
     int len;
     try {
         if (btdb.Compress(prevKey, prevData, key, data, ref arr, out len)) {
             Marshal.Copy(arr, 0, dest.dataPtr, len);
             dest.size = (uint)len;
             return 0;
         } else {
             return DbConstants.DB_BUFFER_SMALL;
         }
     } catch (Exception) {
         return -1;
     }
 }
 internal static SecondaryDatabase fromDB(DB dbp) {
     try {
         return (SecondaryDatabase)dbp.api_internal;
     } catch { }
     return null;
 }
Beispiel #27
0
 private static int doDecompress(IntPtr dbp, IntPtr prevKeyp,
     IntPtr prevDatap, IntPtr cmpp, IntPtr destKeyp, IntPtr destDatap)
 {
     DB db = new DB(dbp, false);
     DatabaseEntry prevKey =
         DatabaseEntry.fromDBT(new DBT(prevKeyp, false));
     DatabaseEntry prevData =
         DatabaseEntry.fromDBT(new DBT(prevDatap, false));
     DBT compressed = new DBT(cmpp, false);
     DBT destKey = new DBT(destKeyp, false);
     DBT destData = new DBT(destDatap, false);
     BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
     uint size;
     try {
         KeyValuePair<DatabaseEntry, DatabaseEntry> kvp = btdb.Decompress(prevKey, prevData, compressed.data, out size);
         int keylen = kvp.Key.Data.Length;
         int datalen = kvp.Value.Data.Length;
         destKey.size = (uint)keylen;
         destData.size = (uint)datalen;
         if (keylen > destKey.ulen ||
             datalen > destData.ulen)
             return DbConstants.DB_BUFFER_SMALL;
         Marshal.Copy(kvp.Key.Data, 0, destKey.dataPtr, keylen);
         Marshal.Copy(kvp.Value.Data, 0, destData.dataPtr, datalen);
         compressed.size = size;
         return 0;
     } catch (Exception) {
         return -1;
     }
 }