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
=== modified file 'html-docs/high-level-api.rst'
--- html-docs/high-level-api.rst 2012-09-18 16:25:41 +0000
+++ html-docs/high-level-api.rst 2013-05-31 16:37:36 +0000
@@ -308,8 +308,8 @@
308Querying an index308Querying an index
309^^^^^^^^^^^^^^^^^309^^^^^^^^^^^^^^^^^
310310
311Pass an index key or a tuple of index keys (if the index is on multiple fields)311Pass an index key or multiple index keys (if the index is on multiple fields)
312to ``get_from_index``; the last index key in each tuple (and *only* the last312to ``get_from_index``; the last index key (and *only* the last
313one) can end with an asterisk, which matches initial substrings. So, querying313one) can end with an asterisk, which matches initial substrings. So, querying
314our ``by-firstname`` index from above:314our ``by-firstname`` index from above:
315315
@@ -332,6 +332,30 @@
332 >>> assert(jb.doc_id in js)332 >>> assert(jb.doc_id in js)
333 >>> assert(jm.doc_id in js)333 >>> assert(jm.doc_id in js)
334334
335Index key values used when querying are always strings. If querying an
336index built with ``bool()`` use the values '0' and '1' to query for
337false and true respectively. For an index built with ``number()`` turn
338key number values into strings with the appropriate left zero-padding
339(and note in particular that querying a ``number()`` index with an int
340value, such as ``db.get_from_index('by-number', 9)``, will throw an error).
341
342.. doctest ::
343
344 >>> db = u1db.open('mydb11.u1db', create=True)
345 >>> db.create_index('done', "bool(done)")
346 >>> doc1 = db.create_doc({'task': 'milk', 'done': False, 'hours': 1})
347 >>> doc2 = db.create_doc({'task': 'coding', 'done': True, 'hours': 12})
348 >>> [doc.content['task'] for doc in db.get_from_index('done', '1')]
349 [u'coding']
350 >>> db.create_index('by-hours', "number(hours, 3)")
351 >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '12')]
352 []
353 >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '012')]
354 [u'coding']
355 >>> [doc.content['task'] for doc in db.get_from_index('by-hours', '001')]
356 [u'milk']
357
358
335Index functions359Index functions
336^^^^^^^^^^^^^^^360^^^^^^^^^^^^^^^
337361
@@ -399,4 +423,5 @@
399 os.remove(os.path.join(tmp_dir, "mydb8.u1db"))423 os.remove(os.path.join(tmp_dir, "mydb8.u1db"))
400 os.remove(os.path.join(tmp_dir, "mydb9.u1db"))424 os.remove(os.path.join(tmp_dir, "mydb9.u1db"))
401 os.remove(os.path.join(tmp_dir, "mydb10.u1db"))425 os.remove(os.path.join(tmp_dir, "mydb10.u1db"))
426 os.remove(os.path.join(tmp_dir, "mydb11.u1db"))
402 os.rmdir(tmp_dir)427 os.rmdir(tmp_dir)
403428
=== modified file 'src/u1db_query.c'
--- src/u1db_query.c 2012-10-09 20:56:28 +0000
+++ src/u1db_query.c 2013-05-31 16:37:36 +0000
@@ -18,6 +18,7 @@
1818
19#include "u1db/u1db_internal.h"19#include "u1db/u1db_internal.h"
20#include <sqlite3.h>20#include <sqlite3.h>
21#include <stdlib.h>
21#include <stdarg.h>22#include <stdarg.h>
22#include <string.h>23#include <string.h>
23#include <ctype.h>24#include <ctype.h>
@@ -242,7 +243,7 @@
242 void *function;243 void *function;
243 char *name;244 char *name;
244 int value_type;245 int value_type;
245 int arity;246 int arity; /* negative means any N*(-arity) values are OK */
246 const int *value_types;247 const int *value_types;
247} OPERATIONS[] = {248} OPERATIONS[] = {
248 { op_lower, "lower", json_type_string, 1, JUST_EXPRESSION },249 { op_lower, "lower", json_type_string, 1, JUST_EXPRESSION },
@@ -1299,7 +1300,7 @@
1299 char *sep = NULL;1300 char *sep = NULL;
1300 parse_tree *node = NULL;1301 parse_tree *node = NULL;
1301 int status = U1DB_OK;1302 int status = U1DB_OK;
1302 int i, array_size;1303 int i, cyclic_arity;
13031304
1304 sep = get_token(tokens);1305 sep = get_token(tokens);
1305 if (sep == NULL || strcmp(sep, "(") != 0) {1306 if (sep == NULL || strcmp(sep, "(") != 0) {
@@ -1346,9 +1347,9 @@
1346 }1347 }
1347 }1348 }
1348 i = 0;1349 i = 0;
1349 array_size = sizeof(result->value_types) / sizeof(int);1350 cyclic_arity = abs(result->arity);
1350 for (node = result->first_child; node != NULL; node = node->next_sibling) {1351 for (node = result->first_child; node != NULL; node = node->next_sibling) {
1351 node->arg_type = result->value_types[i % array_size];1352 node->arg_type = result->value_types[i % cyclic_arity];
1352 if (node->arg_type == EXPRESSION) {1353 if (node->arg_type == EXPRESSION) {
1353 status = to_getter(node);1354 status = to_getter(node);
1354 if (status != U1DB_OK)1355 if (status != U1DB_OK)
13551356
=== modified file 'u1db/tests/test_https.py'
--- u1db/tests/test_https.py 2012-10-02 13:54:36 +0000
+++ u1db/tests/test_https.py 2013-05-31 16:37:36 +0000
@@ -96,7 +96,7 @@
96 try:96 try:
97 remote_target.record_sync_info('other-id', 2, 'T-id')97 remote_target.record_sync_info('other-id', 2, 'T-id')
98 except ssl.SSLError, e:98 except ssl.SSLError, e:
99 self.assertIn("certificate verify failed", str(e))99 self.assertIn("certificate", str(e))
100 else:100 else:
101 self.fail("certificate verification should have failed.")101 self.fail("certificate verification should have failed.")
102102

Subscribers

People subscribed via source and target branches

to all changes: