txn.html 2.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
	<title>BDB</title>
	<link rel="stylesheet" type="text/css" href="../style.css"/>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    </head>

    <body>
	<div class="header">
	    <h1>BDB</h1>
	    <h2>Berkeley DB CFFI bindings</h2>
	</div>

	<h3>Example Usage (Transactions)</h3>
	<pre>
CL-USER&gt; (asdf:oos 'asdf:load-op :bdb-playground)
NIL
CL-USER&gt; (in-package :bdb-playground)
#&lt;PACKAGE "BDB-PLAYGROUND"&gt;
BDB-PLAYGROUND&gt; (setq *env* (db-env-open "/home/main/tdb" :init-txn t :init-log t :init-lock t :init-mpool t :create t))
#&lt;DB-ENV {B7A4221}&gt;
BDB-PLAYGROUND&gt; (setq *db* (db-open "test.db" :env *env* :auto-commit t :create t))
#&lt;DB-TXN {B8042D1}&gt;
BDB-PLAYGROUND&gt; (with-txn (txn *env*)
		  (db-put *db* 1 "data1" :txn txn)
		  (db-put *db* 2 "data2" :txn txn))
T
BDB-PLAYGROUND&gt; (db-get *db* 1)
"data1"
BDB-PLAYGROUND&gt; (db-get *db* 2)
"data2"
BDB-PLAYGROUND&gt; (db-get *db* 3)
NIL
BDB-PLAYGROUND&gt; (with-txn (txn *env*)
		  (db-put *db* 3 "data3" :txn txn)
		  (db-put *db* 4 "data4" :txn txn)
		  (error "ohoh, abort transaction"))
BDB-PLAYGROUND&gt; (db-get *db* 1)
"data1"
BDB-PLAYGROUND&gt; (db-get *db* 2)
"data2"
BDB-PLAYGROUND&gt; (db-get *db* 3)
NIL
BDB-PLAYGROUND&gt; (db-get *db* 4)
NIL
BDB-PLAYGROUND&gt; (db-del *db* 1)
; Evaluation aborted | comment: if you want to delete an entry, you must use a txn
BDB-PLAYGROUND&gt; (with-txn (txn *env*)
		  (db-del *db* 1 :txn txn))
T
BDB-PLAYGROUND&gt; (db-get *db* 1)
NIL
BDB-PLAYGROUND&gt; (db-get *db* 2)
"data2"
BDB-PLAYGROUND&gt; (db-get *db* 3)
NIL
BDB-PLAYGROUND&gt; (db-get *db* 4)
NIL
BDB-PLAYGROUND&gt; (db-close *db*)
T
BDB-PLAYGROUND&gt; (db-env-close *env*)
NIL
BDB-PLAYGROUND&gt; ;; bye bye
	</pre>
<p> </p>

	<div class="footer">
	    <a href="mailto:-urso-@web.de">Email</a>
	</div>

	<div class="check">
	    <a href="http://validator.w3.org/check/referer"> Valid XHTML 1.0 Strict</a>
	</div>
    </body>
</html>