internal DB_LOCK lock_get(uint locker, uint flags, DBT arg2, db_lockmode_t mode) { int err = 0; DB_LOCK ret = lock_get(locker, flags, DatabaseEntry.fromDBT(arg2), mode, ref err); DatabaseException.ThrowException(err); return(ret); }
internal int get_key(DatabaseEntry key) { try { int ret; ret = libdb_csharpPINVOKE.DB_SEQUENCE_get_key(swigCPtr, DBT.getCPtr(DatabaseEntry.getDBT(key))); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(key); } }
private static int doRepTransport(IntPtr envp, IntPtr controlp, IntPtr recp, IntPtr lsnp, int envid, uint flags) { DB_ENV dbenv = new DB_ENV(envp, false); DBT control = new DBT(controlp, false); DBT rec = new DBT(recp, false); DB_LSN tmplsn = new DB_LSN(lsnp, false); LSN dblsn = new LSN(tmplsn.file, tmplsn.offset); return dbenv.api2_internal.transportHandler( DatabaseEntry.fromDBT(control), DatabaseEntry.fromDBT(rec), dblsn, envid, flags); }
internal int write(DatabaseEntry data, Int64 offset, uint flags) { try { int ret; ret = libdb_csharpPINVOKE.DB_STREAM_write(swigCPtr, DBT.getCPtr(DatabaseEntry.getDBT(data)), offset, flags); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(data); } }
internal int rep_start(DatabaseEntry cdata, uint flags) { try { int ret; ret = libdb_csharpPINVOKE.DB_ENV_rep_start(swigCPtr, DBT.getCPtr(DatabaseEntry.getDBT(cdata)), flags); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(cdata); } }
internal int exists(DB_TXN txn, DatabaseEntry key, uint flags) { try { int ret; ret = libdb_csharpPINVOKE.DB_exists(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), flags); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(key); } }
internal int put(DatabaseEntry key, DatabaseEntry data, uint flags) { try { int ret; ret = libdb_csharpPINVOKE.DBC_put(swigCPtr, DBT.getCPtr(DatabaseEntry.getDBT(key)), DBT.getCPtr(DatabaseEntry.getDBT(data)), flags); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(key); GC.KeepAlive(data); } }
internal int rep_process_message(DatabaseEntry control, DatabaseEntry rec, int envid, DB_LSN ret_lsnp) { try { int ret; ret = libdb_csharpPINVOKE.DB_ENV_rep_process_message(swigCPtr, DBT.getCPtr(DatabaseEntry.getDBT(control)), DBT.getCPtr(DatabaseEntry.getDBT(rec)), envid, DB_LSN.getCPtr(ret_lsnp)); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(control); GC.KeepAlive(rec); } }
internal int compact(DB_TXN txn, DatabaseEntry start, DatabaseEntry stop, DB_COMPACT cdata, uint flags, DatabaseEntry end) { try { int ret; ret = libdb_csharpPINVOKE.DB_compact(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(start)), DBT.getCPtr(DatabaseEntry.getDBT(stop)), DB_COMPACT.getCPtr(cdata), flags, DBT.getCPtr(DatabaseEntry.getDBT(end))); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(start); GC.KeepAlive(stop); GC.KeepAlive(end); } }
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)); }
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)); }
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)); }
internal int open(DB_TXN txn, DatabaseEntry key, uint flags) { try { int ret; ret = libdb_csharpPINVOKE.DB_SEQUENCE_open(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), flags); if (ret != 0) { close(0); } DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(key); } }
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; } }
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)); }
internal int key_range(DB_TXN txn, DatabaseEntry key, DB_KEY_RANGE range, uint flags) { try { int ret; ret = libdb_csharpPINVOKE.DB_key_range(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), DB_KEY_RANGE.getCPtr(range), flags); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(key); } }
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)); }
internal static HandleRef getCPtr(DBT obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(DBT obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.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)); }
internal DB_LOCK lock_get(uint locker, uint flags, DBT arg2, db_lockmode_t mode) { int err = 0; DB_LOCK ret = lock_get(locker, flags, DatabaseEntry.fromDBT(arg2), mode, ref err); DatabaseException.ThrowException(err); return ret; }
internal static HandleRef getCPtr(DBT obj) { return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr); }
internal int send_request(IntPtr[] request, uint nrequest, DatabaseEntry response, uint timeout, uint flags) { try { int ret; ret = libdb_csharpPINVOKE.DB_CHANNEL_send_request(swigCPtr, request, nrequest, DBT.getCPtr(DatabaseEntry.getDBT(response)).Handle, timeout, flags); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(response); } }
private DatabaseEntry(DBT dbtp) { dbt = dbtp; Data = (byte[])dbtp.data.Clone(); }
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; } }
/* * Copy between the C# byte array and the C library's void * as needed. * The library will call this method when it needs data from us or has * data to give us. This prevents us from needing to copy all data in * and all data out. The callback to this method gets set when the * DatabaseEnvironment is created (or the Database if created w/o an * environment.) */ internal static int dbt_usercopy(IntPtr dbtp, uint offset, IntPtr buf, uint size, uint flags) { DBT dbt = new DBT(dbtp, false); DatabaseEntry ent = dbt.app_data; if (flags == DbConstants.DB_USERCOPY_GETDATA) Marshal.Copy(ent.Data, 0, buf, (int)size); else { /* * If the offset is zero, we're writing a new buffer and can * simply allocate byte array. If the offset is not zero, * however, we are appending to the exisiting array. Since we * can't extend it, we have to allocate a new one and copy. * * Our caller is setting dbt.size, so set ent._data directly, * since ent.Data would overwrite dbt.size. */ if (offset != 0) { byte[] t = new byte[ent.Data.Length + (int)size]; ent.Data.CopyTo(t, 0); ent._data = t; } else ent._data = new byte[(int)size]; Marshal.Copy(buf, ent.Data, (int)offset, (int)size); } return 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)); }
internal static DatabaseEntry fromDBT(DBT dbt) { if (dbt.app_data != null) return dbt.app_data; else return new DatabaseEntry(dbt); }
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)); }
/// <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; }
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); }
private DB_LOCK lock_get(uint locker, uint flags, DatabaseEntry arg2, db_lockmode_t mode, ref int err) { try { DB_LOCK ret = new DB_LOCK(libdb_csharpPINVOKE.DB_ENV_lock_get(swigCPtr, locker, flags, DBT.getCPtr(DatabaseEntry.getDBT(arg2)), (int)mode, ref err), true); return(ret); } finally { GC.KeepAlive(arg2); } }
/// <summary> /// Create a new, empty DatabaseEntry object. /// </summary> public DatabaseEntry() { dbt = new DBT(); if (!this.GetType().IsGenericType) dbt.app_data = this; }
internal int log_put(DB_LSN lsn, DatabaseEntry data, uint flags) { try { int ret; ret = libdb_csharpPINVOKE.DB_ENV_log_put(swigCPtr, DB_LSN.getCPtr(lsn), DBT.getCPtr(DatabaseEntry.getDBT(data)), flags); DatabaseException.ThrowException(ret); return(ret); } finally { GC.KeepAlive(data); } }
/// <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; }
/// <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; }