diff options
author | Michael Cahill <michael.cahill@wiredtiger.com> | 2012-05-04 10:07:25 +1000 |
---|---|---|
committer | Michael Cahill <michael.cahill@wiredtiger.com> | 2012-05-04 10:07:25 +1000 |
commit | a8978e988c5d7b54ee0c57c99f3d20c9edb25cff (patch) | |
tree | 25058872466c1476592d4f0467fc0366e7cbf7ce /examples/python | |
parent | 455b2143f55e511c005c664eece3422802a70a5f (diff) | |
download | mongo-a8978e988c5d7b54ee0c57c99f3d20c9edb25cff.tar.gz |
Fix the Python example.
closes #206
--HG--
rename : examples/c/Makefile.am => examples/python/Makefile.am
Diffstat (limited to 'examples/python')
-rw-r--r-- | examples/python/Makefile.am | 2 | ||||
-rwxr-xr-x | examples/python/ex_access.py | 66 | ||||
-rwxr-xr-x | examples/python/run-ex_access | 5 |
3 files changed, 19 insertions, 54 deletions
diff --git a/examples/python/Makefile.am b/examples/python/Makefile.am new file mode 100644 index 00000000000..744728fe482 --- /dev/null +++ b/examples/python/Makefile.am @@ -0,0 +1,2 @@ +# The examples can be run with no arguments as simple smoke tests +TESTS = run-ex_access diff --git a/examples/python/ex_access.py b/examples/python/ex_access.py index 5ae7f672651..41790edb511 100755 --- a/examples/python/ex_access.py +++ b/examples/python/ex_access.py @@ -1,64 +1,22 @@ -#!/usr/bin/env PYTHONPATH=../../lang/python:../../lang/python/src python -# -# Copyright (c) 2008-2012 WiredTiger, Inc. -# -# This is free and unencumbered software released into the public domain. -# -# Anyone is free to copy, modify, publish, use, compile, sell, or -# distribute this software, either in source code form or as a compiled -# binary, for any purpose, commercial or non-commercial, and by any -# means. -# -# In jurisdictions that recognize copyright laws, the author or authors -# of this software dedicate any and all copyright interest in the -# software to the public domain. We make this dedication for the benefit -# of the public at large and to the detriment of our heirs and -# successors. We intend this dedication to be an overt act of -# relinquishment in perpetuity of all present and future rights to this -# software under copyright law. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -# OTHER DEALINGS IN THE SOFTWARE. -# -# ex_access.py -# demonstrates how to create and access a simple table. -# +from wiredtiger import wiredtiger_open -import wiredtiger -import sys +# Connect to the database and open a session +conn = wiredtiger_open('WT_TEST', 'create') +session = conn.open_session() -home = 'WT_TEST' +# Create a simple table +session.create('table:T', 'key_format=S,value_format=S') -try: - conn = wiredtiger.wiredtiger_open(home, None, 'create') - print('connected: ' + `conn`); - session = conn.open_session(None, None) -except BaseException as e: - print('Error connecting to', (home + ':'), e); - sys.exit(1) +# Open a cursor and insert a record +cursor = session.open_cursor('table:T', None) -# Note: further error checking omitted for clarity. - -session.create_table('access', 'key_format=S,value_format=S') -cursor = session.open_cursor('table:access', None, None) - -# Insert a record. cursor.set_key('key1') cursor.set_value('value1') +cursor.insert() -# TODO: remove try block when cursor.insert works -try: - cursor.insert() -except BaseException as tuple: - print('Error cursor insert: ', tuple); - +# Iterate through the records +cursor.reset() for key, value in cursor: print('Got record: ' + key + ' : ' + value) -conn.close(None) -sys.exit(0) +conn.close() diff --git a/examples/python/run-ex_access b/examples/python/run-ex_access new file mode 100755 index 00000000000..1550a780304 --- /dev/null +++ b/examples/python/run-ex_access @@ -0,0 +1,5 @@ +#!/bin/sh + +rm -rf WT_TEST ; mkdir WT_TEST + +exec env LD_LIBRARY_PATH=../../.libs DYLD_LIBRARY_PATH=../../.libs PYTHONPATH=${srcdir}/../../lang/python:../../lang/python python ${srcdir}/ex_access.py |