1/* ----------------------------------------------------------------------------
2 * This file was automatically generated by SWIG (http://www.swig.org).
3 * Version 1.3.38
4 *
5 * Do not make changes to this file unless you know what you are doing--modify
6 * the SWIG interface file instead.
7 * ----------------------------------------------------------------------------- */
8
9namespace BerkeleyDB.Internal {
10
11using System;
12using System.Runtime.InteropServices;
13
14internal class DB : IDisposable {
15  private HandleRef swigCPtr;
16  protected bool swigCMemOwn;
17
18  internal DB(IntPtr cPtr, bool cMemoryOwn) {
19    swigCMemOwn = cMemoryOwn;
20    swigCPtr = new HandleRef(this, cPtr);
21  }
22
23  internal static HandleRef getCPtr(DB obj) {
24    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
25  }
26
27  public virtual void Dispose()  {
28    lock(this) {
29      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
30        swigCMemOwn = false;
31      }
32      swigCPtr = new HandleRef(null, IntPtr.Zero);
33      GC.SuppressFinalize(this);
34    }
35}
36
37	internal DBC cursor(DB_TXN txn, uint flags) {
38		int err = 0;
39		DBC ret = cursor(txn, flags, ref err);
40		DatabaseException.ThrowException(err);
41		return ret;
42	}
43
44	internal DBC join(IntPtr[] curslist, uint flags) {
45		int err = 0;
46		DBC ret = join(curslist, flags, ref err);
47		DatabaseException.ThrowException(err);
48		return ret;
49	}
50
51	internal BTreeStatStruct stat_bt(DB_TXN txn, uint flags) {
52		int err = 0;
53		IntPtr ptr = stat(txn, flags, ref err);
54		DatabaseException.ThrowException(err);
55		BTreeStatStruct ret = (BTreeStatStruct)Marshal.PtrToStructure(ptr, typeof(BTreeStatStruct));
56		libdb_csharp.__os_ufree(null, ptr);
57		return ret;
58	}
59	internal HashStatStruct stat_hash(DB_TXN txn, uint flags) {
60		int err = 0;
61		IntPtr ptr = stat(txn, flags, ref err);
62		DatabaseException.ThrowException(err);
63		HashStatStruct ret = (HashStatStruct)Marshal.PtrToStructure(ptr, typeof(HashStatStruct));
64		libdb_csharp.__os_ufree(null, ptr);
65		return ret;
66	}
67	internal QueueStatStruct stat_qam(DB_TXN txn, uint flags) {
68		int err = 0;
69		IntPtr ptr = stat(txn, flags, ref err);
70		DatabaseException.ThrowException(err);
71		QueueStatStruct ret = (QueueStatStruct)Marshal.PtrToStructure(ptr, typeof(QueueStatStruct));
72		libdb_csharp.__os_ufree(null, ptr);
73		return ret;
74	}
75
76  internal BaseDatabase api_internal {
77    set {
78      libdb_csharpPINVOKE.DB_api_internal_set(swigCPtr, value);
79    }
80		get { return libdb_csharpPINVOKE.DB_api_internal_get(swigCPtr); }
81
82  }
83
84  internal int set_usercopy(DBTCopyDelegate dbt_usercopy) {
85		int ret;
86		ret = libdb_csharpPINVOKE.DB_set_usercopy(swigCPtr, dbt_usercopy);
87		DatabaseException.ThrowException(ret);
88		return ret;
89}
90
91  internal DB(DB_ENV env, uint flags) : this(libdb_csharpPINVOKE.new_DB(DB_ENV.getCPtr(env), flags), true) {
92  }
93
94  internal int associate(DB_TXN txn, DB sec, BDB_AssociateDelegate callback, uint flags) {
95		int ret;
96		ret = libdb_csharpPINVOKE.DB_associate(swigCPtr, DB_TXN.getCPtr(txn), DB.getCPtr(sec), callback, flags);
97		DatabaseException.ThrowException(ret);
98		return ret;
99}
100
101  internal int associate_foreign(DB dbp, BDB_AssociateForeignDelegate callback, uint flags) {
102		int ret;
103		ret = libdb_csharpPINVOKE.DB_associate_foreign(swigCPtr, DB.getCPtr(dbp), callback, flags);
104		DatabaseException.ThrowException(ret);
105		return ret;
106}
107
108  internal int close(uint flags) {
109		int ret = libdb_csharpPINVOKE.DB_close(swigCPtr, flags);
110		if (ret == 0)
111			/* Close is a db handle destructor.  Reflect that in the wrapper class. */
112			swigCPtr = new HandleRef(null, IntPtr.Zero);
113		else
114			DatabaseException.ThrowException(ret);
115		return ret;
116}
117
118  internal int compact(DB_TXN txn, DatabaseEntry start, DatabaseEntry stop, DB_COMPACT cdata, uint flags, DatabaseEntry end) {
119    try {
120		int ret;
121		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)));
122		DatabaseException.ThrowException(ret);
123		return ret;
124} finally {
125      GC.KeepAlive(start);
126      GC.KeepAlive(stop);
127      GC.KeepAlive(end);
128    }
129  }
130
131  private DBC cursor(DB_TXN txn, uint flags, ref int err) {
132    IntPtr cPtr = libdb_csharpPINVOKE.DB_cursor(swigCPtr, DB_TXN.getCPtr(txn), flags, ref err);
133    DBC ret = (cPtr == IntPtr.Zero) ? null : new DBC(cPtr, false);
134    return ret;
135  }
136
137  internal int del(DB_TXN txn, DatabaseEntry key, uint flags) {
138    try {
139		int ret;
140		ret = libdb_csharpPINVOKE.DB_del(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), flags);
141		DatabaseException.ThrowException(ret);
142		return ret;
143} finally {
144      GC.KeepAlive(key);
145    }
146  }
147
148  internal DB_ENV env() {
149    IntPtr cPtr = libdb_csharpPINVOKE.DB_env(swigCPtr);
150    DB_ENV ret = (cPtr == IntPtr.Zero) ? null : new DB_ENV(cPtr, false);
151    return ret;
152  }
153
154  internal int exists(DB_TXN txn, DatabaseEntry key, uint flags) {
155    try {
156		int ret;
157		ret = libdb_csharpPINVOKE.DB_exists(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), flags);
158		DatabaseException.ThrowException(ret);
159		return ret;
160} finally {
161      GC.KeepAlive(key);
162    }
163  }
164
165  internal int get(DB_TXN txn, DatabaseEntry key, DatabaseEntry data, uint flags) {
166    try {
167		int ret;
168		ret = libdb_csharpPINVOKE.DB_get(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), DBT.getCPtr(DatabaseEntry.getDBT(data)), flags);
169		DatabaseException.ThrowException(ret);
170		return ret;
171} finally {
172      GC.KeepAlive(key);
173      GC.KeepAlive(data);
174    }
175  }
176
177  internal int get_byteswapped(ref int isswapped) {
178		int ret;
179		ret = libdb_csharpPINVOKE.DB_get_byteswapped(swigCPtr, ref isswapped);
180		DatabaseException.ThrowException(ret);
181		return ret;
182}
183
184  internal int get_dbname(ref string filenamep, ref string dbnamep) {
185		int ret;
186		ret = libdb_csharpPINVOKE.DB_get_dbname(swigCPtr, ref filenamep, ref dbnamep);
187		DatabaseException.ThrowException(ret);
188		return ret;
189}
190
191  internal int get_multiple() {
192		return libdb_csharpPINVOKE.DB_get_multiple(swigCPtr);
193}
194
195  internal int get_open_flags(ref uint flags) {
196		int ret;
197		ret = libdb_csharpPINVOKE.DB_get_open_flags(swigCPtr, ref flags);
198		DatabaseException.ThrowException(ret);
199		return ret;
200}
201
202  internal int get_transactional() {
203		return libdb_csharpPINVOKE.DB_get_transactional(swigCPtr);
204}
205
206  internal int get_type(ref DBTYPE type) {
207		int ret;
208		ret = libdb_csharpPINVOKE.DB_get_type(swigCPtr, ref type);
209		DatabaseException.ThrowException(ret);
210		return ret;
211}
212
213  private DBC join(IntPtr[] curslist, uint flags, ref int err) {
214    IntPtr cPtr = libdb_csharpPINVOKE.DB_join(swigCPtr, curslist, flags, ref err);
215    DBC ret = (cPtr == IntPtr.Zero) ? null : new DBC(cPtr, false);
216    return ret;
217  }
218
219  internal int key_range(DB_TXN txn, DatabaseEntry key, DB_KEY_RANGE range, uint flags) {
220    try {
221		int ret;
222		ret = libdb_csharpPINVOKE.DB_key_range(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), DB_KEY_RANGE.getCPtr(range), flags);
223		DatabaseException.ThrowException(ret);
224		return ret;
225} finally {
226      GC.KeepAlive(key);
227    }
228  }
229
230  internal int open(DB_TXN txn, string file, string database, DBTYPE type, uint flags, int mode) {
231	int ret;
232	ret = libdb_csharpPINVOKE.DB_open(swigCPtr, DB_TXN.getCPtr(txn), file, database, (int)type, flags, mode);
233	if (ret != 0)
234		close(0);
235	DatabaseException.ThrowException(ret);
236	return ret;
237}
238
239  internal int pget(DB_TXN txn, DatabaseEntry key, DatabaseEntry pkey, DatabaseEntry data, uint flags) {
240    try {
241		int ret;
242		ret = libdb_csharpPINVOKE.DB_pget(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), DBT.getCPtr(DatabaseEntry.getDBT(pkey)), DBT.getCPtr(DatabaseEntry.getDBT(data)), flags);
243		DatabaseException.ThrowException(ret);
244		return ret;
245} finally {
246      GC.KeepAlive(key);
247      GC.KeepAlive(pkey);
248      GC.KeepAlive(data);
249    }
250  }
251
252  internal int put(DB_TXN txn, DatabaseEntry key, DatabaseEntry data, uint flags) {
253    try {
254		int ret;
255		ret = libdb_csharpPINVOKE.DB_put(swigCPtr, DB_TXN.getCPtr(txn), DBT.getCPtr(DatabaseEntry.getDBT(key)), DBT.getCPtr(DatabaseEntry.getDBT(data)), flags);
256		DatabaseException.ThrowException(ret);
257		return ret;
258} finally {
259      GC.KeepAlive(key);
260      GC.KeepAlive(data);
261    }
262  }
263
264  internal int remove(string file, string database, uint flags) {
265	int ret;
266	ret = libdb_csharpPINVOKE.DB_remove(swigCPtr, file, database, flags);
267	/*
268	 * remove is a handle destructor, regardless of whether the remove
269	 * succeeds.  Reflect that in the wrapper class.
270	 */
271	swigCPtr = new HandleRef(null, IntPtr.Zero);
272	DatabaseException.ThrowException(ret);
273	return ret;
274}
275
276  internal int rename(string file, string database, string newname, uint flags) {
277	int ret;
278	ret = libdb_csharpPINVOKE.DB_rename(swigCPtr, file, database, newname, flags);
279	/*
280	 * rename is a handle destructor, regardless of whether the rename
281	 * succeeds.  Reflect that in the wrapper class.
282	 */
283	swigCPtr = new HandleRef(null, IntPtr.Zero);
284	DatabaseException.ThrowException(ret);
285	return ret;
286}
287
288  internal int set_append_recno(BDB_AppendRecnoDelegate callback) {
289		int ret;
290		ret = libdb_csharpPINVOKE.DB_set_append_recno(swigCPtr, callback);
291		DatabaseException.ThrowException(ret);
292		return ret;
293}
294
295  internal int set_bt_compare(BDB_CompareDelegate callback) {
296		int ret;
297		ret = libdb_csharpPINVOKE.DB_set_bt_compare(swigCPtr, callback);
298		DatabaseException.ThrowException(ret);
299		return ret;
300}
301
302  internal int set_bt_compress(BDB_CompressDelegate compress, BDB_DecompressDelegate decompress) {
303		int ret;
304		ret = libdb_csharpPINVOKE.DB_set_bt_compress(swigCPtr, compress, decompress);
305		DatabaseException.ThrowException(ret);
306		return ret;
307}
308
309  internal int get_bt_minkey(ref uint bt_minkey) {
310		int ret;
311		ret = libdb_csharpPINVOKE.DB_get_bt_minkey(swigCPtr, ref bt_minkey);
312		DatabaseException.ThrowException(ret);
313		return ret;
314}
315
316  internal int set_bt_minkey(uint bt_minkey) {
317		int ret;
318		ret = libdb_csharpPINVOKE.DB_set_bt_minkey(swigCPtr, bt_minkey);
319		DatabaseException.ThrowException(ret);
320		return ret;
321}
322
323  internal int set_bt_prefix(BDB_CompareDelegate callback) {
324		int ret;
325		ret = libdb_csharpPINVOKE.DB_set_bt_prefix(swigCPtr, callback);
326		DatabaseException.ThrowException(ret);
327		return ret;
328}
329
330  internal int get_cachesize(ref uint gbytes, ref uint bytes, ref int ncache) {
331		int ret;
332		ret = libdb_csharpPINVOKE.DB_get_cachesize(swigCPtr, ref gbytes, ref bytes, ref ncache);
333		DatabaseException.ThrowException(ret);
334		return ret;
335}
336
337  internal int set_cachesize(uint gbytes, uint bytes, int ncache) {
338		int ret;
339		ret = libdb_csharpPINVOKE.DB_set_cachesize(swigCPtr, gbytes, bytes, ncache);
340		DatabaseException.ThrowException(ret);
341		return ret;
342}
343
344  internal int set_dup_compare(BDB_CompareDelegate callback) {
345		int ret;
346		ret = libdb_csharpPINVOKE.DB_set_dup_compare(swigCPtr, callback);
347		DatabaseException.ThrowException(ret);
348		return ret;
349}
350
351  internal int get_encrypt_flags(ref uint flags) {
352		int ret;
353		ret = libdb_csharpPINVOKE.DB_get_encrypt_flags(swigCPtr, ref flags);
354		DatabaseException.ThrowException(ret);
355		return ret;
356}
357
358  internal int set_encrypt(string pwd, uint flags) {
359		int ret;
360		ret = libdb_csharpPINVOKE.DB_set_encrypt(swigCPtr, pwd, flags);
361		DatabaseException.ThrowException(ret);
362		return ret;
363}
364
365  internal void set_errcall(BDB_ErrcallDelegate db_errcall_fcn) {
366    libdb_csharpPINVOKE.DB_set_errcall(swigCPtr, db_errcall_fcn);
367  }
368
369  internal int set_feedback(BDB_DbFeedbackDelegate callback) {
370		int ret;
371		ret = libdb_csharpPINVOKE.DB_set_feedback(swigCPtr, callback);
372		DatabaseException.ThrowException(ret);
373		return ret;
374}
375
376  internal int get_flags(ref uint flags) {
377		int ret;
378		ret = libdb_csharpPINVOKE.DB_get_flags(swigCPtr, ref flags);
379		DatabaseException.ThrowException(ret);
380		return ret;
381}
382
383  internal int set_flags(uint flags) {
384		int ret;
385		ret = libdb_csharpPINVOKE.DB_set_flags(swigCPtr, flags);
386		DatabaseException.ThrowException(ret);
387		return ret;
388}
389
390  internal int set_h_compare(BDB_CompareDelegate callback) {
391		int ret;
392		ret = libdb_csharpPINVOKE.DB_set_h_compare(swigCPtr, callback);
393		DatabaseException.ThrowException(ret);
394		return ret;
395}
396
397  internal int get_h_ffactor(ref uint ffactor) {
398		int ret;
399		ret = libdb_csharpPINVOKE.DB_get_h_ffactor(swigCPtr, ref ffactor);
400		DatabaseException.ThrowException(ret);
401		return ret;
402}
403
404  internal int set_h_ffactor(uint ffactor) {
405		int ret;
406		ret = libdb_csharpPINVOKE.DB_set_h_ffactor(swigCPtr, ffactor);
407		DatabaseException.ThrowException(ret);
408		return ret;
409}
410
411  internal int set_h_hash(BDB_HashDelegate callback) {
412		int ret;
413		ret = libdb_csharpPINVOKE.DB_set_h_hash(swigCPtr, callback);
414		DatabaseException.ThrowException(ret);
415		return ret;
416}
417
418  internal int get_h_nelem(ref uint nelem) {
419		int ret;
420		ret = libdb_csharpPINVOKE.DB_get_h_nelem(swigCPtr, ref nelem);
421		DatabaseException.ThrowException(ret);
422		return ret;
423}
424
425  internal int set_h_nelem(uint nelem) {
426		int ret;
427		ret = libdb_csharpPINVOKE.DB_set_h_nelem(swigCPtr, nelem);
428		DatabaseException.ThrowException(ret);
429		return ret;
430}
431
432  internal int get_lorder(ref int lorder) {
433		int ret;
434		ret = libdb_csharpPINVOKE.DB_get_lorder(swigCPtr, ref lorder);
435		DatabaseException.ThrowException(ret);
436		return ret;
437}
438
439  internal int set_lorder(int lorder) {
440		int ret;
441		ret = libdb_csharpPINVOKE.DB_set_lorder(swigCPtr, lorder);
442		DatabaseException.ThrowException(ret);
443		return ret;
444}
445
446  internal int get_pagesize(ref uint pgsz) {
447		int ret;
448		ret = libdb_csharpPINVOKE.DB_get_pagesize(swigCPtr, ref pgsz);
449		DatabaseException.ThrowException(ret);
450		return ret;
451}
452
453  internal int set_pagesize(uint pgsz) {
454		int ret;
455		ret = libdb_csharpPINVOKE.DB_set_pagesize(swigCPtr, pgsz);
456		DatabaseException.ThrowException(ret);
457		return ret;
458}
459
460  internal int get_priority(ref uint flags) {
461		int ret;
462		ret = libdb_csharpPINVOKE.DB_get_priority(swigCPtr, ref flags);
463		DatabaseException.ThrowException(ret);
464		return ret;
465}
466
467  internal int set_priority(uint flags) {
468		int ret;
469		ret = libdb_csharpPINVOKE.DB_set_priority(swigCPtr, flags);
470		DatabaseException.ThrowException(ret);
471		return ret;
472}
473
474  internal int get_q_extentsize(ref uint extentsz) {
475		int ret;
476		ret = libdb_csharpPINVOKE.DB_get_q_extentsize(swigCPtr, ref extentsz);
477		DatabaseException.ThrowException(ret);
478		return ret;
479}
480
481  internal int set_q_extentsize(uint extentsz) {
482		int ret;
483		ret = libdb_csharpPINVOKE.DB_set_q_extentsize(swigCPtr, extentsz);
484		DatabaseException.ThrowException(ret);
485		return ret;
486}
487
488  internal int get_re_delim(ref int delim) {
489		int ret;
490		ret = libdb_csharpPINVOKE.DB_get_re_delim(swigCPtr, ref delim);
491		DatabaseException.ThrowException(ret);
492		return ret;
493}
494
495  internal int set_re_delim(int delim) {
496		int ret;
497		ret = libdb_csharpPINVOKE.DB_set_re_delim(swigCPtr, delim);
498		DatabaseException.ThrowException(ret);
499		return ret;
500}
501
502  internal int get_re_len(ref uint len) {
503		int ret;
504		ret = libdb_csharpPINVOKE.DB_get_re_len(swigCPtr, ref len);
505		DatabaseException.ThrowException(ret);
506		return ret;
507}
508
509  internal int set_re_len(uint len) {
510		int ret;
511		ret = libdb_csharpPINVOKE.DB_set_re_len(swigCPtr, len);
512		DatabaseException.ThrowException(ret);
513		return ret;
514}
515
516  internal int get_re_pad(ref int pad) {
517		int ret;
518		ret = libdb_csharpPINVOKE.DB_get_re_pad(swigCPtr, ref pad);
519		DatabaseException.ThrowException(ret);
520		return ret;
521}
522
523  internal int set_re_pad(int pad) {
524		int ret;
525		ret = libdb_csharpPINVOKE.DB_set_re_pad(swigCPtr, pad);
526		DatabaseException.ThrowException(ret);
527		return ret;
528}
529
530  internal int get_re_source(ref string source) {
531		int ret;
532		ret = libdb_csharpPINVOKE.DB_get_re_source(swigCPtr, ref source);
533		DatabaseException.ThrowException(ret);
534		return ret;
535}
536
537  internal int set_re_source(string source) {
538		int ret;
539		ret = libdb_csharpPINVOKE.DB_set_re_source(swigCPtr, source);
540		DatabaseException.ThrowException(ret);
541		return ret;
542}
543
544  private IntPtr stat(DB_TXN txnid, uint flags, ref int err) {
545	return libdb_csharpPINVOKE.DB_stat(swigCPtr, DB_TXN.getCPtr(txnid), flags, ref err);
546}
547
548  internal int stat_print(uint flags) {
549		int ret;
550		ret = libdb_csharpPINVOKE.DB_stat_print(swigCPtr, flags);
551		DatabaseException.ThrowException(ret);
552		return ret;
553}
554
555  internal int sync(uint flags) {
556		int ret;
557		ret = libdb_csharpPINVOKE.DB_sync(swigCPtr, flags);
558		DatabaseException.ThrowException(ret);
559		return ret;
560}
561
562  internal int truncate(DB_TXN txn, ref uint countp, uint flags) {
563		int ret;
564		ret = libdb_csharpPINVOKE.DB_truncate(swigCPtr, DB_TXN.getCPtr(txn), ref countp, flags);
565		DatabaseException.ThrowException(ret);
566		return ret;
567}
568
569  internal int upgrade(string file, uint flags) {
570		int ret;
571		ret = libdb_csharpPINVOKE.DB_upgrade(swigCPtr, file, flags);
572		DatabaseException.ThrowException(ret);
573		return ret;
574}
575
576  internal int verify(string file, string database, System.IO.TextWriter handle, BDB_FileWriteDelegate callback, uint flags) {
577		int ret;
578		ret = libdb_csharpPINVOKE.DB_verify(swigCPtr, file, database, handle, callback, flags);
579		/* Verify is a db handle destructor.  Reflect that in the wrapper class. */
580		swigCMemOwn = false;
581		swigCPtr = new HandleRef(null, IntPtr.Zero);
582		DatabaseException.ThrowException(ret);
583		return ret;
584}
585
586}
587
588}
589