diff --git a/examples/secondary.html b/examples/secondary.html index 17b022c5bd09b8cf1aa599bdfc763a247517ed64..9e0f5548d04a28c2ccef268a12a3d5aff4e8921c 100644 --- a/examples/secondary.html +++ b/examples/secondary.html @@ -17,10 +17,12 @@

Example Usage (Secondary Databases)

WARNING: this 'native' kind of using secondary databases with Berkeley DB is very C-centric, thus for every callback function you create, cffi will create one and those functions and associated data (when using closures for example) - will not being garbage collected, even if databases were closed. Thus if you use alot of secondary databases, there will be - a lot of garbage being produced over time... + will not being garbage collected, even if databases were closed. Thus if you use alot of secondary databases, there may be + a lot of garbage being produced over time...
+ Using transactional databases, C-Style callbacks are not used anymore and you must not be "afraid" about anything...

+
 CL-USER> (asdf:oos 'asdf:load-op :bdb-playground)
 NIL
 CL-USER> (in-package :bdb-playground)
@@ -30,10 +32,10 @@ BDB-PLAYGROUND> (defun first-callback (sdb key data)
 FIRST-CALLBACK
 BDB-PLAYGROUND> (setq *callback* (create-assoc-callback #'first-callback))
 #.(SB-SYS:INT-SAP #X050006F8)
-BDB-PLAYGROUND> (setq *db* (db-open "test.db" :create t))
-#.(SB-SYS:INT-SAP #X08197120)
-BDB-PLAYGROUND> (setq *sdb* (db-open "sec.db" :create t :dup-sort t))
-#.(SB-SYS:INT-SAP #X081995A0)
+BDB-PLAYGROUND> (setq *db* (db-open "test.db" :create t :exclusive t))
+#<DB-STD {A866C31}>
+BDB-PLAYGROUND> (setq *sdb* (db-open "sec.db" :create t :exclusive t :dup-sort t))
+#<DB-STD {A9DEB49}>
 BDB-PLAYGROUND> (db-associate *db* *sdb* *callback*)
 T
 BDB-PLAYGROUND> (db-put *db* 1 '(max mustermann))
@@ -43,7 +45,7 @@ T
 BDB-PLAYGROUND> (db-put *db* 3 '(micky maus))
 T
 BDB-PLAYGROUND> (setq *cursor* (db-cursor *db*))
-#.(SB-SYS:INT-SAP #X0819CF28)
+#<BDB::CURSOR {B350ED1}>
 BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
 1
 (MAX MUSTERMANN)
@@ -57,9 +59,9 @@ BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
 NIL
 NIL
 BDB-PLAYGROUND> (db-cursor-close *cursor*)
-T
+NIL
 BDB-PLAYGROUND> (setq *cursor* (db-cursor *sdb*))
-#.(SB-SYS:INT-SAP #X0819BB28)
+#<BDB::CURSOR {B4CF249}>
 BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
 KATER
 (KATER KARLO)
@@ -72,8 +74,15 @@ MAX
 BDB-PLAYGROUND> (db-cursor-get *cursor* :next t)
 NIL
 NIL
+BDB-PLAYGROUND> (db-cursor-close *cursor*)
+NIL
+BDB-PLAYGROUND> (db-close *sdb*)
+NIL
+BDB-PLAYGROUND> (db-close *db*)
+NIL
 BDB-PLAYGROUND> ;;bye bye
 	
+

(to be used by this library only) - +>

(to be used by this library only)

(defcfun "strlen" :int
   (str :pointer))
Berkley DB CFFI-Bindings

Berkley DB CFFI-Bindings

Secondary Databases 

- Notes: - the C library handles secondaries like this: - db_create: - will create environment, if none specified and - add to db pointer - db_put/__db_put: - create cursor with write-lock - - use __db_c_put on cursor to insert data - __db_c_put: - uses private flag DB_UPDATE_SECONDARY to do puts on - secondary databases - - use __db_s_first and __db_s_next for iterating over - secondaries, they will take care of thread-locking - - in first loop add new keys: - - call callback to get secondary key - - open cursor on secondary with transaction and - lock id of primary database - - use __db_c_put with DB_UPDATE_SECONDARY flag - to insert data into secondary - - close cursor - - in second loop remove old secondary indicies: - - get old secondary key - - if secondary key needs to be deleted than: - - get cursor - - use get to move cursor to position - - delete entry - - update primary database now - - perl/tcl/python/ruby libs weren't much more helpfull :( - - for the lisp library: - - when opening a database it depends on the environment, - wether we'll use the C-based (using db-associate-ll) - implementation or a transaction based if transactions - are supported by environment. - Todo so, db-open returns different kind of classes: - - db-std ;; standard db-class, if txn not allowed - - db-txn ;; if environment supports transactions - - - db-associate needs different implementations for db-std - and db-txn: - - db-std: - - use the old low level method - - use defcallback and go on - - no changes to db-put - - db-txn: - - add callback function and secondary to table - in database - - when closing secondary, remove from table - - don't use defcallback, use lambda directly - - overwrite db-put: - - create an transaction - - add data to primary - - in a loop, add keys to secondaries - - - - -

(defcstruct DBT ;;tried to avoid using DBT directly... :'(
-  (data :pointer)
-  (size :uint32)
-  (ulen :uint32)
-  (dlen :uint32)
-  (doff :uint32)
-  (flags :uint32))
- - - - - - - - - - - - - - - - - -
\ No newline at end of file diff --git a/qbook/bdb/api/function_005FBDB_003A_003ADB-OPEN.html b/qbook/bdb/api/function_005FBDB_003A_003ADB-OPEN.html index c78d644eb628236301e2fc1db0c25512cbed32ac..39ec7339bd5ba11993b143714c65c5e92b3eeb1d 100644 --- a/qbook/bdb/api/function_005FBDB_003A_003ADB-OPEN.html +++ b/qbook/bdb/api/function_005FBDB_003A_003ADB-OPEN.html @@ -14,13 +14,7 @@ >

Documentation

creates and opens a new Database - params: env = Environment the database shall be opened in - txn = Transaction - db = Database in File (optional) - mode = file mode, use create-umask or 0 for default - type = :db-btree :db-hash :db-recno or :db-queue - flags... see BDB documentation or db.h

creates and opens a new Database
   params: env = Environment the database shall be opened in txn = Transaction db = Database in File (optional) mode = file mode, use create-umask or 0 for default type = :db-btree :db-hash :db-recno or :db-queue flags... see BDB documentation or db.h

Source

Documentation

callback returns a cbuffer, which will be freed by this put function

callback returns a cbuffer, which will be freed by this put function

Source


 
(eval-when (:compile-toplevel :load-toplevel :execute)
-  (unless (find-package :cffi-util-system)
-    (defpackage :cffi-util-system
-      (:use :common-lisp :asdf))))

(eval-when (:compile-toplevel :load-toplevel :execute)
  (unless (find-package :cffi-util-system) (defpackage :cffi-util-system (:use :common-lisp :asdf))))

(in-package :cffi-util-system)

(in-package :cffi-util-system)

(defsystem :cffi-util
-  :description "some utilities"
-  :author ""
-  :version "0.0,0"
-  :components
-  ((:module :src
-	    :components ((:file "packages")
-			 (:file "flags"
-				:depends-on ("packages"))
-			 (:file "defcfun"
-				:depends-on ("packages" "flags"))
-			 (:file "cbuffer"
-				:depends-on ("packages"))
-			 (:file "cbuffer-streams"
-				:depends-on ("cbuffer")))))
-  :depends-on (:cffi :mycl-util :trivial-gray-streams :flexi-streams))

(defsystem :cffi-util
  :description "some utilities"
  :author ""
  :version "0.0,0"
  :components
  ((:module :src :components ((:file "packages") (:file "flags" :depends-on ("packages")) (:file "defcfun" :depends-on ("packages" "flags")) (:file "cbuffer" :depends-on ("packages")) (:file "cbuffer-streams" :depends-on ("cbuffer")))))
  :depends-on (:cffi :mycl-util :trivial-gray-streams :flexi-streams))

(defstruct cbuffer
-  (data (foreign-alloc :uchar :count 16))
-  (size 0)
-  (length 16))

(defstruct cbuffer
  (data (foreign-alloc :uchar :count 16))
  (size 0)
  (length 16))

@@ -90,11 +87,7 @@ >
(defcfun "memcpy"
-    :pointer
-  (dest :pointer)
-  (src :pointer)
-  (length :int))

(defcfun "memcpy" :pointer
  (dest :pointer)
  (src :pointer)
  (length :int))

Documentation

WARNING: size must be smaller then length!!! - use cbuffer-ensure-size before using cbuffer-adjust-min-size - for example

WARNING: size must be smaller then length!!! use cbuffer-ensure-size before using cbuffer-adjust-min-size for example

Source

Documentation

resizes cbuffer by creating a new one and copying the data along. - if new-size < size then buffer may be truncated

resizes cbuffer by creating a new one and copying the data along.
   if new-size < size then buffer may be truncated

Source

Documentation

creates an integer using logior using a list of flags: - e.g. (concat-flags '(:append :create <more-symbols>))

creates an integer using logior using a list of flags:
   e.g. (concat-flags '(:append :create ))

Source

Documentation

flag systems may be children of other flag systems

flag systems may be children of other flag systems

Source

Documentation

returns a list of flags, which byte pattern is found in value

returns a list of flags, which byte pattern is found in value

Source

Documentation

make-cbuffer-pool creates a priority-pool using the length - of buffers as priority... Largest Buffers have highest priority

make-cbuffer-pool creates a priority-pool using the length
   of buffers as priority... Largest Buffers have highest priority

Source

Documentation

same as def-flag, but creates a constant

same as def-flag, but creates a constant

Source

Documentation

if ret-type is keyword :error-int the cfunction will return - an int indicating an error if ret!=0 and error-fun is called with using - the returned value - syntax: (defcfun* (name fun-name <:error-fun symbol> <:method t|nil>) - ret-type - args*) - ctype ::= see cffi manual... - args ::= (arg ctype [:key]) | (arg :out ctype) | - (arg ctype :const value) | - (arg :flag flag-list - <:flag-type ctype> - <:default flag-list> - <:flag-system flag-system>) - (arg ctype :class class-args) - flag-list ::= (flag-keyword*) - class-args ::= slot-name | (class-name slot-name) - params: flag-type: default is uint32 - default: flags being set to t by default - name: cfunction name - fun-name: function name for lisp interface - error-fun: function called if ret-type id of type :error-int - ret-type: see defcfun - arglist: see defcfun (if arglist contains :out keyword for - several args, these will be returned - using values... try macroexpand to find out - more :P )

if ret-type is keyword :error-int the cfunction will return
   an int indicating an error if ret!=0 and error-fun is called with using
   the returned value
   syntax: (defcfun* (name fun-name <:error-fun symbol> <:method t|nil>) ret-type args) ctype ::= see cffi manual... args ::= (arg ctype [:key]) | (arg :out ctype) | (arg ctype :const value) | (arg :flag flag-list <:flag-type ctype> <:default flag-list> <:flag-system flag-system>) (arg ctype :class class-args) flag-list ::= (flag-keyword) class-args ::= slot-name | (class-name slot-name)
   params: flag-type: default is uint32 default: flags being set to t by default name: cfunction name fun-name: function name for lisp interface error-fun: function called if ret-type id of type :error-int ret-type: see defcfun arglist: see defcfun (if arglist contains :out keyword for several args, these will be returned using values... try macroexpand to find out more :P )

Source

Documentation

creates code using a flag-system and a list of args. - All functions using this macros must be recompiled if - they're using flags being redefined in a flag-system - after compilation. - Uses *current-flag-system*... use with-flag-system - if you need to use another flag-system within this macro

creates code using a flag-system and a list of args.
   All functions using this macros must be recompiled if
   they're using flags being redefined in a flag-system
   after compilation.
   Uses current-flag-system... use with-flag-system
   if you need to use another flag-system within this macro

Source

Documentation

max num of buffers in pool

max num of buffers in pool

Source

Documentation

min size of buffers in pool

min size of buffers in pool

Source

Documentation

...

...

Source

 | toc

example usage: - -(defcfun* ("test" test :method t) :error-int - (a :int) - (b :out :uchar) - (c :int :key) - (flag :flag (:create :truncate)) - (aflag :uint32 :const 0) - (cl :uint32 :class (my-class value)) - (cl2 :uint32 :class any-slot) - ) -==> -(PROGN - (DEFCFUN ("test" %TEST) - :INT - (A :INT) - (B :POINTER) - (C :INT) - (FLAG :UINT32) - (AFLAG :UINT32) - (CL :UINT32) - (CL2 :UINT32)) - (DEFMETHOD TEST (A (CL MY-CLASS) CL2 &KEY C CREATE TRUNCATE) - (WITH-FOREIGN-OBJECTS ((B :UCHAR)) - (LET ((RET - (%TEST A - B - C - (LOGIOR (IF CREATE 0 0) - (IF TRUNCATE 0 0)) - 0 - (SLOT-VALUE CL 'VALUE) - (SLOT-VALUE CL2 'ANY-SLOT)))) - (WHEN (STD-CHECK-ERROR RET) - (VALUES (MEM-REF B :UCHAR))))))) +>

example usage:

(defcfun* ("test" test :method t) :error-int
  (a :int)
  (b :out :uchar)
  (c :int :key)
  (p :pointer)
  (flag :flag (:create :truncate))
  (aflag :uint32 :const 0)
  (cl :uint32 :class (my-class value))
  (cl2 :uint32 :class any-slot)
  (cl3 :pointer :key :class handle))
 ==>
(PROGN
 (DEFCFUN ("test" %TEST) :INT (A :INT) (B :POINTER) (C :INT) (P :POINTER) (FLAG :UINT32) (AFLAG :UINT32) (CL :UINT32) (CL2 :UINT32) (CL3 :POINTER))
 (DEFMETHOD TEST (A P (CL MY-CLASS) CL2 &KEY C CL3 CREATE TRUNCATE) (WITH-FOREIGN-OBJECTS ((B :UCHAR)) (LET ((RET (%TEST A B C (IF (NOT P) (NULL-POINTER) P) (LOGIOR (IF CREATE 1 0) (IF TRUNCATE 128 0)) 0 (SLOT-VALUE CL 'VALUE) (SLOT-VALUE CL2 'ANY-SLOT) (IF (OR (NOT CL3) (NOT (SLOT-VALUE CL3 'HANDLE))) (NULL-POINTER) (SLOT-VALUE CL3 'HANDLE))))) (WHEN (STD-CHECK-ERROR RET) (VALUES (MEM-REF B :UCHAR)))))))