Merge lp:~dobey/u1db/update-13-10 into lp:u1db/stable-13-10

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: no longer in the source branch.
Merged at revision: 437
Proposed branch: lp:~dobey/u1db/update-13-10
Merge into: lp:u1db/stable-13-10
Diff against target: 105 lines (+33/-7)
3 files modified
html-docs/high-level-api.rst (+27/-2)
src/u1db_query.c (+5/-4)
u1db/tests/test_https.py (+1/-1)
To merge this branch: bzr merge lp:~dobey/u1db/update-13-10
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
Review via email: mp+166849@code.launchpad.net

Commit message

[Samuele Pedroni]

    Clarify querying of number() and bool() indexes, values for querying are always strings (atm).
    Fix code that was using sizeof of value_types like it was some sort of dynamic array len, use the explicit arity value instead.
    Be less strict about the error message we get testing failing cert verification.

To post a comment you must log in.
Revision history for this message
Mike McCracken (mikemc) :
review: Approve
lp:~dobey/u1db/update-13-10 updated
437. By Samuele Pedroni

[Samuele Pedroni]

    Clarify querying of number() and bool() indexes, values for querying are always strings (atm).
    Fix code that was using sizeof of value_types like it was some sort of dynamic array len, use the explicit arity value instead.
    Be less strict about the error message we get testing failing cert verification.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'html-docs/high-level-api.rst'
2--- html-docs/high-level-api.rst 2012-09-18 16:25:41 +0000
3+++ html-docs/high-level-api.rst 2013-05-31 16:37:36 +0000
4@@ -308,8 +308,8 @@
5 Querying an index
6 ^^^^^^^^^^^^^^^^^
7
8-Pass an index key or a tuple of index keys (if the index is on multiple fields)
9-to ``get_from_index``; the last index key in each tuple (and *only* the last
10+Pass an index key or multiple index keys (if the index is on multiple fields)
11+to ``get_from_index``; the last index key (and *only* the last
12 one) can end with an asterisk, which matches initial substrings. So, querying
13 our ``by-firstname`` index from above:
14
15@@ -332,6 +332,30 @@
16 >>> assert(jb.doc_id in js)
17 >>> assert(jm.doc_id in js)
18
19+Index key values used when querying are always strings. If querying an
20+index built with ``bool()`` use the values '0' and '1' to query for
21+false and true respectively. For an index built with ``number()`` turn
22+key number values into strings with the appropriate left zero-padding
23+(and note in particular that querying a ``number()`` index with an int
24+value, such as ``db.get_from_index('by-number', 9)``, will throw an error).
25+
26+.. doctest ::
27+
28+ >>> db = u1db.open('mydb11.u1db', create=True)
29+ >>> db.create_index('done', "bool(done)")
30+ >>> doc1 = db.create_doc({'task': 'milk', 'done': False, 'hours': 1})
31+ >>> doc2 = db.create_doc({'task': 'coding', 'done': True, 'hours': 12})
32+ >>> [doc.content['task'] for doc in db.get_from_index('done', '1')]
33+ [u'coding']
34+ >>> db.create_index('by-hours', "number(hours, 3)")
35+ >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '12')]
36+ []
37+ >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '012')]
38+ [u'coding']
39+ >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '001')]
40+ [u'milk']
41+
42+
43 Index functions
44 ^^^^^^^^^^^^^^^
45
46@@ -399,4 +423,5 @@
47 os.remove(os.path.join(tmp_dir, "mydb8.u1db"))
48 os.remove(os.path.join(tmp_dir, "mydb9.u1db"))
49 os.remove(os.path.join(tmp_dir, "mydb10.u1db"))
50+ os.remove(os.path.join(tmp_dir, "mydb11.u1db"))
51 os.rmdir(tmp_dir)
52
53=== modified file 'src/u1db_query.c'
54--- src/u1db_query.c 2012-10-09 20:56:28 +0000
55+++ src/u1db_query.c 2013-05-31 16:37:36 +0000
56@@ -18,6 +18,7 @@
57
58 #include "u1db/u1db_internal.h"
59 #include <sqlite3.h>
60+#include <stdlib.h>
61 #include <stdarg.h>
62 #include <string.h>
63 #include <ctype.h>
64@@ -242,7 +243,7 @@
65 void *function;
66 char *name;
67 int value_type;
68- int arity;
69+ int arity; /* negative means any N*(-arity) values are OK */
70 const int *value_types;
71 } OPERATIONS[] = {
72 { op_lower, "lower", json_type_string, 1, JUST_EXPRESSION },
73@@ -1299,7 +1300,7 @@
74 char *sep = NULL;
75 parse_tree *node = NULL;
76 int status = U1DB_OK;
77- int i, array_size;
78+ int i, cyclic_arity;
79
80 sep = get_token(tokens);
81 if (sep == NULL || strcmp(sep, "(") != 0) {
82@@ -1346,9 +1347,9 @@
83 }
84 }
85 i = 0;
86- array_size = sizeof(result->value_types) / sizeof(int);
87+ cyclic_arity = abs(result->arity);
88 for (node = result->first_child; node != NULL; node = node->next_sibling) {
89- node->arg_type = result->value_types[i % array_size];
90+ node->arg_type = result->value_types[i % cyclic_arity];
91 if (node->arg_type == EXPRESSION) {
92 status = to_getter(node);
93 if (status != U1DB_OK)
94
95=== modified file 'u1db/tests/test_https.py'
96--- u1db/tests/test_https.py 2012-10-02 13:54:36 +0000
97+++ u1db/tests/test_https.py 2013-05-31 16:37:36 +0000
98@@ -96,7 +96,7 @@
99 try:
100 remote_target.record_sync_info('other-id', 2, 'T-id')
101 except ssl.SSLError, e:
102- self.assertIn("certificate verify failed", str(e))
103+ self.assertIn("certificate", str(e))
104 else:
105 self.fail("certificate verification should have failed.")
106

Subscribers

People subscribed via source and target branches

to all changes: