summaryrefslogtreecommitdiff
path: root/lang
diff options
context:
space:
mode:
authorDon Anderson <dda@ddanderson.com>2014-08-06 21:36:47 -0400
committerDon Anderson <dda@ddanderson.com>2014-08-06 21:36:47 -0400
commit31ca4b33dd1cbe9cf8dd6f692ac1f294acb2e5f4 (patch)
treee8eb491b1339e765851e431694ff5c6b5d5b358e /lang
parent2b0508fe2907f109721425dca86a6c7ac7280787 (diff)
downloadmongo-31ca4b33dd1cbe9cf8dd6f692ac1f294acb2e5f4.tar.gz
Add JSON loading to cursors and wt load utility. refs #740.
Allow set_key and set_value on JSON cursors. The argument is a string that is interpreted as JSON and must match the format created by a JSON dump cursor or the 'wt dump -j' command. Add -j option to 'wt load' utility to allow loading JSON. Small adjustment to Python interface so that JSON cursor key/values inputs are always treated as strings. Added doc and Python tests for JSON cursors and wt load -j.
Diffstat (limited to 'lang')
-rw-r--r--lang/python/wiredtiger.i27
1 files changed, 22 insertions, 5 deletions
diff --git a/lang/python/wiredtiger.i b/lang/python/wiredtiger.i
index 0c228c56e5f..be55845a7b2 100644
--- a/lang/python/wiredtiger.i
+++ b/lang/python/wiredtiger.i
@@ -388,7 +388,9 @@ COMPARE_OK(__wt_cursor::search_near)
%exception __wt_async_op::_set_key;
%exception __wt_async_op::_set_value;
%exception __wt_cursor::_set_key;
+%exception __wt_cursor::_set_key_str;
%exception __wt_cursor::_set_value;
+%exception __wt_cursor::_set_value_str;
%exception wiredtiger_strerror;
%exception wiredtiger_version;
@@ -577,6 +579,11 @@ typedef int int_void;
$self->set_key($self, &k);
}
+ /* Get / set keys and values */
+ void _set_key_str(char *str) {
+ $self->set_key($self, str);
+ }
+
int_void _set_recno(uint64_t recno) {
WT_ITEM k;
uint8_t recno_buf[20];
@@ -601,6 +608,11 @@ typedef int int_void;
$self->set_value($self, &v);
}
+ /* Get / set keys and values */
+ void _set_value_str(char *str) {
+ $self->set_value($self, str);
+ }
+
/* Don't return values, just throw exceptions on failure. */
int_void _get_key(char **datap, int *sizep) {
WT_ITEM k;
@@ -739,6 +751,8 @@ typedef int int_void;
args = args[0]
if self.is_column:
self._set_recno(long(args[0]))
+ elif self.is_json:
+ self._set_key_str(args[0])
else:
# Keep the Python string pinned
self._key = pack(self.key_format, *args)
@@ -748,11 +762,14 @@ typedef int int_void;
'''set_value(self) -> None
@copydoc WT_CURSOR::set_value'''
- if len(args) == 1 and type(args[0]) == tuple:
- args = args[0]
- # Keep the Python string pinned
- self._value = pack(self.value_format, *args)
- self._set_value(self._value)
+ if self.is_json:
+ self._set_value_str(args[0])
+ else:
+ if len(args) == 1 and type(args[0]) == tuple:
+ args = args[0]
+ # Keep the Python string pinned
+ self._value = pack(self.value_format, *args)
+ self._set_value(self._value)
def __iter__(self):
'''Cursor objects support iteration, equivalent to calling