uonedb-qt team mailing list archive
-
uonedb-qt team
-
Mailing list archive
-
Message #00283
[Merge] lp:~kalikiana/u1db-qt/wonderiousFields into lp:u1db-qt
Christian Dywan has proposed merging lp:~kalikiana/u1db-qt/wonderiousFields into lp:u1db-qt.
Requested reviews:
U1DB Qt developers (uonedb-qt)
Related bugs:
Bug #1214538 in U1DB Qt/ QML: "Not indexing documents unless all fields are in the index expression clause"
https://bugs.launchpad.net/u1db-qt/+bug/1214538
Bug #1215898 in U1DB Qt/ QML: "Strange behaviour with multiple elements on first level in contents"
https://bugs.launchpad.net/u1db-qt/+bug/1215898
Bug #1284194 in U1DB Qt/ QML: "Wonderious fields constellation gets ignored"
https://bugs.launchpad.net/u1db-qt/+bug/1284194
For more details, see:
https://code.launchpad.net/~kalikiana/u1db-qt/wonderiousFields/+merge/207968
--
https://code.launchpad.net/~kalikiana/u1db-qt/wonderiousFields/+merge/207968
Your team U1DB Qt developers is requested to review the proposed merge of lp:~kalikiana/u1db-qt/wonderiousFields into lp:u1db-qt.
=== modified file 'src/query.cpp'
--- src/query.cpp 2014-02-19 09:39:07 +0000
+++ src/query.cpp 2014-03-03 15:40:22 +0000
@@ -135,10 +135,9 @@
j.next();
- bool tmp_match = queryField(j.key(), j.value());
-
- if(tmp_match == false){
+ if (!queryField(j.key(), j.value())) {
match = false;
+ break;
}
}
@@ -178,9 +177,6 @@
Query a single field.
*/
bool Query::queryField(QString field, QVariant value){
-
- bool match = false;
-
QVariant query = getQuery();
// * is the default if query is empty
if (!query.isValid())
@@ -188,26 +184,18 @@
QString typeName = query.typeName();
if(typeName == "QString")
- {
- QString query_string = query.toString();
- match = queryString(query_string, value);
- }
+ return queryString(query.toString(), value);
else if(typeName == "int")
- {
- QString query_string = query.toString();
- match = queryString(query_string, value);
- }
+ return queryString(query.toString(), value);
else if(typeName == "QVariantList")
- {
- match = iterateQueryList(query, field, value);
- }
+ return iterateQueryList(query, field, value);
else
{
m_query = "";
qWarning("u1db: Unexpected type %s for query", qPrintable(typeName));
}
- return match;
+ return true;
}
@@ -217,9 +205,6 @@
*/
bool Query::iterateQueryList(QVariant query, QString field, QVariant value)
{
-
- bool match = false;
-
QList<QVariant> query_list = query.toList();
QListIterator<QVariant> j(query_list);
@@ -231,21 +216,12 @@
if(typeName == "QVariantMap")
{
- match = queryMap(j_value.toMap(), value.toString(), field);
-
- if(match == true){
- break;
- }
-
+ if (!queryMap(j_value.toMap(), value.toString(), field))
+ return false;
}
else if(typeName == "QString"){
-
- match = queryString(j_value.toString(), value);
-
- if(match == true){
- break;
- }
-
+ if (!queryString(j_value.toString(), value))
+ return false;
}
else
{
@@ -255,7 +231,23 @@
}
- return match;
+ return true;
+}
+
+/*!
+ \internal
+ Verify that query is an identical or wild card match.
+ */
+bool Query::queryMatchesValue(QString query, QString value)
+{
+ if (query == "*")
+ return true;
+ if (query == value)
+ return true;
+ if (!query.contains ("*"))
+ return false;
+ QString prefix(query.split("*")[0]);
+ return value.startsWith(prefix, Qt::CaseSensitive);
}
/*!
@@ -274,25 +266,7 @@
return false;
}
- bool match = false;
-
- if(query == "*"){
- return true;
- }
- else if(query == value){
- return true;
- }
- else if(query.contains("*")){
- QStringList k_string_list = query.split("*");
- QString k_string = k_string_list[0];
- match = value.toString().startsWith(k_string,Qt::CaseSensitive);
-
- return match;
-
- }
-
-
- return match;
+ return queryMatchesValue(query, value.toString());
}
/*!
@@ -301,9 +275,6 @@
*/
bool Query::queryMap(QVariantMap map, QString value, QString field)
{
-
- bool match = false;
-
QMapIterator<QString,QVariant> k(map);
while(k.hasNext()){
@@ -315,23 +286,12 @@
if(field == k_key){
- if(query == "*"){
- return true;
- }
- else if(query == value){
- return true;
- }
- else if(query.contains("*")){
- QStringList k_string_list = query.split("*");
- QString k_string = k_string_list[0];
- match = value.startsWith(k_string,Qt::CaseSensitive);
- return match;
- }
-
+ if (!queryMatchesValue(query, value))
+ return false;
}
}
- return match;
+ return true;
}
/*!
=== modified file 'src/query.h'
--- src/query.h 2014-01-31 19:20:07 +0000
+++ src/query.h 2014-03-03 15:40:22 +0000
@@ -70,6 +70,7 @@
void generateQueryResults();
bool iterateQueryList(QVariant query, QString field, QVariant value);
+ bool queryMatchesValue(QString query, QString value);
bool queryString(QString query, QVariant value);
bool queryMap(QVariantMap map, QString value, QString field);
bool queryField(QString field, QVariant value);
=== modified file 'tests/tst_query.qml'
--- tests/tst_query.qml 2014-02-19 09:39:07 +0000
+++ tests/tst_query.qml 2014-03-03 15:40:22 +0000
@@ -47,6 +47,12 @@
contents: { 'misc': { 'software': 'linux', 'sports': [ 'basketball', 'hockey' ] }, 'date': '2014-01-01' , 'gents': [ { 'name': 'Ivanka', 'phone': 00321 }, ] }
}
+ U1db.Document {
+ database: gents
+ docId: 'F'
+ contents: { 'details': { 'name': 'spy', 'type': 'hide', 'colour': 'blue' } }
+ }
+
U1db.Index {
id: byPhone
database: gents
@@ -133,6 +139,73 @@
query: [{ 'date': '2014*', 'sports': 'basketball', 'software': 'linux' }]
}
+ U1db.Query {
+ id: queryOne
+ index: U1db.Index {
+ database: gents
+ expression: [ 'details.type' ]
+ }
+ query: [ 'show' ]
+ }
+
+ U1db.Query {
+ id: queryBoth
+ index: U1db.Index {
+ database: gents
+ expression: [ 'details.type', 'details.colour' ]
+ }
+ query: [ 'show', '*' ]
+ }
+
+ U1db.Database {
+ id: tokusatsu
+ }
+
+ U1db.Document {
+ database: tokusatsu
+ docId: 'ooo'
+ contents: { 'series': 'ooo', 'type': 'rider' }
+ }
+
+ U1db.Document {
+ database: tokusatsu
+ docId: 'gokaiger'
+ contents: { 'series': 'gokaiger', 'type': 'sentai' }
+ }
+
+ U1db.Document {
+ id: tokusatsuDocumentWizard
+ docId: 'wizard'
+ contents: { 'series': 'wizard', 'type': 'rider',
+ 'transformations': ['Flame Style','Water Style'] }
+ }
+
+ U1db.Document {
+ id: tokusatsuDocumentDino
+ docId: 'dino'
+ contents: { 'series': 'zyuranger', 'scarf': false, 'type': 'sentai',
+ 'beasts': ['T-Rex', 'Mastodon'] }
+ }
+
+ U1db.Index {
+ id: bySeries
+ database: tokusatsu
+ name: 'by-series'
+ expression: ['series', 'type']
+ }
+
+ U1db.Query {
+ id: allHeroesWithType
+ index: bySeries
+ query: [{ 'series': '*' }, { 'type': '*' }]
+ }
+
+ U1db.Query {
+ id: allHeroesSeriesOnly
+ index: bySeries
+ query: [{ 'series': '*' }]
+ }
+
SignalSpy {
id: spyDocumentsChanged
target: defaultPhone
@@ -154,7 +227,7 @@
return A
}
- function compare (a, b) {
+ function compare (a, b, msg) {
/* Override built-in compare to:
Match different JSON for identical values (number hash versus list)
Produce readable output for all JSON values
@@ -163,7 +236,7 @@
return
var A = prettyJson(a), B = prettyJson(b)
if (A != B) {
- fail('%1 != %2 (%3 != %4)'.arg(A).arg(B).arg(JSON.stringify(a)).arg(JSON.stringify(b)))
+ fail('%5%1 != %2 (%3 != %4)'.arg(A).arg(B).arg(JSON.stringify(a)).arg(JSON.stringify(b)).arg(msg ? msg + ': ' : ''))
}
}
@@ -226,5 +299,28 @@
compare(defaultPhone.documents, ['1', 'a'], 'dos')
}
+ function test_5_fields () {
+ compare(queryOne.documents, {}, 'one field')
+ compare(queryBoth.documents, {}, 'two fields')
+ }
+
+ function test_6_definition () {
+ workaroundQueryAndWait(allHeroesWithType)
+ compare(allHeroesWithType.documents, ['gokaiger', 'ooo'], 'ichi')
+ workaroundQueryAndWait(allHeroesSeriesOnly)
+ compare(allHeroesSeriesOnly.documents, ['gokaiger', 'ooo'], 'ni')
+ compare(allHeroesWithType.documents, allHeroesSeriesOnly.documents, 'doube-check')
+ // Add a document with extra fields
+ tokusatsu.putDoc(tokusatsuDocumentWizard.contents, tokusatsuDocumentWizard.docId)
+ workaroundQueryAndWait(allHeroesWithType)
+ compare(allHeroesWithType.documents, ['gokaiger', 'ooo', 'wizard'], 'san')
+ workaroundQueryAndWait(allHeroesSeriesOnly)
+ compare(allHeroesWithType.documents, allHeroesSeriesOnly.documents, 'chi')
+ // Add a document with mixed custom fields
+ tokusatsu.putDoc(tokusatsuDocumentDino.contents, tokusatsuDocumentDino.docId)
+ workaroundQueryAndWait(allHeroesWithType)
+ compare(allHeroesWithType.documents, ['dino', 'gokaiger', 'ooo', 'wizard'], 'go')
+ compare(allHeroesWithType.documents, allHeroesSeriesOnly.documents, 'roku')
+ }
} }
Follow ups